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

ArConfig Class Reference

Classes dealing with config files can inherit from this one. More...

#include <ArConfig.h>

Inheritance diagram for ArConfig:

ArRobotParams List of all members.

Public Member Functions

bool addComment (const char *comment, const char *sectionName="", ArPriority::Priority priority=ArPriority::NORMAL)
 Command to add a new comment to the given section with given priority.
bool addParam (const ArConfigArg &arg, const char *sectionName="", ArPriority::Priority priority=ArPriority::NORMAL)
 Command to add a parameter to the given section with given priority.
void addProcessFileCB (ArRetFunctor< bool > *functor, int priority=0)
 Adds a processedFile callback.
void addProcessFileWithErrorCB (ArRetFunctor2< bool, char *, size_t > *functor, int priority=0)
 Adds a processedFile callback with error messages.
 ArConfig (const ArConfig &config)
 Copy constructor.
 ArConfig (const char *baseDirectory=NULL, bool noBlanksBetweenParams=false, bool ignoreBounds=false, bool failOnBadSection=false)
 Constructor.
bool callProcessFileCallBacks (bool continueOnError, char *errorBuffer, size_t errorBufferLen)
 Call the processFileCBs.
void clearAll (void)
 Clears out all the section information and the processFileCBs.
void clearSections (void)
 Clears out all the section information.
ArConfigSectionfindSection (const char *sectionName) const
 Finds the section with the given name. Returns NULL if not found.
const char * getBaseDirectory (void) const
 Gets the base directory.
const char * getFileName (void) const
 Gets the file name we loaded.
bool getNoBlanksBetweenParams (void)
 Get whether we have blanks between the params or not.
ArLog::LogLevel getProcessFileCallbacksLogLevel (void)
 Gets the level we log our map changed callback at.
std::list< ArConfigSection * > * getSections (void)
 Gets the sections themselves (use only if you know what to do).
ArConfigoperator= (const ArConfig &config)
bool parseArgument (ArArgumentBuilder *arg, char *errorBuffer=NULL, size_t errorBufferLen=0)
 This parses the argument given (for parser or other use).
bool parseArgumentParser (ArArgumentParser *parser, bool continueOnError=false, char *errorBuffer=NULL, size_t errorBufferLen=0)
 Uses an argument parser to change the config.
bool parseFile (const char *fileName, bool continueOnError=false, bool noFileNotFoundMessage=false, char *errorBuffer=NULL, size_t errorBufferLen=0)
 Parse a config file.
bool parseSection (ArArgumentBuilder *arg, char *errorBuffer=NULL, size_t errorBufferLen=0)
 This parses the section change (for parser or other use).
virtual bool processFile (void)
 for inheritors this is called after the file is processed
void remProcessFileCB (ArRetFunctor2< bool, char *, size_t > *functor)
 Removes a processedFile callback.
void remProcessFileCB (ArRetFunctor< bool > *functor)
 Removes a processedFile callback.
void setBaseDirectory (const char *baseDirectory)
 Sets the base directory.
void setNoBlanksBetweenParams (bool noBlanksBetweenParams)
 Set whether we have blanks between the params or not.
void setProcessFileCallbacksLogLevel (ArLog::LogLevel level)
 Sets the level we log our map changed callback at.
void setSectionComment (const char *sectionName, const char *comment)
 Sets the comment for a section.
void useArgumentParser (ArArgumentParser *parser)
 Uses this argument parser after it parses a file before it processes.
bool writeFile (const char *fileName, bool append=false, std::set< std::string > *alreadyWritten=NULL, bool writePriorities=false)
 Write out a config file with defaults.
virtual ~ArConfig ()
 Destructor.

Protected Member Functions

void addParserHandlers (void)

Protected Attributes

ArArgumentParsermyArgumentParser
std::string myBaseDirectory
bool myDuplicateParams
bool myFailOnBadSection
std::string myFileName
bool myIgnoreBounds
bool myNoBlanksBetweenParams
ArFileParser myParser
ArRetFunctor3C< bool, ArConfig,
ArArgumentBuilder *, char *,
size_t > 
myParserCB
ArLog::LogLevel myProcessFileCallbacksLogLevel
std::multimap< int, ProcessFileCBType * > myProcessFileCBList
std::string mySection
bool mySectionBroken
ArRetFunctor3C< bool, ArConfig,
ArArgumentBuilder *, char *,
size_t > 
mySectionCB
std::list< ArConfigSection * > mySections
bool myUsingSections

Classes

class  ProcessFileCBType

Detailed Description

Classes dealing with config files can inherit from this one.

Definition at line 41 of file ArConfig.h.


Constructor & Destructor Documentation

ArConfig::ArConfig const char *  baseDirectory = NULL,
bool  noBlanksBetweenParams = false,
bool  ignoreBounds = false,
bool  failOnBadSection = false
 

Constructor.

Parameters:
baseDirectory the directory to load fomr
noBlanksBetweenParams if there should be blanks between params in output
ignoreBounds if this is true bounds checking will be ignored when the file is read in this should ONLY be used by developers debugging
failOnBadSections if this is true and there is a bad section the parseFile will fail

Definition at line 39 of file ArConfig.cpp.

References ArFileParser::addHandlerWithError(), ArLog::log(), and setBaseDirectory().


Member Function Documentation

bool ArConfig::addComment const char *  comment,
const char *  sectionName = "",
ArPriority::Priority  priority = ArPriority::NORMAL
 

Command to add a new comment to the given section with given priority.

Parameters:
comment 

Definition at line 267 of file ArConfig.cpp.

References addParam().

Referenced by ArRobotParams::ArRobotParams().

void ArConfig::addProcessFileCB ArRetFunctor< bool > *  functor,
int  priority = 0
 

Adds a processedFile callback.

After a file has been read all the way these processFileCBs are called in the priority (higher numbers first)... these are only called if there were no errors parsing the file or continueOnError was set to false when parseFile was called

The functor should return true if the config parsed was good (parseFile will return true) false if the config parsed wasn't (parseFile will return false)

Parameters:
functor the functor to call
priority the functors are called in descending order, if two things have the same number the first one added is the first one called

Definition at line 933 of file ArConfig.cpp.

void ArConfig::addProcessFileWithErrorCB ArRetFunctor2< bool, char *, size_t > *  functor,
int  priority = 0
 

Adds a processedFile callback with 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.

After a file has been read all the way these processFileCBs are called in the priority (higher numbers first)... these are only called if there were no errors parsing the file or continueOnError was set to false when parseFile was called

The functor should return true if the config parsed was good (parseFile will return true) false if the config parsed wasn't (parseFile will return false)

Parameters:
functor the functor to call (the char * and unsigned int should be used by the functor to put an error message into that buffer)
priority the functors are called in descending order, if two things have the same number the first one added is the first one called

Definition at line 984 of file ArConfig.cpp.

Referenced by ArMap::ArMap().

bool ArConfig::parseArgument ArArgumentBuilder arg,
char *  errorBuffer = NULL,
size_t  errorBufferLen = 0
 

This parses the argument given (for parser or other use).

The extra string of the parser should be set to the command wanted, while the rest of the arg should be the arguments to the command. Its case insensitive.

Parameters:
errorBuffer if this is NULL it is ignored, otherwise the string for the error is put into the buffer, the first word should be the parameter that has trouble
errorBufferLen the length of the error buffer

Definition at line 349 of file ArConfig.cpp.

References ArConfigArg::getName(), ArConfigSection::getName(), ArConfigSection::getParams(), ArConfigArg::getString(), ArConfigArg::getType(), ArLog::log(), ArConfigArg::setArgWithFunctor(), ArConfigArg::setBool(), ArConfigArg::setDouble(), ArConfigArg::setInt(), ArConfigArg::setString(), and ArUtil::strcasecmp().

Referenced by parseArgumentParser().

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

Parse a config file.

Parameters:
fileName the file to load
continueOnErrors whether to continue parsing if we get errors (or just bail)
noFileNotFoundMessage if the file isn't found and this param is true it won't complain, otherwise it will
errorBuffer buffer to pass error information into
errorBufferLen the length of the errorBuffer

Definition at line 564 of file ArConfig.cpp.

References callProcessFileCallBacks(), parseArgumentParser(), and ArFileParser::parseFile().

Referenced by ArRobot::loadParamFile(), and ArRobot::madeConnection().

bool ArConfig::parseSection ArArgumentBuilder arg,
char *  errorBuffer = NULL,
size_t  errorBufferLen = 0
 

This parses the section change (for parser or other use).

The extra string of the parser should be set to the 'section' command while the rest of the arg should be the arguments to the section command. Its case insensitive.

Parameters:
errorBuffer if this is NULL it is ignored, otherwise the string for the error is put into the buffer, the first word should be the parameter that has trouble
errorBufferLen the length of the error buffer

Definition at line 286 of file ArConfig.cpp.

References ArConfigSection::getName(), and ArLog::log().

virtual bool ArConfig::processFile void   )  [inline, virtual]
 

for inheritors this is called after the file is processed

For classes that inherit from ArConfig this function is called after parseFile and all of the processFileCBs are called... If you want to call something before the processFileCBs then just add a processFileCB... this is only called if there were no errors parsing the file or continueOnError was set to false when parseFile was called

Returns:
true if the config parsed was good (parseFile will return true) false if the config parsed wasn't (parseFile will return false)

Definition at line 88 of file ArConfig.h.

Referenced by callProcessFileCallBacks().

void ArConfig::remProcessFileCB ArRetFunctor2< bool, char *, size_t > *  functor  ) 
 

Removes a processedFile callback.

Removes a processFileCB, see addProcessFileCB for details

Definition at line 996 of file ArConfig.cpp.

References remProcessFileCB().

void ArConfig::remProcessFileCB ArRetFunctor< bool > *  functor  ) 
 

Removes a processedFile callback.

Removes a processFileCB, see addProcessFileCB for details

Definition at line 944 of file ArConfig.cpp.

Referenced by remProcessFileCB().

void ArConfig::setSectionComment const char *  sectionName,
const char *  comment
 

Sets the comment for a section.

This sets the comment on a section, if the section doesn't exist it is created.

Definition at line 188 of file ArConfig.cpp.

References findSection(), ArLog::log(), and ArConfigSection::setComment().

Referenced by ArRobotParams::ArRobotParams().

void ArConfig::useArgumentParser ArArgumentParser parser  ) 
 

Uses this argument parser after it parses a file before it processes.

This argument parser the arguments in to check for parameters of this name, note that ONLY the first parameter of this name will be used, so if you have duplicates only the first one will be set.

Definition at line 1109 of file ArConfig.cpp.

bool ArConfig::writeFile const char *  fileName,
bool  append = false,
std::set< std::string > *  alreadyWritten = NULL,
bool  writePriorities = false
 

Write out a config file with defaults.

Parameters:
fileName the fileName to write out
append if true then it'll append, otherwise it'll overwrite
alreadyWritten a list of strings that have already been written out, don't write again if its in this list... when you write something put it into this list (if its not NULL)
writePriorities if this is true priorities will be written, if it is false they will not be

clear out our written ones between sections

Definition at line 627 of file ArConfig.cpp.

References ArArgumentBuilder::add(), ArArgumentBuilder::getArg(), ArArgumentBuilder::getArgc(), ArConfigArg::getArgsWithFunctor(), ArConfigArg::getBool(), ArConfigSection::getComment(), ArConfigArg::getConfigPriority(), ArConfigArg::getDescription(), ArConfigArg::getDouble(), ArConfigArg::getInt(), ArConfigArg::getMaxDouble(), ArConfigArg::getMaxInt(), ArConfigArg::getMinDouble(), ArConfigArg::getMinInt(), ArConfigArg::getName(), ArConfigSection::getName(), ArConfigSection::getParams(), ArConfigArg::getString(), ArConfigArg::getType(), and ArLog::log().

Referenced by ArRobotParams::save().


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