Parse a file as space-separated tokens. More...
#include <FileTokenizer.hpp>
Public Member Functions | |
FileTokenizer (msq_stdc::FILE *file_ptr) | |
constructor More... | |
~FileTokenizer () | |
destructor : closes file. More... | |
const char * | get_string (MsqError &err) |
get next token More... | |
bool | get_newline (MsqError &err) |
check for newline More... | |
bool | get_doubles (size_t count, double *array, MsqError &err) |
Parse a sequence of double values. More... | |
bool | get_floats (size_t count, float *array, MsqError &err) |
Parse a sequence of float values. More... | |
bool | get_integers (size_t count, int *array, MsqError &err) |
Parse a sequence of integer values. More... | |
bool | get_long_ints (size_t count, long *array, MsqError &err) |
Parse a sequence of integer values. More... | |
bool | get_short_ints (size_t count, short *array, MsqError &err) |
Parse a sequence of integer values. More... | |
bool | get_bytes (size_t count, unsigned char *array, MsqError &err) |
Parse a sequence of integer values. More... | |
bool | get_booleans (size_t count, bool *array, MsqError &err) |
Parse a sequence of bit or boolean values. More... | |
bool | eof () const |
Check for end-of-file condition. More... | |
int | line_number () const |
Get the line number the last token was read from. More... | |
void | unget_token () |
Put current token back in buffer. More... | |
bool | match_token (const char *string, MsqError &err) |
Match current token to passed string. More... | |
int | match_token (const char *const *string_list, MsqError &err) |
Match the current token to one of an array of strings. More... | |
FileTokenizer (msq_stdc::FILE *file_ptr) | |
constructor More... | |
~FileTokenizer () | |
destructor : closes file. More... | |
const char * | get_string (MsqError &err) |
get next token More... | |
bool | get_newline (MsqError &err) |
check for newline More... | |
bool | get_doubles (size_t count, double *array, MsqError &err) |
Parse a sequence of double values. More... | |
bool | get_floats (size_t count, float *array, MsqError &err) |
Parse a sequence of float values. More... | |
bool | get_integers (size_t count, int *array, MsqError &err) |
Parse a sequence of integer values. More... | |
bool | get_long_ints (size_t count, long *array, MsqError &err) |
Parse a sequence of integer values. More... | |
bool | get_short_ints (size_t count, short *array, MsqError &err) |
Parse a sequence of integer values. More... | |
bool | get_bytes (size_t count, unsigned char *array, MsqError &err) |
Parse a sequence of integer values. More... | |
bool | get_booleans (size_t count, bool *array, MsqError &err) |
Parse a sequence of bit or boolean values. More... | |
bool | eof () const |
Check for end-of-file condition. More... | |
int | line_number () const |
Get the line number the last token was read from. More... | |
void | unget_token () |
Put current token back in buffer. More... | |
bool | match_token (const char *string, MsqError &err) |
Match current token to passed string. More... | |
int | match_token (const char *const *string_list, MsqError &err) |
Match the current token to one of an array of strings. More... | |
Private Member Functions | |
bool | get_double_internal (double &result, MsqError &err) |
Internal implementation of get_doubles. More... | |
bool | get_long_int_internal (long &result, MsqError &err) |
Internal implementation of get_long_ints. More... | |
bool | get_boolean_internal (bool &result, MsqError &err) |
Internal implementation of get_Booleans. More... | |
bool | get_float_internal (float &result, MsqError &err) |
Internal implementation of get_floats. More... | |
bool | get_integer_internal (int &result, MsqError &err) |
Internal implementation of get_integers. More... | |
bool | get_short_int_internal (short &result, MsqError &err) |
Internal implementation of get_short_ints. More... | |
bool | get_byte_internal (unsigned char &result, MsqError &err) |
Internal implementation of get_bytes. More... | |
bool | get_double_internal (double &result, MsqError &err) |
Internal implementation of get_doubles. More... | |
bool | get_long_int_internal (long &result, MsqError &err) |
Internal implementation of get_long_ints. More... | |
bool | get_boolean_internal (bool &result, MsqError &err) |
Internal implementation of get_Booleans. More... | |
bool | get_float_internal (float &result, MsqError &err) |
Internal implementation of get_floats. More... | |
bool | get_integer_internal (int &result, MsqError &err) |
Internal implementation of get_integers. More... | |
bool | get_short_int_internal (short &result, MsqError &err) |
Internal implementation of get_short_ints. More... | |
bool | get_byte_internal (unsigned char &result, MsqError &err) |
Internal implementation of get_bytes. More... | |
Private Attributes | |
msq_stdc::FILE * | filePtr |
Pointer to standard C FILE struct. More... | |
char | buffer [512] |
Input buffer. More... | |
char * | nextToken |
One past the end of the last token returned. More... | |
char * | bufferEnd |
One past the last used byte of the buffer. More... | |
int | lineNumber |
Line number of last returned token. More... | |
char | lastChar |
The whitespace character marking the end of the last returned token. More... | |
Parse a file as space-separated tokens.
Read a file, separating it into space-separated tokens. This is provided in place of using the standard C or C++ file parsing routines because it counts lines, which is useful for error reporting. Also provides some useful utility methods for parsing VTK files (which is the intended use of this implementation.)
Uses raw reads/writes, implementing internal buffering. Token size may not exceed buffer size.
Definition at line 60 of file includeLinks/FileTokenizer.hpp.
FileTokenizer | ( | msq_stdc::FILE * | file_ptr | ) |
constructor
file_ptr | The file to read from. |
~FileTokenizer | ( | ) |
destructor : closes file.
The destructor closes the passed file handle. This is done as a convenience feature. If the caller creates an instance of this object on the stack, the file will automatically be closed when the caller returns.
Definition at line 50 of file Misc/FileTokenizer.cpp.
References cimg_library::cimg::fclose().
FileTokenizer | ( | msq_stdc::FILE * | file_ptr | ) |
constructor
file_ptr | The file to read from. |
~FileTokenizer | ( | ) |
destructor : closes file.
The destructor closes the passed file handle. This is done as a convenience feature. If the caller creates an instance of this object on the stack, the file will automatically be closed when the caller returns.
bool eof | ( | ) | const |
Check for end-of-file condition.
Definition at line 53 of file Misc/FileTokenizer.cpp.
Referenced by MeshImpl::read_vtk().
bool eof | ( | ) | const |
Check for end-of-file condition.
|
private |
Internal implementation of get_Booleans.
Definition at line 272 of file Misc/FileTokenizer.cpp.
References MSQ_CHKERR, and MSQ_SETERR.
|
private |
Internal implementation of get_Booleans.
bool get_booleans | ( | size_t | count, |
bool * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of bit or boolean values.
Read the specified number of space-deliminated values.
count | The number of values to read. |
array | The memory at which to store the values. |
Definition at line 363 of file Misc/FileTokenizer.cpp.
References i, and MSQ_CHKERR.
Referenced by MeshImpl::vtk_read_typed_data().
bool get_booleans | ( | size_t | count, |
bool * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of bit or boolean values.
Read the specified number of space-deliminated values.
count | The number of values to read. |
array | The memory at which to store the values. |
|
private |
Internal implementation of get_bytes.
Definition at line 221 of file Misc/FileTokenizer.cpp.
References i, MSQ_CHKERR, and MSQ_SETERR.
|
private |
Internal implementation of get_bytes.
bool get_bytes | ( | size_t | count, |
unsigned char * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of integer values.
Read the specified number of space-deliminated ints.
count | The number of values to read. |
array | The memory at which to store the values. |
Definition at line 314 of file Misc/FileTokenizer.cpp.
References i, and MSQ_CHKERR.
bool get_bytes | ( | size_t | count, |
unsigned char * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of integer values.
Read the specified number of space-deliminated ints.
count | The number of values to read. |
array | The memory at which to store the values. |
|
private |
Internal implementation of get_doubles.
|
private |
Internal implementation of get_doubles.
Definition at line 144 of file Misc/FileTokenizer.cpp.
References MSQ_CHKERR, and MSQ_SETERR.
bool get_doubles | ( | size_t | count, |
double * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of double values.
Read the specified number of space-deliminated doubles.
count | The number of values to read. |
array | The memory at which to store the values. |
Definition at line 302 of file Misc/FileTokenizer.cpp.
References i, and MSQ_CHKERR.
Referenced by MeshImpl::vtk_read_field(), MeshImpl::vtk_read_polydata(), MeshImpl::vtk_read_rectilinear_grid(), MeshImpl::vtk_read_scalar_attrib(), MeshImpl::vtk_read_structured_grid(), MeshImpl::vtk_read_structured_points(), MeshImpl::vtk_read_typed_data(), and MeshImpl::vtk_read_unstructured_grid().
bool get_doubles | ( | size_t | count, |
double * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of double values.
Read the specified number of space-deliminated doubles.
count | The number of values to read. |
array | The memory at which to store the values. |
|
private |
Internal implementation of get_floats.
Definition at line 180 of file Misc/FileTokenizer.cpp.
References d, MSQ_CHKERR, and MSQ_SETERR.
|
private |
Internal implementation of get_floats.
bool get_floats | ( | size_t | count, |
float * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of float values.
Read the specified number of space-deliminated doubles.
count | The number of values to read. |
array | The memory at which to store the values. |
Definition at line 291 of file Misc/FileTokenizer.cpp.
References i.
Referenced by MeshImpl::vtk_read_color_attrib(), and MeshImpl::vtk_read_scalar_attrib().
bool get_floats | ( | size_t | count, |
float * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of float values.
Read the specified number of space-deliminated doubles.
count | The number of values to read. |
array | The memory at which to store the values. |
|
private |
Internal implementation of get_integers.
|
private |
Internal implementation of get_integers.
Definition at line 255 of file Misc/FileTokenizer.cpp.
References i, MSQ_CHKERR, and MSQ_SETERR.
bool get_integers | ( | size_t | count, |
int * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of integer values.
Read the specified number of space-deliminated ints.
count | The number of values to read. |
array | The memory at which to store the values. |
bool get_integers | ( | size_t | count, |
int * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of integer values.
Read the specified number of space-deliminated ints.
count | The number of values to read. |
array | The memory at which to store the values. |
Definition at line 339 of file Misc/FileTokenizer.cpp.
References i, and MSQ_CHKERR.
Referenced by MeshImpl::vtk_read_texture_attrib(), and MeshImpl::vtk_read_typed_data().
|
private |
Internal implementation of get_long_ints.
Definition at line 197 of file Misc/FileTokenizer.cpp.
References MSQ_CHKERR, and MSQ_SETERR.
|
private |
Internal implementation of get_long_ints.
bool get_long_ints | ( | size_t | count, |
long * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of integer values.
Read the specified number of space-deliminated ints.
count | The number of values to read. |
array | The memory at which to store the values. |
bool get_long_ints | ( | size_t | count, |
long * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of integer values.
Read the specified number of space-deliminated ints.
count | The number of values to read. |
array | The memory at which to store the values. |
Definition at line 351 of file Misc/FileTokenizer.cpp.
References i, and MSQ_CHKERR.
Referenced by MeshImpl::read_vtk(), MeshImpl::vtk_read_color_attrib(), MeshImpl::vtk_read_field(), MeshImpl::vtk_read_polydata(), MeshImpl::vtk_read_polygons(), MeshImpl::vtk_read_rectilinear_grid(), MeshImpl::vtk_read_scalar_attrib(), MeshImpl::vtk_read_structured_grid(), MeshImpl::vtk_read_structured_points(), and MeshImpl::vtk_read_unstructured_grid().
bool get_newline | ( | MsqError & | err | ) |
check for newline
Consume whitespace upto and including the next newline. If a non-space character is found before a newline, the function will stop, set the error message, and return false.
bool get_newline | ( | MsqError & | err | ) |
check for newline
Consume whitespace upto and including the next newline. If a non-space character is found before a newline, the function will stop, set the error message, and return false.
Definition at line 442 of file Misc/FileTokenizer.cpp.
References cimg_library::cimg::fread(), and MSQ_SETERR.
Referenced by MeshImpl::vtk_read_polydata(), MeshImpl::vtk_read_polygons(), MeshImpl::vtk_read_rectilinear_grid(), MeshImpl::vtk_read_structured_grid(), MeshImpl::vtk_read_structured_points(), and MeshImpl::vtk_read_unstructured_grid().
|
private |
Internal implementation of get_short_ints.
Definition at line 238 of file Misc/FileTokenizer.cpp.
References i, MSQ_CHKERR, and MSQ_SETERR.
|
private |
Internal implementation of get_short_ints.
bool get_short_ints | ( | size_t | count, |
short * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of integer values.
Read the specified number of space-deliminated ints.
count | The number of values to read. |
array | The memory at which to store the values. |
bool get_short_ints | ( | size_t | count, |
short * | array, | ||
MsqError & | err | ||
) |
Parse a sequence of integer values.
Read the specified number of space-deliminated ints.
count | The number of values to read. |
array | The memory at which to store the values. |
Definition at line 326 of file Misc/FileTokenizer.cpp.
References i, and MSQ_CHKERR.
const char * get_string | ( | MsqError & | err | ) |
get next token
Get the next whitesapce-deliminated token from the file. NOTE: The returned string is only valid until the next call to any of the functions in this class that read from the file.
Definition at line 56 of file Misc/FileTokenizer.cpp.
References cimg_library::cimg::fread(), and MSQ_SETERR.
Referenced by MeshImpl::vtk_read_attrib_data(), MeshImpl::vtk_read_field(), and MeshImpl::vtk_read_scalar_attrib().
const char* get_string | ( | MsqError & | err | ) |
get next token
Get the next whitesapce-deliminated token from the file. NOTE: The returned string is only valid until the next call to any of the functions in this class that read from the file.
|
inline |
Get the line number the last token was read from.
Definition at line 184 of file src/Misc/FileTokenizer.hpp.
References FileTokenizer::lineNumber.
|
inline |
Get the line number the last token was read from.
Definition at line 184 of file includeLinks/FileTokenizer.hpp.
References FileTokenizer::lineNumber.
Referenced by MeshImpl::read_vtk(), MeshImpl::vtk_read_attrib_data(), MeshImpl::vtk_read_cell_data(), MeshImpl::vtk_read_color_attrib(), MeshImpl::vtk_read_point_data(), MeshImpl::vtk_read_polydata(), MeshImpl::vtk_read_rectilinear_grid(), MeshImpl::vtk_read_scalar_attrib(), MeshImpl::vtk_read_structured_grid(), MeshImpl::vtk_read_structured_points(), MeshImpl::vtk_read_texture_attrib(), and MeshImpl::vtk_read_unstructured_grid().
bool match_token | ( | const char * | string, |
MsqError & | err | ||
) |
Match current token to passed string.
If token doesn't match, set error message.
bool match_token | ( | const char * | string, |
MsqError & | err | ||
) |
Match current token to passed string.
If token doesn't match, set error message.
Definition at line 392 of file Misc/FileTokenizer.cpp.
References MSQ_CHKERR, and MSQ_SETERR.
Referenced by MeshImpl::read_vtk(), MeshImpl::vtk_read_attrib_data(), MeshImpl::vtk_read_dataset(), MeshImpl::vtk_read_field(), MeshImpl::vtk_read_polydata(), MeshImpl::vtk_read_rectilinear_grid(), MeshImpl::vtk_read_scalar_attrib(), MeshImpl::vtk_read_structured_grid(), MeshImpl::vtk_read_structured_points(), MeshImpl::vtk_read_tensor_attrib(), MeshImpl::vtk_read_texture_attrib(), MeshImpl::vtk_read_unstructured_grid(), and MeshImpl::vtk_read_vector_attrib().
int match_token | ( | const char *const * | string_list, |
MsqError & | err | ||
) |
Match the current token to one of an array of strings.
Sets the error message if the current token doesn't match any of the input strings.
string_list | A NULL-terminated array of strings. |
int match_token | ( | const char *const * | string_list, |
MsqError & | err | ||
) |
Match the current token to one of an array of strings.
Sets the error message if the current token doesn't match any of the input strings.
string_list | A NULL-terminated array of strings. |
Definition at line 411 of file Misc/FileTokenizer.cpp.
References MSQ_CHKERR, and MSQ_SETERR.
void unget_token | ( | ) |
Put current token back in buffer.
Can only unget one token.
void unget_token | ( | ) |
Put current token back in buffer.
Can only unget one token.
Definition at line 375 of file Misc/FileTokenizer.cpp.
Referenced by MeshImpl::read_vtk(), and MeshImpl::vtk_read_scalar_attrib().
|
private |
Input buffer.
Definition at line 230 of file includeLinks/FileTokenizer.hpp.
|
private |
One past the last used byte of the buffer.
Definition at line 235 of file includeLinks/FileTokenizer.hpp.
|
private |
Pointer to standard C FILE struct.
Definition at line 227 of file includeLinks/FileTokenizer.hpp.
|
private |
The whitespace character marking the end of the last returned token.
Saved here because if it is a newline, the line count will need to be incremented when the next token is returned.
Definition at line 245 of file includeLinks/FileTokenizer.hpp.
|
private |
Line number of last returned token.
Definition at line 238 of file includeLinks/FileTokenizer.hpp.
Referenced by FileTokenizer::line_number().
|
private |
One past the end of the last token returned.
Definition at line 233 of file includeLinks/FileTokenizer.hpp.