Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

LBufferedTransactionReader.hpp

Go to the documentation of this file.
00001 #ifndef LBufferedTransactionReader_HPP
00002 #define LBufferedTransactionReader_HPP
00003 
00008 #include "io/input/transaction_reader/BufferedTransactionReader.hpp"  
00009 
00010 // This class represents a buffered TransactionReader.
00011 template <class T_R = TransactionReader<> >
00012 class LBufferedTransactionReader : public BufferedTransactionReader<T_R>
00013 {
00014    private:
00015       typedef BufferedTransactionReader<T_R> PARENT;
00016    public:
00017       typedef typename BufferedTransactionReader<T_R>::params_t params_t;
00018       LBufferedTransactionReader( const params_t* par )
00019          : BufferedTransactionReader<T_R>( par)
00020       {
00021          bufLength = readFromFile(PARENT::buffer, PARENT::buffer_size);
00022          bufPosition = 0;
00023       }
00024 
00026       template <class BIS> counter_t nextTransactionBIS( BIS& transaction );
00027 
00029       template <class UAC> counter_t nextTransactionUAC( UAC& transaction );
00030 
00032       void rewind()
00033       {
00034          BufferedTransactionReader<T_R>::rewind();
00035          bufLength = readFromFile(PARENT::buffer, PARENT::buffer_size);
00036          bufPosition = 0;
00037       }
00038 
00039 
00040    private:
00042       std::streamsize bufPosition;
00044       std::streamsize bufLength;
00045 
00046    private:
00047 
00049       inline bool DINLINE getNextItem(int& item, char& c)
00050       {
00051          item = 0;
00052          bool has_next_int = false;
00053          c = PARENT::buffer[bufPosition];
00054          ++bufPosition;
00055          if( bufPosition >= bufLength ) 
00056          {
00057             bufLength = readFromFile(PARENT::buffer, PARENT::buffer_size);
00058             bufPosition = 0;
00059          }
00060             
00061          while( (bufLength != 0) && (c >= '0') && (c <= '9') )
00062          {
00063             has_next_int = true;
00064             item = 10 * item + (c - '0');
00065             c = PARENT::buffer[bufPosition];
00066             ++bufPosition;
00067             if (bufPosition >= bufLength) 
00068             {
00069                bufLength = readFromFile(PARENT::buffer, PARENT::buffer_size);
00070                bufPosition = 0;
00071             }
00072          }
00073          return has_next_int;
00074       }
00075 };
00076 
00077 template <class T_R> template <class BIS> inline counter_t 
00078 LBufferedTransactionReader<T_R>::nextTransactionBIS( BIS& transaction )
00079 {
00080    transaction.clear();
00081    if( bufLength == 0 ) return 0;
00082    char          c;
00083    int           item;
00084 
00085    do
00086    {
00087       if( getNextItem(item, c) )
00088          transaction.push_back( (item_t) item );
00089    }
00090    while( (bufLength != 0) && (c != '\n') );
00091    return 1;
00092 }
00093 
00094 template <class T_R> template <class UAC> inline counter_t 
00095 LBufferedTransactionReader<T_R>::nextTransactionUAC( UAC& transaction )
00096 {
00097    transaction.clear();
00098    if( bufLength == 0 ) return 0;
00099    int item;
00100    char c;
00101 
00102    do
00103    {
00104       if( getNextItem(item, c) ) 
00105          transaction.insert( (item_t) item );
00106    }
00107    while( (bufLength != 0) && (c != '\n') );
00108    return 1;
00109 }
00110 
00111 
00112 #endif

Generated on Sun Sep 17 17:50:39 2006 for FIM environment by  doxygen 1.4.4