aimsdata  5.0.5
Neuroimaging data handling
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

◆ ~ItemReader()

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

Definition at line 101 of file itemR.h.

Member Function Documentation

◆ read() [1/4]

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

Reimplemented in aims::DefaultBSwapItemReader< AimsVector< T, D > >, aims::DefaultItemReader< AimsVector< T, D > >, aims::DefaultBSwapItemReader< T >, aims::DefaultBSwapItemReader< DtiTensor >, aims::DefaultAsciiItemReader< std::vector< T > >, aims::DefaultBSwapItemReader< SparseMatrix >, aims::DefaultBSwapItemReader< Trieder >, aims::DefaultBSwapItemReader< Tensor >, aims::DefaultBSwapItemReader< std::list< T > >, aims::DefaultAsciiItemReader< T >, aims::DefaultAsciiItemReader< DtiTensor >, aims::DefaultAsciiItemReader< SparseMatrix >, aims::DefaultAsciiItemReader< Trieder >, aims::DefaultAsciiItemReader< Tensor >, aims::DefaultBSwapItemReader< std::vector< T > >, aims::DefaultAsciiItemReader< std::list< T > >, aims::DefaultItemReader< T >, aims::DefaultItemReader< DtiTensor >, aims::DefaultItemReader< SparseMatrix >, aims::DefaultItemReader< Trieder >, aims::DefaultItemReader< Tensor >, aims::DefaultItemReader< std::list< T > >, and aims::DefaultItemReader< std::vector< T > >.

Definition at line 103 of file itemR.h.

Referenced by aims::BckMapReader< T >::read(), aims::GenesisReader< T >::read(), aims::TexReader< T >::read(), aims::MeshReader< D, T >::read(), aims::DefaultItemReader< T >::read(), aims::FdfReader< T >::read(), aims::ImasVolFormat< T >::read(), aims::DefaultAsciiItemReader< T >::read(), aims::SpmReader< T >::read(), aims::DefaultBSwapItemReader< T >::read(), aims::DefaultItemReader< AimsVector< T, D > >::read(), and aims::DefaultBSwapItemReader< AimsVector< T, D > >::read().

◆ read() [2/4]

◆ read() [3/4]

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

Definition at line 106 of file itemR.h.

◆ read() [4/4]

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.

◆ reader()


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