Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/FileTokenizer.hpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Lawrence Livermore National Laboratory. Under
5  the terms of Contract B545069 with the University of Wisconsin --
6  Madison, Lawrence Livermore National Laboratory retains certain
7  rights in this software.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  kraftche@cae.wisc.edu
24 
25  ***************************************************************** */
26 
27 #ifndef FILE_TOKENIZER_HPP
28 #define FILE_TOKENIZER_HPP
29 
30 #ifdef MSQ_USE_OLD_C_HEADERS
31 # include <stdio.h>
32 #else
33 # include <cstdio>
34 #endif
35 #include "Mesquite.hpp"
36 #include <sys/types.h>
37 
38 namespace Mesquite
39 {
40 
41  class MsqError;
42 
61 {
62  public:
63 
68  FileTokenizer( msq_stdc::FILE* file_ptr );
69 
79 
90  const char* get_string( MsqError& err );
91 
102  bool get_newline( MsqError& err );
103 
104 
113  bool get_doubles( size_t count, double* array, MsqError& err );
114 
115 
124  bool get_floats( size_t count, float* array, MsqError& err );
125 
134  bool get_integers( size_t count, int* array, MsqError& err );
135 
144  bool get_long_ints( size_t count, long* array, MsqError& err );
145 
154  bool get_short_ints( size_t count, short* array, MsqError& err );
155 
164  bool get_bytes( size_t count, unsigned char* array, MsqError& err );
165 
174  bool get_booleans( size_t count, bool* array, MsqError& err );
175 
179  bool eof() const;
180 
184  int line_number() const { return lineNumber; }
185 
189  void unget_token();
190 
195  bool match_token( const char* string, MsqError& err );
196 
206  int match_token( const char* const* string_list, MsqError& err );
207 
208  private:
209 
211  bool get_double_internal( double& result, MsqError& err );
213  bool get_long_int_internal( long& result, MsqError& err );
215  bool get_boolean_internal( bool& result, MsqError& err );
216 
218  bool get_float_internal( float& result, MsqError& err );
220  bool get_integer_internal( int& result, MsqError& err );
222  bool get_short_int_internal( short& result, MsqError& err );
224  bool get_byte_internal( unsigned char& result, MsqError& err );
225 
227  msq_stdc::FILE* filePtr;
228 
230  char buffer[512];
231 
233  char *nextToken;
235  char *bufferEnd;
236 
239 
245  char lastChar;
246 };
247 
248 } // namespace Mesquite
249 
250 #endif
bool get_boolean_internal(bool &result, MsqError &err)
Internal implementation of get_Booleans.
int line_number() const
Get the line number the last token was read from.
void unget_token()
Put current token back in buffer.
~FileTokenizer()
destructor : closes file.
bool get_float_internal(float &result, MsqError &err)
Internal implementation of get_floats.
bool get_long_int_internal(long &result, MsqError &err)
Internal implementation of get_long_ints.
bool match_token(const char *string, MsqError &err)
Match current token to passed string.
Used to hold the error state and return it to the application.
bool get_newline(MsqError &err)
check for newline
bool get_floats(size_t count, float *array, MsqError &err)
Parse a sequence of float values.
bool get_short_ints(size_t count, short *array, MsqError &err)
Parse a sequence of integer values.
bool get_doubles(size_t count, double *array, MsqError &err)
Parse a sequence of double values.
const char * get_string(MsqError &err)
get next token
bool get_bytes(size_t count, unsigned char *array, MsqError &err)
Parse a sequence of integer values.
FileTokenizer(msq_stdc::FILE *file_ptr)
constructor
bool get_long_ints(size_t count, long *array, MsqError &err)
Parse a sequence of integer values.
bool get_short_int_internal(short &result, MsqError &err)
Internal implementation of get_short_ints.
char * bufferEnd
One past the last used byte of the buffer.
char * nextToken
One past the end of the last token returned.
bool get_double_internal(double &result, MsqError &err)
Internal implementation of get_doubles.
bool get_integer_internal(int &result, MsqError &err)
Internal implementation of get_integers.
bool get_booleans(size_t count, bool *array, MsqError &err)
Parse a sequence of bit or boolean values.
bool get_byte_internal(unsigned char &result, MsqError &err)
Internal implementation of get_bytes.
msq_stdc::FILE * filePtr
Pointer to standard C FILE struct.
bool get_integers(size_t count, int *array, MsqError &err)
Parse a sequence of integer values.
int lineNumber
Line number of last returned token.
char lastChar
The whitespace character marking the end of the last returned token.
bool eof() const
Check for end-of-file condition.
Parse a file as space-separated tokens.