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

brBufferedTransactionReader.hpp

Go to the documentation of this file.
00001 
00009 #ifndef brBufferedTransactionReader_050405
00010 #define brBufferedTransactionReader_050405
00011 
00012 
00013 #include "io/input/transaction_reader/BufferedTransactionReader.hpp"  
00014 #include <stdio.h>
00015 #include <fstream> //for exceptions
00016 #include <string.h>
00017 #include <cerrno>
00018 #include "common/log.h"
00019 #include <string>
00020 
00021 
00026 template <class T_R = TransactionReader<> >
00027 class brBufferedTransactionReader : public BufferedTransactionReader<T_R>
00028 {
00029    private:
00030       char *bufp, *bufend;
00031       bool ateof;
00032 
00033    public:
00034       typedef typename BufferedTransactionReader<T_R>::params_t params_t;
00035 
00036       brBufferedTransactionReader( const params_t* par) : 
00037          BufferedTransactionReader<T_R>(par)
00038       {
00039          //setbuffer(fin,buffer,buffer_size);
00040       }
00041 
00042       inline void DINLINE nextChar(char &c) 
00043       {
00044          c=*bufp;
00045          if ((++bufp)==bufend) {
00046             bufp=this->buffer;
00047             std::streamsize r=readFromFile(this->buffer,this->buffer_size);
00048             if (r)
00049                bufend=bufp + r;
00050             else {
00051                ateof=true;
00052                *bufp='\n';
00053             }
00054          }
00055       } 
00056 
00062       template <class BIS> counter_t nextTransactionBIS( BIS& Items ){
00063          Items.clear();
00064          if (ateof) {
00065             return 0;
00066          }
00067          char c;
00068          do {
00069             item_t item=0;
00070             nextChar(c);
00071             //        int pos=0;
00072             if ((c >= '0') && (c <= '9')) {
00073                item = (c-'0');
00074                nextChar(c);
00075                while((c >= '0') && (c <= '9')) {
00076                   item *=10;
00077                   item += int(c)-int('0');
00078                   // c = getc(fin);
00079                   nextChar(c);
00080                }
00081                Items.push_back(item);
00082             }
00083             /*          if (item>largest_item)
00084                         largest_item=item;*/
00085          }while((c != '\n') && (!ateof));
00086          if (Items.size())
00087             return 1;
00088          return 0;
00089       }
00090 
00094       template <class UAC> counter_t nextTransactionUAC( UAC& transaction ){
00095          transaction.clear();
00096          return 0;
00097       }
00098 
00100       void rewind()
00101       {
00102          T_R::rewind();
00103          std::streamsize r = readFromFile(this->buffer,this->buffer_size);;
00104          bufp = this->buffer; 
00105          bufend = this->buffer + r;
00106          ateof = false;
00107       }
00108 }; //class bufferedtransactionreader
00109 
00110 #endif //brBufferedTransactionReader_050405

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