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

SimpleTransactionReader.hpp

Go to the documentation of this file.
00001 #ifndef SimpleTransactionReader_HPP
00002 #define SimpleTransactionReader_HPP
00003 
00004 
00005 #include "io/StreamRepr.hpp"  
00006 #include "io/input/transaction_reader/TransactionReader.hpp"  
00007 
00019 class SimpleTransactionReader : public TransactionReader<StreamRepr>
00020 {
00021    public:
00022 
00023       SimpleTransactionReader( const params_t* par ) :
00024          TransactionReader<StreamRepr>(par){}
00025 
00026       template <class BIS> counter_t nextTransactionBIS( BIS& transaction );
00027 
00028       template <class UAC> counter_t nextTransactionUAC( UAC& transaction );
00029 
00030    private:
00037       bool getNextItem(int& item, char& c);
00038 };
00039 
00040 template <class BIS> inline counter_t SimpleTransactionReader::
00041 nextTransactionBIS( BIS& transaction )
00042 {
00043    transaction.clear();
00044    if( input_stream.eof() ) return 0;
00045    char          c;
00046    int           item;
00047       
00048    do
00049    {
00050       if( getNextItem(item, c) )
00051          transaction.push_back( (item_t) item );
00052    }
00053    while( !input_stream.eof() && c != '\n' );
00054 //   copy(transaction.begin(),transaction.end(),ostream_iterator<item_t>(cout," "));
00055 //   cout<<"\n";
00056    return 1;
00057 }
00058 
00059 template <class UAC> inline counter_t SimpleTransactionReader::
00060 nextTransactionUAC( UAC& transaction )
00061 {
00062    transaction.clear();
00063    if( input_stream.eof() ) return 0;
00064    int item;
00065    char c;
00066    do
00067    {
00068       if( getNextItem(item, c) ) 
00069          transaction.insert( (item_t) item );
00070    }
00071    while( !input_stream.eof() && c != '\n' );
00072    return 1;
00073 }
00074 
00075 inline bool SimpleTransactionReader::getNextItem(int& item, char& c)
00076 {
00077    item = 0;
00078    bool has_next_int;
00079    has_next_int = false;
00080    input_stream.get(c);
00081    while(input_stream.good() && (c >= '0') && (c <= '9'))
00082    {
00083       has_next_int = true;
00084       item = 10 * item + int(c) - int('0');
00085       input_stream.get(c);
00086    }
00087    return has_next_int;
00088 }
00089 
00090 #endif

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