Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends

PARASOLFileReader Class Reference

#include <parasolfilereader.h>

Inheritance diagram for PARASOLFileReader:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 PARASOLFileReader (const string filename="")

Static Public Member Functions

static PARASOLProduct get_product (const string &filename)
 access to the product using parsing the name
static void * custom_new (void *buf, const int &nb_data, const PARASOLDataType &type)
 allocate a buffer to read data from a PARASOL data file.
static void * inc_ptr (void *buf_start, const int &inc, const PARASOLDataType &type)
 find the element of a buffer at index inc, for buffer of type void*. It is a method equivalent to buf_start[inc] for void* typed buffer

Protected Member Functions

virtual void read_record (const Record &record_code)
 read the whole data of a record
void read_entry (void *record, const Record &record_code, int &entry_nb, RecordFormat::iterator &entry_format, const int &record_offset)
 read the values of an entry.
const size_t read_value (void *val, const RecordFormat::iterator &val_format, const int &previous_value_offset)
 read ONE value in the PARASOL file
void swap_endianess (void *val, const PARASOLDataType &type)
 swap the given value endianess.
virtual const bool is_record_loaded (const Record &rec)=0
 check if a record has been read.
virtual void free_records ()=0
 Free the objects used to store the values read in the file records.
virtual PARASOLFileRecordinit_record (const Record &rec)=0
 Initialize a record class.
virtual const int get_record_offset (const Record &rec)=0
 access to ones record file offset If the record isn't in the leader leader file, it returns -1
virtual const int get_entry_offset (const Record rec, const int entry_idx, const vector< int > &i_val)
 return the offset of a record entry, in record unit. It means that the first entry (ie the record number) has an entry_offset of 0
virtual vector< EntryBlockget_entry_block (const Record rec, const int entry_idx) const =0
 returns the number of times an entry group is repeated in the data record. If the entry is not repeated in a record, returns 1
virtual const RecordFormat * get_record_format (const Record &rec)=0
 access to the RecordFormat object that describes the name, type, offset and length of each record entry
virtual PARASOLFileRecordget_record (const Record &rec)=0
 access to one record entry
const bool is_file_loaded ()
 check if the file to read has been laded
void open_file ()
void close_file ()

Static Protected Member Functions

static void fill_buffer_default (void *buf, const int &nb_val, const PARASOLDataType &type)
 fill a buffer used to read the file with fill values It uses a memset to do that

Protected Attributes

string filename
PARASOLProduct product
FILE * fp

Friends

class PARASOLFileData

Detailed Description

This class contains the methods used to read the PARASOL that are common to the leader and the data files.

Author:
Nicolas PASCAL

Member Function Documentation

void * PARASOLFileReader::custom_new ( void *  buf,
const int &  nb_data,
const PARASOLDataType &  type 
) [static]

allocate a buffer to read data from a PARASOL data file.

Warning:
the buffer is allocated using the new[] operator (and not malloc !!!). So It must be freed with delete[].
Parameters:
buf the buffer to be allocated
nb_data the buffer's length
type the buffer's data type (using PARASOLDataType)
Returns:
the allocated buffer or NULL if not enough memory
void PARASOLFileReader::fill_buffer_default ( void *  buf,
const int &  nb_val,
const PARASOLDataType &  type 
) [static, protected]

fill a buffer used to read the file with fill values It uses a memset to do that

Parameters:
buf the buffer
nb_val the number of values of the buffer
type the data type

References PARASOLFileFormat::get_size_of().

Referenced by PARASOLData::read_data().

virtual vector<EntryBlock> PARASOLFileReader::get_entry_block ( const Record  rec,
const int  entry_idx 
) const [protected, pure virtual]

returns the number of times an entry group is repeated in the data record. If the entry is not repeated in a record, returns 1

Exceptions:
bad_parametre_idx if the entry idx is invalid for the current product
Parameters:
entry_idx index of the entry (product specific)
Returns:
the number of times the group is repeated return the block describing the given entry : the number of times the entry is repeated and the size in bytes of the group
Parameters:
rec current record
entry_idx indice of the entry
Returns:
the block(s) of the entry. If the entry is composed of a unique value, returns an empty vector

Implemented in PARASOLData, and PARASOLLeader.

Referenced by get_entry_offset(), and read_entry().

const int PARASOLFileReader::get_entry_offset ( const Record  rec,
const int  entry_idx,
const vector< int > &  i_val 
) [protected, virtual]

return the offset of a record entry, in record unit. It means that the first entry (ie the record number) has an entry_offset of 0

Parameters:
record_idx the record code
entry_idx the index of the entry to find the offset, start at 0. The record number has an entry_index of 0
entry_group_idx (optional) for an entry that is in a repeated group, the index of the repetition. It is an abstraction, but for example, it is the index a direction for a directional parameter, starting at 0.
val_idx (optional) an index to select a particular value
Returns:
the offset of the entry in the record, in bytes access to the offset of an entry, relative to the record start TODO example
Parameters:
rec the concerned record
entry_idx index of the entry, start at 0, record_number is index 0
i_val indices of the value, for parametres repeated many times in a record
Returns:
the offset, from the record start

References get_entry_block(), and get_record_format().

Referenced by PARASOLData::read_data(), and read_entry().

PARASOLProduct PARASOLFileReader::get_product ( const string &  filename  )  [static]

access to the product using parsing the name

Parameters:
filename the PARASOL file name (without the path)
Returns:
the product
virtual PARASOLFileRecord* PARASOLFileReader::get_record ( const Record &  rec  )  [protected, pure virtual]

access to one record entry

Parameters:
rec the record code
Returns:
the entry corresponding to record code

Implemented in PARASOLData, and PARASOLLeader.

Referenced by read_record().

virtual const RecordFormat* PARASOLFileReader::get_record_format ( const Record &  rec  )  [protected, pure virtual]

access to the RecordFormat object that describes the name, type, offset and length of each record entry

Parameters:
rec the record code
Returns:
the RecordFormat corresponding to record code

Implemented in PARASOLData, and PARASOLLeader.

Referenced by get_entry_offset(), and read_record().

virtual const int PARASOLFileReader::get_record_offset ( const Record &  rec  )  [protected, pure virtual]

access to ones record file offset If the record isn't in the leader leader file, it returns -1

Parameters:
rec the record code
Returns:
the record's offset in the leader file

Implemented in PARASOLData, and PARASOLLeader.

Referenced by read_record().

void * PARASOLFileReader::inc_ptr ( void *  buf_start,
const int &  inc,
const PARASOLDataType &  type 
) [static]

find the element of a buffer at index inc, for buffer of type void*. It is a method equivalent to buf_start[inc] for void* typed buffer

Parameters:
buf_start the buffer start pointer
inc the increment
type the buffer's type code
Returns:
a pointer to the element

Referenced by PARASOLData::read_data().

virtual PARASOLFileRecord* PARASOLFileReader::init_record ( const Record &  rec  )  [protected, pure virtual]

Initialize a record class.

Parameters:
rec the record code
Returns:
the initialized object (or NULL in case of problem)

Implemented in PARASOLData, and PARASOLLeader.

Referenced by read_record().

const bool PARASOLFileReader::is_file_loaded (  )  [inline, protected]

check if the file to read has been laded

Returns:
true of loaded

Referenced by PARASOLFileData::close_file(), PARASOLFileData::is_file_loaded(), PARASOLFileData::load_geolocation_data(), PARASOLData::read_data(), and read_record().

virtual const bool PARASOLFileReader::is_record_loaded ( const Record &  rec  )  [protected, pure virtual]

check if a record has been read.

Returns:
true if the record has already been read

Implemented in PARASOLData, and PARASOLLeader.

Referenced by read_record().

void PARASOLFileReader::read_entry ( void *  record,
const Record &  record_code,
int &  entry_nb,
RecordFormat::iterator &  entry_format,
const int &  record_offset 
) [protected]

read the values of an entry.

Parameters:
entry the variable where to put the read value(s)
entry_nb the number of the entry. Updated by the method
record_code the code of the current processed record
entry_format the entry record format descriptor (a RecordFormat::iterator) Updated by the method
record_offset the start offset of the read record.

References get_entry_block(), get_entry_offset(), and read_value().

Referenced by read_record().

void PARASOLFileReader::read_record ( const Record &  record_code  )  [protected, virtual]
const size_t PARASOLFileReader::read_value ( void *  val,
const RecordFormat::iterator &  val_format,
const int &  previous_value_offset 
) [protected]

read ONE value in the PARASOL file

Parameters:
val the variable where to put the read value
val_format a RecordFormat element describing the value format
previous_value_offset the file offset of the nearest preceeding value.
Returns:
the number of bytes read

References PARASOLFileFormat::get_size_of(), and swap_endianess().

Referenced by read_entry().

void PARASOLFileReader::swap_endianess ( void *  val,
const PARASOLDataType &  type 
) [protected]

swap the given value endianess.

Parameters:
val the value to be swapped
type the type code of this value

Referenced by PARASOLData::read_data(), and read_value().


The documentation for this class was generated from the following files: