casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Types | Private Member Functions | Private Attributes
asdm::TableStreamReader< T, R > Class Template Reference

A generic class to read a file containing an ASDM table as a stream. More...

#include <TableStreamReader.h>

List of all members.

Public Member Functions

 TableStreamReader ()
 An empty constructor.
virtual ~TableStreamReader ()
 The destructor.
void open (const std::string &directory)
 Opens a file expected to contain an ASDM table of type T with rows of type R.
void reset ()
 Repositions the read head to the beginning of the table.
const std::vector< R * > & nextNRows (unsigned int nRows)
 Reads at most n rows in the file, creates as many memory representations of these rows and return the reference of a vector of pointers on these representations.
const std::vector< R * > & untilNBytes (unsigned int nBytes)
 Reads as many rows as possible in the file, keeps their in memory representation until the number of read bytes is greater or equal a number of bytes, n, passed as a parameter to the method.
bool hasRows ()
 Returns true if the end of the file has not been reached.
void close ()
 Releases all the resources allocated to the instance which can be reused with another file.
 TableStreamReader ()
 An empty constructor.
virtual ~TableStreamReader ()
 The destructor.
void open (const std::string &directory)
 Opens a file expected to contain an ASDM table of type T with rows of type R.
void reset ()
 Repositions the read head to the beginning of the table.
const std::vector< R * > & nextNRows (unsigned int nRows)
 Reads at most n rows in the file, creates as many memory representations of these rows and return the reference of a vector of pointers on these representations.
const std::vector< R * > & untilNBytes (unsigned int nBytes)
 Reads as many rows as possible in the file, keeps their in memory representation until the number of read bytes is greater or equal a number of bytes, n, passed as a parameter to the method.
bool hasRows ()
 Returns true if the end of the file has not been reached.
void close ()
 Releases all the resources allocated to the instance which can be reused with another file.

Private Types

enum  State {
  S_CLOSED,
  S_OPENED,
  S_CLOSED,
  S_OPENED
}
enum  Transition {
  T_OPEN,
  T_CHECK,
  T_RESET,
  T_READ,
  T_CLOSE,
  T_OPEN,
  T_CHECK,
  T_RESET,
  T_READ,
  T_CLOSE
}
enum  State {
  S_CLOSED,
  S_OPENED,
  S_CLOSED,
  S_OPENED
}
enum  Transition {
  T_OPEN,
  T_CHECK,
  T_RESET,
  T_READ,
  T_CLOSE,
  T_OPEN,
  T_CHECK,
  T_RESET,
  T_READ,
  T_CLOSE
}

Private Member Functions

void checkState (Transition t, const string &methodName) const
void clear ()
 Empty the local storage containing the rows obtained during the last read operation.
void checkState (Transition t, const string &methodName) const
void clear ()
 Empty the local storage containing the rows obtained during the last read operation.

Private Attributes

std::string tablePath
std::ifstream tableFile
off_t fileSizeInBytes
asdm::EndianIFStream eifs
std::vector< std::string > attributesSeq
asdm::ASDM asdm
std::vector< R * > rows
char * readBuffer
streampos whereRowsStart
State currentState

Detailed Description

template<class T, class R>
class asdm::TableStreamReader< T, R >

A generic class to read a file containing an ASDM table as a stream.

The purpose of this class is to provide the programmer with a way to read a file containing an ASDM table by successive slices. Each slice is transformed into the in memory representation of the rows which have been read. A slice can be specified in two ways :

Remarks

Parameters:
TThe parameter T must be the type of one of the tables which can be found in an ASDM (e.g. AntennaTable)
RThe parameter R must be the type of the rows which make the content of a table of type T (e.g. AntennaRow is T is AntennaTable).

Definition at line 39 of file TableStreamReader.h.


Member Enumeration Documentation

template<class T , class R >
enum asdm::TableStreamReader::State [private]
Enumerator:
S_CLOSED 
S_OPENED 
S_CLOSED 
S_OPENED 

Definition at line 260 of file TableStreamReader.h.

template<class T , class R >
enum asdm::TableStreamReader::State [private]
Enumerator:
S_CLOSED 
S_OPENED 
S_CLOSED 
S_OPENED 

Definition at line 260 of file TableStreamReader.h.

template<class T , class R >
enum asdm::TableStreamReader::Transition [private]
Enumerator:
T_OPEN 
T_CHECK 
T_RESET 
T_READ 
T_CLOSE 
T_OPEN 
T_CHECK 
T_RESET 
T_READ 
T_CLOSE 

Definition at line 261 of file TableStreamReader.h.

template<class T , class R >
enum asdm::TableStreamReader::Transition [private]
Enumerator:
T_OPEN 
T_CHECK 
T_RESET 
T_READ 
T_CLOSE 
T_OPEN 
T_CHECK 
T_RESET 
T_READ 
T_CLOSE 

Definition at line 261 of file TableStreamReader.h.


Constructor & Destructor Documentation

template<class T , class R >
asdm::TableStreamReader< T, R >::TableStreamReader ( ) [inline]
template<class T , class R >
virtual asdm::TableStreamReader< T, R >::~TableStreamReader ( ) [inline, virtual]

The destructor.

Definition at line 49 of file TableStreamReader.h.

template<class T , class R >
asdm::TableStreamReader< T, R >::TableStreamReader ( ) [inline]
template<class T , class R >
virtual asdm::TableStreamReader< T, R >::~TableStreamReader ( ) [inline, virtual]

The destructor.

Definition at line 49 of file TableStreamReader.h.


Member Function Documentation

template<class T , class R >
void asdm::TableStreamReader< T, R >::checkState ( Transition  t,
const string &  methodName 
) const [inline, private]
template<class T , class R >
void asdm::TableStreamReader< T, R >::checkState ( Transition  t,
const string &  methodName 
) const [inline, private]
template<class T , class R >
void asdm::TableStreamReader< T, R >::clear ( ) [inline, private]

Empty the local storage containing the rows obtained during the last read operation.

Definition at line 277 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::rows.

Referenced by asdm::TableStreamReader< T, R >::close(), asdm::TableStreamReader< T, R >::nextNRows(), asdm::TableStreamReader< T, R >::reset(), and asdm::TableStreamReader< T, R >::untilNBytes().

template<class T , class R >
void asdm::TableStreamReader< T, R >::clear ( ) [inline, private]

Empty the local storage containing the rows obtained during the last read operation.

Definition at line 277 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::rows.

template<class T , class R >
void asdm::TableStreamReader< T, R >::close ( ) [inline]
template<class T , class R >
void asdm::TableStreamReader< T, R >::close ( ) [inline]
template<class T , class R >
bool asdm::TableStreamReader< T, R >::hasRows ( ) [inline]
template<class T , class R >
bool asdm::TableStreamReader< T, R >::hasRows ( ) [inline]
template<class T , class R >
const std::vector<R*>& asdm::TableStreamReader< T, R >::nextNRows ( unsigned int  nRows) [inline]

Reads at most n rows in the file, creates as many memory representations of these rows and return the reference of a vector of pointers on these representations.

Parameters:
nRowsthe maximum number of rows to read.
Returns:
a constant reference to a vector of pointers on instances of R.

Definition at line 193 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::asdm, asdm::TableStreamReader< T, R >::attributesSeq, asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::eifs, asdm::ASDM::getTable(), asdm::TableStreamReader< T, R >::hasRows(), casa::name(), asdm::TableStreamReader< T, R >::rows, and asdm::TableStreamReader< T, R >::T_READ.

template<class T , class R >
const std::vector<R*>& asdm::TableStreamReader< T, R >::nextNRows ( unsigned int  nRows) [inline]

Reads at most n rows in the file, creates as many memory representations of these rows and return the reference of a vector of pointers on these representations.

Parameters:
nRowsthe maximum number of rows to read.
Returns:
a constant reference to a vector of pointers on instances of R.

Definition at line 193 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::asdm, asdm::TableStreamReader< T, R >::attributesSeq, asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::eifs, asdm::ASDM::getTable(), asdm::TableStreamReader< T, R >::hasRows(), casa::name(), asdm::TableStreamReader< T, R >::rows, and asdm::TableStreamReader< T, R >::T_READ.

template<class T , class R >
void asdm::TableStreamReader< T, R >::open ( const std::string &  directory) [inline]

Opens a file expected to contain an ASDM table of type T with rows of type R.

Parameters:
directorythe path to the directory containing the file.

Open the file.

streambuf * sb_p = tableFile.rdbuf()->pubsetbuf(readBuffer, READBUFFERSIZE); cout << (unsigned long long) sb_p << endl;

Determine the size of the file.

Locate the xmlPartMIMEHeader.

Locate the binaryPartMIMEHeader while accumulating the characters of the xml header.

      We have the xmlHeader , let's parse it.

Then it's an "old fashioned" MIME file for tables. Just try to deserialize it with Big_Endian for the bytes ordering.

It's a new (and correct) MIME file for tables.

       1st )  Look for a BulkStoreRef element with an attribute byteOrder.

Skip the two first children (Entity and ContainerEntity).

We found BulkStoreRef, now look for its attribute byteOrder.

        2nd) Look for the Attributes element and grab the names of the elements it contains.

Create an EndianIFStream from the substring containing the binary part.

We do nothing with that but we have to read it.

Let's read numRows but ignore it and rely on the value specified in the ASDM.xml file.

Memorize the starting point of rows.

Update the state

Definition at line 56 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::attributesSeq, asdm::ByteOrder::Big_Endian, asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::currentState, asdm::TableStreamReader< T, R >::eifs, asdm::TableStreamReader< T, R >::fileSizeInBytes, asdm::Entity::fromBin(), asdm::ByteOrder::fromString(), casa::name(), asdm::TableStreamReader< T, R >::S_OPENED, asdm::TableStreamReader< T, R >::T_OPEN, asdm::TableStreamReader< T, R >::tableFile, asdm::TableStreamReader< T, R >::tablePath, and asdm::TableStreamReader< T, R >::whereRowsStart.

template<class T , class R >
void asdm::TableStreamReader< T, R >::open ( const std::string &  directory) [inline]

Opens a file expected to contain an ASDM table of type T with rows of type R.

Parameters:
directorythe path to the directory containing the file.

Open the file.

streambuf * sb_p = tableFile.rdbuf()->pubsetbuf(readBuffer, READBUFFERSIZE); cout << (unsigned long long) sb_p << endl;

Determine the size of the file.

Locate the xmlPartMIMEHeader.

Locate the binaryPartMIMEHeader while accumulating the characters of the xml header.

      We have the xmlHeader , let's parse it.

Then it's an "old fashioned" MIME file for tables. Just try to deserialize it with Big_Endian for the bytes ordering.

It's a new (and correct) MIME file for tables.

       1st )  Look for a BulkStoreRef element with an attribute byteOrder.

Skip the two first children (Entity and ContainerEntity).

We found BulkStoreRef, now look for its attribute byteOrder.

        2nd) Look for the Attributes element and grab the names of the elements it contains.

Create an EndianIFStream from the substring containing the binary part.

We do nothing with that but we have to read it.

Let's read numRows but ignore it and rely on the value specified in the ASDM.xml file.

Memorize the starting point of rows.

Update the state

Definition at line 56 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::attributesSeq, asdm::ByteOrder::Big_Endian, asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::currentState, asdm::TableStreamReader< T, R >::eifs, asdm::TableStreamReader< T, R >::fileSizeInBytes, asdm::Entity::fromBin(), asdm::ByteOrder::fromString(), casa::name(), asdm::TableStreamReader< T, R >::S_OPENED, asdm::TableStreamReader< T, R >::T_OPEN, asdm::TableStreamReader< T, R >::tableFile, asdm::TableStreamReader< T, R >::tablePath, and asdm::TableStreamReader< T, R >::whereRowsStart.

template<class T , class R >
void asdm::TableStreamReader< T, R >::reset ( ) [inline]

Repositions the read head to the beginning of the table.

The internal storage containing the result of the last read operation is cleared.

Definition at line 181 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::T_RESET, asdm::TableStreamReader< T, R >::tableFile, and asdm::TableStreamReader< T, R >::whereRowsStart.

template<class T , class R >
void asdm::TableStreamReader< T, R >::reset ( ) [inline]

Repositions the read head to the beginning of the table.

The internal storage containing the result of the last read operation is cleared.

Definition at line 181 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::T_RESET, asdm::TableStreamReader< T, R >::tableFile, and asdm::TableStreamReader< T, R >::whereRowsStart.

template<class T , class R >
const std::vector<R*>& asdm::TableStreamReader< T, R >::untilNBytes ( unsigned int  nBytes) [inline]

Reads as many rows as possible in the file, keeps their in memory representation until the number of read bytes is greater or equal a number of bytes, n, passed as a parameter to the method.

Parameters:
nthe number of read bytes which is used as an upper limit to the read operation.
Returns:
a constant reference to a vector of pointers on instances of R.

Definition at line 213 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::asdm, asdm::TableStreamReader< T, R >::attributesSeq, asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::eifs, asdm::ASDM::getTable(), asdm::TableStreamReader< T, R >::hasRows(), casa::name(), asdm::TableStreamReader< T, R >::rows, asdm::TableStreamReader< T, R >::T_READ, and asdm::TableStreamReader< T, R >::tableFile.

template<class T , class R >
const std::vector<R*>& asdm::TableStreamReader< T, R >::untilNBytes ( unsigned int  nBytes) [inline]

Reads as many rows as possible in the file, keeps their in memory representation until the number of read bytes is greater or equal a number of bytes, n, passed as a parameter to the method.

Parameters:
nthe number of read bytes which is used as an upper limit to the read operation.
Returns:
a constant reference to a vector of pointers on instances of R.

Definition at line 213 of file TableStreamReader.h.

References asdm::TableStreamReader< T, R >::asdm, asdm::TableStreamReader< T, R >::attributesSeq, asdm::TableStreamReader< T, R >::checkState(), asdm::TableStreamReader< T, R >::clear(), asdm::TableStreamReader< T, R >::eifs, asdm::ASDM::getTable(), asdm::TableStreamReader< T, R >::hasRows(), casa::name(), asdm::TableStreamReader< T, R >::rows, asdm::TableStreamReader< T, R >::T_READ, and asdm::TableStreamReader< T, R >::tableFile.


Member Data Documentation

template<class T , class R >
asdm::ASDM asdm::TableStreamReader< T, R >::asdm [private]
template<class T , class R >
std::vector< std::string > asdm::TableStreamReader< T, R >::attributesSeq [private]
template<class T , class R >
State asdm::TableStreamReader< T, R >::currentState [private]
template<class T , class R >
asdm::EndianIFStream asdm::TableStreamReader< T, R >::eifs [private]
template<class T , class R >
off_t asdm::TableStreamReader< T, R >::fileSizeInBytes [private]
template<class T , class R >
char * asdm::TableStreamReader< T, R >::readBuffer [private]
template<class T , class R >
std::vector< R * > asdm::TableStreamReader< T, R >::rows [private]
template<class T , class R >
std::ifstream asdm::TableStreamReader< T, R >::tableFile [private]
template<class T , class R >
std::string asdm::TableStreamReader< T, R >::tablePath [private]

Definition at line 248 of file TableStreamReader.h.

Referenced by asdm::TableStreamReader< T, R >::open().

template<class T , class R >
streampos asdm::TableStreamReader< T, R >::whereRowsStart [private]

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