00001 #ifndef InputreaderTester_HPP 00002 #define InputreaderTester_HPP 00003 00007 #include "common.hpp" 00008 #include "common/log.h" 00009 #include "io/input/transaction_reader/TransactionReader.hpp" 00010 #include "io/input/transaction_reader/LBufferedTransactionReader.hpp" 00011 #include "io/input/transaction_reader/brBufferedTransactionReader.hpp" 00012 #include "io/FileReprBase.hpp" 00013 #include <vector> 00014 00015 #if DEBUG_LEVEL >= LEVEL_DBG 00016 #include <iterator> 00017 #endif 00018 00041 class InputreaderTester 00042 { 00043 public: 00045 void usageSimpleInput(); 00046 00047 00049 void doTest( int argc, char *argv[] ); 00050 private: 00052 template <class F_R> void selectReader( 00053 char* reader, char* file_name, unsigned int nr_of_scan, 00054 std::streamsize lowlevel_buffer_size); 00055 00057 template <class T_R> void readDatabase( 00058 char* file_name, unsigned int nr_of_scan, 00059 std::streamsize lowlevel_buffer_size); 00060 }; 00069 template <class F_R> void InputreaderTester::selectReader( 00070 char* reader, char* file_name, unsigned int nr_of_scan, 00071 std::streamsize lowlevel_buffer_size) 00072 { 00073 if( strcmp(reader, "lars") == 0 ) 00074 { 00075 log_info(0,"Lars' buffered transaction reader is selected for test."); 00076 readDatabase< LBufferedTransactionReader< TransactionReader<F_R> > >( 00077 file_name, nr_of_scan, lowlevel_buffer_size); 00078 } 00079 else if( strcmp(reader, "bracz") == 0 ) 00080 { 00081 log_info(0,"Bracz' buffered transaction reader is selected for test."); 00082 readDatabase< brBufferedTransactionReader< TransactionReader<F_R> > >( 00083 file_name, nr_of_scan, lowlevel_buffer_size); 00084 } 00085 else 00086 usageSimpleInput(); 00087 } 00088 00096 template <class T_R> void InputreaderTester::readDatabase( 00097 char* file_name, unsigned int nr_of_scan, 00098 std::streamsize lowlevel_buffer_size) 00099 { 00100 typename T_R::params_t par; 00101 par.file_name = file_name; 00102 par.mode = FileReprBase::READ; 00103 par.file_buffer_size = lowlevel_buffer_size; 00104 00105 try 00106 { 00107 T_R t_r(&par); 00108 std::vector<item_t> transaction; 00109 while(nr_of_scan) 00110 { 00111 --nr_of_scan; 00112 t_r.rewind(); 00113 log_info(0,"New scan started."); 00114 while( t_r.nextTransactionBIS(transaction) ) 00115 { 00116 #if DEBUG_LEVEL >= LEVEL_DBG 00117 std::copy( transaction.begin(), transaction.end(), 00118 std::ostream_iterator<item_t>(std::cout, " ")); 00119 std::cout<<std::endl; 00120 #endif 00121 } 00122 } 00123 } 00124 catch (std::ios_base::failure e) 00125 { 00126 log_err(0,"Exiting the program due to IO exception"); 00127 exit(1); 00128 } 00129 } 00130 00131 #endif