A.I.M.S


aims::ItemReader< T > Class Template Referenceabstract

Low-level "small item" reader, used by higher-level file readers. More...

#include <aims/io/itemR.h>

Inheritance diagram for aims::ItemReader< T >:

Public Member Functions

virtual ~ItemReader ()
 
virtual void read (std::istream &is, T &item) const
 
virtual void read (std::istream &is, T *pitem, size_t n) const =0
 
void read (const std::string &istring, T &item) const
 
void read (const std::string &istring, T *pitem, size_t n) const
 
virtual ItemReader< T > * reader (const std::string &openmode="binar", bool bswap=false) const =0
 

Detailed Description

template<class T>
class aims::ItemReader< T >

Low-level "small item" reader, used by higher-level file readers.

It can read either a single item, or an array of them. This template class is inherited by specific item readers, esp. by the DefaultItemReader classes.

This new version differs from the one in Aims 2.7 and before in several aspects:

  • the input stream is not stored in the ItemReader, but passed when used through the read() functions
  • the reading mode (ascii / binary / byte-swapped binary) is not passed each time the read() functions are called
  • the new ItemReader is a more specialized object than it was: it can only read one reading mode: ascii / bin / byte-swapped
  • ItemReader objects have the ability to "switch" to another one depending on the reading mode by allocating a new objetc related to itself: that is the job of the reader() function. We could have written a small factory instead and it will maybe be done one day, but for now I was just too lazy to do it.

As a result the new ItemReader is a lot faster than in Aims 2.7 since it doesn't have to check the reading mode and switch to different operating modes at each specific read.
As a counterpart, you now generally have to allocate two readers: one to use the correct item variant, and another one to switch on the reading-mode specific ItemReader:

// Let's read a vector of signed 16 bits elements
short shortarray[ 100 ];
DefaultItemReader<short> ir1;
string openmode; // "ascii" / "binar"
bool bswap;
// get openmode and bswap from the header of the file to read
// ...
// now we assume it's done
ItemReader<short> *ir = ir1.reader( openmode, bswap );
// we use ir in the following, we can forget ir1 now.
std::ifstream infile( "file.dat" );
assert( infile );
// read 100 elements
ir->read( infile, shortarray, 100 );
// don't forget to destroy the reader after use
delete ir;

Definition at line 98 of file itemR.h.

Constructor & Destructor Documentation

template<class T>
virtual aims::ItemReader< T >::~ItemReader ( )
inlinevirtual

Definition at line 101 of file itemR.h.

Member Function Documentation

template<class T>
virtual void aims::ItemReader< T >::read ( std::istream &  is,
T &  item 
) const
inlinevirtual
template<class T>
void aims::ItemReader< T >::read ( const std::string &  istring,
T &  item 
) const
inline

Definition at line 106 of file itemR.h.

template<class T>
void aims::ItemReader< T >::read ( const std::string &  istring,
T *  pitem,
size_t  n 
) const
inline

Definition at line 115 of file itemR.h.


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