moab
|
00001 00016 #ifndef FILE_TOKENIZER_HPP 00017 #define FILE_TOKENIZER_HPP 00018 00019 #include "moab/Types.hpp" 00020 #include <cstdio> 00021 #include <sys/types.h> 00022 00023 namespace moab { 00024 00025 class ReadUtilIface; 00026 00043 class FileTokenizer 00044 { 00045 public: 00046 00053 FileTokenizer( std::FILE* file_ptr, 00054 ReadUtilIface* read_util_ptr ); 00055 00064 ~FileTokenizer(); 00065 00076 const char* get_string( ); 00077 00088 bool get_newline( ); 00089 00090 00099 bool get_doubles( size_t count, double* array ); 00100 00101 00110 bool get_floats( size_t count, float* array ); 00111 00120 bool get_integers( size_t count, int* array ); 00121 00130 bool get_long_ints( size_t count, long* array ); 00131 00140 bool get_short_ints( size_t count, short* array ); 00141 00150 bool get_bytes( size_t count, unsigned char* array ); 00151 00158 bool get_binary( size_t bytes, void* mem ); 00159 00168 bool get_booleans( size_t count, bool* array ); 00169 00173 bool eof() const; 00174 00178 int line_number() const { return lineNumber; } 00179 00183 void unget_token(); 00184 00189 bool match_token( const char* string, bool print_error = true ); 00190 00200 int match_token( const char* const* string_list, bool print_error = true ); 00201 00202 private: 00203 00205 bool get_double_internal( double& result ); 00207 bool get_long_int_internal( long& result ); 00209 bool get_boolean_internal( bool& result ); 00210 00212 bool get_float_internal( float& result ); 00214 bool get_integer_internal( int& result ); 00216 bool get_short_int_internal( short& result ); 00218 bool get_byte_internal( unsigned char& result ); 00219 00221 std::FILE* filePtr; 00222 00224 ReadUtilIface* readUtilPtr; 00225 00227 char buffer[512]; 00228 00230 char *nextToken; 00232 char *bufferEnd; 00233 00235 int lineNumber; 00236 00242 char lastChar; 00243 }; 00244 00245 } // namespace moab 00246 00247 #endif