/* * Buffer.h * */ #ifndef PROCESSOR_BUFFER_H_ #define PROCESSOR_BUFFER_H_ #include using namespace std; #include "Math/Share.h" #include "Math/field_types.h" #include "Tools/time-func.h" #include "config.h" #ifndef BUFFER_SIZE #define BUFFER_SIZE 101 #endif class BufferBase { protected: static bool rewind; ifstream* file; int next; const char* data_type; const char* field_type; Timer timer; int tuple_length; string filename; public: bool eof; BufferBase() : file(0), next(BUFFER_SIZE), data_type(0), field_type(0), tuple_length(-1), eof(false) {} void setup(ifstream* f, int length, string filename, const char* type = 0, const char* field = 0); void seekg(int pos); bool is_up() { return file != 0; } void try_rewind(); void prune(); void purge(); }; template class Buffer : public BufferBase { T buffer[BUFFER_SIZE]; void read(char* read_buffer); public: ~Buffer(); void input(U& a); void fill_buffer(); }; template < template class U, template class V > class BufferHelper { public: Buffer< U, V > bufferp; Buffer< U, V > buffer2; ifstream* files[N_DATA_FIELD_TYPE]; BufferHelper() { memset(files, 0, sizeof(files)); } void input(V& a) { bufferp.input(a); } void input(V& a) { buffer2.input(a); } BufferBase& get_buffer(DataFieldType field_type); void setup(DataFieldType field_type, string filename, int tuple_length, const char* data_type = 0); void close(); void prune(); void purge(); }; #endif /* PROCESSOR_BUFFER_H_ */