Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ParamMap Class Reference

#include <Component/ParamMap.H>

Collaboration diagram for ParamMap:

Collaboration graph
[legend]
List of all members.

Detailed Description

Allows reading and writing of parameters to and from files or streams.

ParamMap allows reading and writing of arbitrarily nested data structes to and from files or other streams.

Definition at line 49 of file ParamMap.H.

Public Types

enum  ReturnCode { MISSING, UNCHANGED, CHANGED }
 Return codes when getting params from the map. More...

Public Member Functions

 ParamMap ()
 Default construct with an empty map.
 ParamMap (const std::string &fname)
 Construct and load() from fname.
 ~ParamMap ()
 Destructor.
key_iterator keys_begin () const
 Get an iterator to the beginning of the keys sequence.
key_iterator keys_end () const
 Get an iterator to one-past-the-end of the keys sequence.
void load (std::istream &istrm)
 Load in a parameter map from the given input stream.
void load (const std::string &fname)
 Convenience overload of the other load().
void format (std::ostream &ostrm, int indentlev=0) const
 Write a formatted parameter map to the given output stream.
void format (const std::string &fname) const
 Convenience overload of the other format().
bool hasParam (const std::string &paramname) const
 Query whether the parameter map has a particular named parameter.
bool isLeaf (const std::string &paramname) const
 Query whether the parameter map is a leaf or not.
void print (const std::string &name) const
 For testing/debugging only.
Functions to extract named values from the ParamMap
There are several kinds of functions that differ in how they handle named parameters that are not found in the ParamMap. The first kind look for a named parameter, and trigger and error if that parameter is not found. The second kind take a default value as an additional argument, and return that value if the named parameter is not found. The third kind take a destination by reference, and leave that destination unchanged if the parameter is not found, and additional return a ReturnCode specifying with the parameter was missing, found-and-changed, or found-and-unchanged.

rutz::shared_ptr< ParamMapgetSubpmap (const std::string &paramname) const
 Get a named parameter as a nested parameter map.
std::string getStringParam (const std::string &paramname) const
 Get a named parameter as a string value.
double getDoubleParam (const std::string &paramname) const
 Get a named parameter as a 'double' value.
int getIntParam (const std::string &paramname) const
 Get a named parameter as an 'int' value.
std::string getStringParam (const std::string &paramname, const std::string &defval) const
 Get a named parameter as a string value, or return the default value.
double getDoubleParam (const std::string &paramname, const double defval) const
 Get a named parameter as a 'double' value, or return the default value.
int getIntParam (const std::string &paramname, const int defval) const
 Get a named parameter as an 'int' value, or return the default value.
rutz::shared_ptr< ParamMaplookupSubpmap (const std::string &paramname)
 Returns the submap for the given name.
ReturnCode queryStringParam (const std::string &paramname, std::string &result) const
 Get the named parameter, or do nothing if the parameter is missing.
ReturnCode queryDoubleParam (const std::string &paramname, double &result) const
 Get the named parameter, or do nothing if the parameter is missing.
ReturnCode queryIntParam (const std::string &paramname, int &result) const
 Get the named parameter, or do nothing if the parameter is missing.
Functions to place named values into the ParamMap
void putSubpmap (const std::string &paramname, const rutz::shared_ptr< ParamMap > &val)
 Add a nested parameter map with a given name.
void putStringParam (const std::string &paramname, const std::string &val)
 Add a string value with a given name.
void putDoubleParam (const std::string &paramname, double val)
 Add a double-precision floating point value with a given name.
void putIntParam (const std::string &paramname, int val)
 Add an integral value with a given name.
void replaceSubpmap (const std::string &paramname, const rutz::shared_ptr< ParamMap > &val)
 Replace a submap.
void replaceStringParam (const std::string &paramname, const std::string &val)
 Replace string-param.
void replaceDoubleParam (const std::string &paramname, double val)
 Replace double-param.
void replaceIntParam (const std::string &paramname, int val)
 Replace int-param.
void clear ()
 Remove all params from the ParamMap.

Static Public Member Functions

static rutz::shared_ptr< ParamMaploadPmapFile (const std::string &fname)
 Convenience function to create a new ParamMap from a .pmap file.
static rutz::shared_ptr< ParamMaploadConfFile (const std::string &fname)
 Compatibility function to create a new ParamMap from a .conf file.

Classes

class  key_iterator
struct  Impl


Member Enumeration Documentation

enum ParamMap::ReturnCode
 

Return codes when getting params from the map.

Enumerator:
MISSING  the param was not found
UNCHANGED  the param was found, but the value was unchanged
CHANGED  the param was found and its value was changed

Definition at line 66 of file ParamMap.H.


Constructor & Destructor Documentation

ParamMap::ParamMap  ) 
 

Default construct with an empty map.

Definition at line 321 of file ParamMap.C.

ParamMap::ParamMap const std::string fname  ) 
 

Construct and load() from fname.

Definition at line 326 of file ParamMap.C.

References load().

ParamMap::~ParamMap  ) 
 

Destructor.

Definition at line 333 of file ParamMap.C.


Member Function Documentation

void ParamMap::clear  ) 
 

Remove all params from the ParamMap.

Definition at line 697 of file ParamMap.C.

References ParamMap::Impl::itsParams.

Referenced by ModelManagerDialog::handleItemEdit(), and ModelManagerDialog::init().

void ParamMap::format const std::string fname  )  const
 

Convenience overload of the other format().

In this case we just build an ostream internally from the given filename, and then format() from that.

Definition at line 460 of file ParamMap.C.

References format(), and LFATAL.

void ParamMap::format std::ostream &  ostrm,
int  indentlev = 0
const
 

Write a formatted parameter map to the given output stream.

The indentlev parameter is only used internally by ParamMap, and can be safely ignored by external callers.

Definition at line 444 of file ParamMap.C.

References dummy_namespace_to_avoid_gcc411_bug_ParamMap_C::escapeWrite(), i, ParamMap::Impl::itsParams, and lobot::stop().

Referenced by Channels_xx_facets_xx_1(), format(), SingleChannelBeo::handleInput(), and ModelManager::saveConfig().

double ParamMap::getDoubleParam const std::string paramname,
const double  defval
const
 

Get a named parameter as a 'double' value, or return the default value.

The default value will be returned if the named parameter is not found.

Definition at line 545 of file ParamMap.C.

References queryDoubleParam().

double ParamMap::getDoubleParam const std::string paramname  )  const
 

Get a named parameter as a 'double' value.

Triggers an error if there is no parameter with the given name.

Definition at line 514 of file ParamMap.C.

References ParamMap::Impl::itsParams, and LFATAL.

Referenced by modelparam_xx_writeto_xx_1(), ChannelFacetScalarComplex::readFrom(), and ChannelFacetScalarSingle::readFrom().

int ParamMap::getIntParam const std::string paramname,
const int  defval
const
 

Get a named parameter as an 'int' value, or return the default value.

The default value will be returned if the named parameter is not found.

Definition at line 554 of file ParamMap.C.

References queryIntParam().

int ParamMap::getIntParam const std::string paramname  )  const
 

Get a named parameter as an 'int' value.

Triggers an error if there is no parameter with the given name.

Definition at line 525 of file ParamMap.C.

References ParamMap::Impl::itsParams, and LFATAL.

std::string ParamMap::getStringParam const std::string paramname,
const std::string defval
const
 

Get a named parameter as a string value, or return the default value.

The default value will be returned if the named parameter is not found.

Definition at line 536 of file ParamMap.C.

References queryStringParam().

std::string ParamMap::getStringParam const std::string paramname  )  const
 

Get a named parameter as a string value.

Triggers an error if there is no parameter with the given name.

Definition at line 503 of file ParamMap.C.

References ParamMap::Impl::itsParams, and LFATAL.

Referenced by ChannelBase::readFrom().

rutz::shared_ptr< ParamMap > ParamMap::getSubpmap const std::string paramname  )  const
 

Get a named parameter as a nested parameter map.

Triggers an error if there is no parameter with the given name.

Definition at line 492 of file ParamMap.C.

References ParamMap::Impl::itsParams, and LFATAL.

Referenced by ModelManagerDialog::handleItemEdit(), ModelManagerDialog::init(), lookupSubpmap(), ChannelFacetMap::readFacetsFrom(), IntegerComplexChannel::readFrom(), ComplexChannel::readFrom(), and ModelComponent::readParamsFrom().

bool ParamMap::hasParam const std::string paramname  )  const
 

Query whether the parameter map has a particular named parameter.

Definition at line 475 of file ParamMap.C.

References ParamMap::Impl::itsParams.

Referenced by lookupSubpmap(), ChannelFacetMap::readFacetsFrom(), IntegerComplexChannel::readFrom(), ComplexChannel::readFrom(), ChannelFacetScalarComplex::readFrom(), ChannelFacetScalarSingle::readFrom(), ChannelBase::readFrom(), and ModelComponent::readParamsFrom().

bool ParamMap::isLeaf const std::string paramname  )  const
 

Query whether the parameter map is a leaf or not.

Definition at line 482 of file ParamMap.C.

References ParamMap::Impl::itsParams.

ParamMap::key_iterator ParamMap::keys_begin  )  const
 

Get an iterator to the beginning of the keys sequence.

Definition at line 340 of file ParamMap.C.

References ParamMap::Impl::itsParams, and ParamMap::key_iterator::rep.

ParamMap::key_iterator ParamMap::keys_end  )  const
 

Get an iterator to one-past-the-end of the keys sequence.

Definition at line 349 of file ParamMap.C.

References ParamMap::Impl::itsParams, and ParamMap::key_iterator::rep.

void ParamMap::load const std::string fname  ) 
 

Convenience overload of the other load().

In this case we just build an istream internally from the given filename, and then load() from that.

Definition at line 429 of file ParamMap.C.

References LFATAL, and load().

void ParamMap::load std::istream &  istrm  ) 
 

Load in a parameter map from the given input stream.

Definition at line 357 of file ParamMap.C.

References c, dummy_namespace_to_avoid_gcc411_bug_ParamMap_C::escapeRead(), ParamMap::Impl::itsParams, LFATAL, and rutz::max().

Referenced by Channels_xx_facets_xx_1(), SingleChannelBeoServer::check(), load(), ModelManager::loadConfig(), ParamMap(), and ModelManager::parseCommandLine().

rutz::shared_ptr< ParamMap > ParamMap::loadConfFile const std::string fname  )  [static]
 

Compatibility function to create a new ParamMap from a .conf file.

See readConfig for details on the format of a .conf file. Basically, it is similar to the .pmap format, except that comments must be bracketed by whitespace-separated '#' characters on both sides, and that there is no nesting of data structures.

Definition at line 282 of file ParamMap.C.

References counter, and LINFO.

rutz::shared_ptr< ParamMap > ParamMap::loadPmapFile const std::string fname  )  [static]
 

Convenience function to create a new ParamMap from a .pmap file.

Definition at line 274 of file ParamMap.C.

Referenced by main().

rutz::shared_ptr< ParamMap > ParamMap::lookupSubpmap const std::string paramname  ) 
 

Returns the submap for the given name.

If a submap for the given name exists, a rutz::shared_ptr to it is returned. If no submap for the given name has yet been created, one is created, and a rutz::shared_ptr to it is returned. This function differs from getSubpmap(), which only returns existing submaps.

Definition at line 563 of file ParamMap.C.

References getSubpmap(), hasParam(), and putSubpmap().

void ParamMap::print const std::string name  )  const
 

For testing/debugging only.

Prints the raw contents of this parameter map to standard output.

Definition at line 703 of file ParamMap.C.

References ParamMap::Impl::itsParams, and lobot::stop().

void ParamMap::putDoubleParam const std::string paramname,
double  val
 

Add a double-precision floating point value with a given name.

Definition at line 656 of file ParamMap.C.

References ParamMap::Impl::itsParams.

Referenced by GaborChannel::writeTo(), ChannelFacetScalarComplex::writeTo(), and ChannelFacetScalarSingle::writeTo().

void ParamMap::putIntParam const std::string paramname,
int  val
 

Add an integral value with a given name.

Definition at line 662 of file ParamMap.C.

References ParamMap::Impl::itsParams.

Referenced by modelparam_xx_readfrom_xx_1(), and GaborChannel::writeTo().

void ParamMap::putStringParam const std::string paramname,
const std::string val
 

Add a string value with a given name.

Definition at line 650 of file ParamMap.C.

References ParamMap::Impl::itsParams.

Referenced by ModelParamAuxImpl::writeTo(), and ChannelBase::writeTo().

void ParamMap::putSubpmap const std::string paramname,
const rutz::shared_ptr< ParamMap > &  val
 

Add a nested parameter map with a given name.

Definition at line 644 of file ParamMap.C.

References ParamMap::Impl::itsParams.

Referenced by lookupSubpmap(), ChannelFacetMap::writeFacetsTo(), ModelComponent::writeParamsTo(), IntegerComplexChannel::writeTo(), and ComplexChannel::writeTo().

ParamMap::ReturnCode ParamMap::queryDoubleParam const std::string paramname,
double &  result
const
 

Get the named parameter, or do nothing if the parameter is missing.

The ReturnCode describes what happened when looking up the param.

Definition at line 599 of file ParamMap.C.

References CHANGED, ParamMap::Impl::itsParams, LINFO, MISSING, and UNCHANGED.

Referenced by getDoubleParam(), and GaborChannel::readFrom().

ParamMap::ReturnCode ParamMap::queryIntParam const std::string paramname,
int &  result
const
 

Get the named parameter, or do nothing if the parameter is missing.

The ReturnCode describes what happened when looking up the param.

Definition at line 622 of file ParamMap.C.

References CHANGED, ParamMap::Impl::itsParams, LINFO, MISSING, and UNCHANGED.

Referenced by getIntParam(), and GaborChannel::readFrom().

ParamMap::ReturnCode ParamMap::queryStringParam const std::string paramname,
std::string result
const
 

Get the named parameter, or do nothing if the parameter is missing.

The ReturnCode describes what happened when looking up the param.

Definition at line 576 of file ParamMap.C.

References CHANGED, ParamMap::Impl::itsParams, LINFO, MISSING, and UNCHANGED.

Referenced by getStringParam(), and ModelParamAuxImpl::readFrom().

void ParamMap::replaceDoubleParam const std::string paramname,
double  val
 

Replace double-param.

Definition at line 683 of file ParamMap.C.

References ParamMap::Impl::itsParams.

void ParamMap::replaceIntParam const std::string paramname,
int  val
 

Replace int-param.

Definition at line 690 of file ParamMap.C.

References ParamMap::Impl::itsParams.

void ParamMap::replaceStringParam const std::string paramname,
const std::string val
 

Replace string-param.

Definition at line 676 of file ParamMap.C.

References ParamMap::Impl::itsParams.

void ParamMap::replaceSubpmap const std::string paramname,
const rutz::shared_ptr< ParamMap > &  val
 

Replace a submap.

Definition at line 668 of file ParamMap.C.

References ParamMap::Impl::itsParams.


The documentation for this class was generated from the following files:
Generated on Sat Nov 7 13:35:44 2009 for iLab Neuromorphic Vision Toolkit by  doxygen 1.4.4