Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArFileParser Class Reference

Class for parsing files more easily. More...

#include <ArFileParser.h>

List of all members.

Public Member Functions

bool addHandler (const char *keyword, ArRetFunctor1< bool, ArArgumentBuilder * > *functor)
 Adds a functor to handle a keyword that wants an easily parsable string.
bool addHandlerWithError (const char *keyword, ArRetFunctor3< bool, ArArgumentBuilder *, char *, size_t > *functor)
 Adds a functor to handle a keyword that wants an easily parsable string and returns error messages.
 ArFileParser (const char *baseDirectory="./")
 Constructor.
const char * getBaseDirectory (void) const
 Gets the base directory.
bool parseFile (FILE *file, char *buffer, int bufferLength, bool continueOnErrors=true, char *errorBuffer=NULL, size_t errorBufferLen=0)
 Parses an open file; the file is not closed by this method.
bool parseFile (const char *fileName, bool continueOnErrors=true, bool noFileNotFoundMessage=false, char *errorBuffer=NULL, size_t errorBufferLen=0)
 The function to parse a file.
bool parseLine (char *line, char *errorBuffer=NULL, size_t errorBufferLen=0)
 Function to parse a single line.
bool remHandler (ArRetFunctor3< bool, ArArgumentBuilder *, char *, size_t > *functor)
 Removes any handlers with this functor.
bool remHandler (ArRetFunctor1< bool, ArArgumentBuilder * > *functor)
 Removes any handlers with this functor.
bool remHandler (const char *keyword, bool logIfCannotFind=true)
 Removes a handler for a keyword.
void resetCounters (void)
 Function to reset counters.
void setBaseDirectory (const char *baseDirectory)
 Sets the base directory.
 ~ArFileParser (void)
 Destructor.

Protected Attributes

std::string myBaseDir
int myLineNumber
std::map< std::string, HandlerCBType *,
ArStrCaseCmpOp > 
myMap
HandlerCBType * myRemainderHandler

Classes

class  HandlerCBType


Detailed Description

Class for parsing files more easily.

This class is set up so that you can parse a file more easily... basically you add a bunch of functors of different types of arguments with addHandler then call parseFile to parse the file, parseFile returns true if there were no errors parsing and false if there were errors.

One side feature is that you can have ONE handler for the keyword NULL, and if there is a line read that isn't entirely comments or whitespace that handler will be given the line. There isn't an explicit set for them since then there'd be another set of 5 adds.

There should be some whitespace after keywords in the file, and any semicolon (;) will act as a comment with the rest of the line ignored. If no handler exists for the first word the line is passed to the handler above for NULL. You can't have any lines longer than 10000 characters or keywords longer than 512 characters (though I don't know why you'd have either). If you have more than 2048 words on a line you'll have problems as well.

Definition at line 56 of file ArFileParser.h.


Member Function Documentation

bool ArFileParser::addHandlerWithError const char *  keyword,
ArRetFunctor3< bool, ArArgumentBuilder *, char *, size_t > *  functor
 

Adds a functor to handle a keyword that wants an easily parsable string and returns error messages.

This function has a different name than addProcessFileCB just so that if you mean to get this function but have the wrong functor you'll get an error. The rem's are the same though since that shouldn't matter.

Definition at line 81 of file ArFileParser.cpp.

References ArLog::log().

Referenced by ArConfig::addParam(), and ArConfig::ArConfig().

bool ArFileParser::parseFile FILE *  file,
char *  buffer,
int  bufferLength,
bool  continueOnErrors = true,
char *  errorBuffer = NULL,
size_t  errorBufferLen = 0
 

Parses an open file; the file is not closed by this method.

Parameters:
file the open FILE* to be parsed; must not be NULL
buffer a non-NULL char array in which to read the file
bufferLength the number of chars in the buffer; must be greater than 0
continueOnErrors a bool set to true if parsing should continue even after an error is detected

Definition at line 470 of file ArFileParser.cpp.

References parseLine(), and resetCounters().

bool ArFileParser::parseFile const char *  fileName,
bool  continueOnErrors = true,
bool  noFileNotFoundMessage = false,
char *  errorBuffer = NULL,
size_t  errorBufferLen = 0
 

The function to parse a file.

Parameters:
fileName the file to open
continueOnError whether to continue or immediately bail upon an error
noFileNotFoundMessage whether or not to log if we find a file (we normally want to but for robot param files that'd be too annoying since we test for a lot of files)
errorBuffer buffer to put errors into, can be NULL, only the first error is saved, and as soon as this function is called it immediately empties the errorBuffer
errorBufferLen the length of the errorBuffer

if( setvbuf( file, buf, _IOFBF, sizeof( buf ) ) != 0 ) printf( "Incorrect type or size of buffer for file\n" ); else printf( "'file' now has a buffer of 1024 bytes\n" );

Definition at line 407 of file ArFileParser.cpp.

References ArLog::log(), parseLine(), and resetCounters().

Referenced by ArConfig::parseFile().


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:45 2005 for Aria by  doxygen 1.4.0