ParamMap Class Reference

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

#include <Component/ParamMap.H>

Collaboration diagram for ParamMap:
Collaboration graph
[legend]

List of all members.

Classes

struct  Impl
class  key_iterator

Public Types

enum  ReturnCode { MISSING, UNCHANGED, CHANGED }
 

Convenience function to create a new ParamMap from an equivalent.

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.
uint getsize () const
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.
void erase (const std::string &paramname)
 Remove a single param 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.

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 56 of file ParamMap.H.


Member Enumeration Documentation

Convenience function to create a new ParamMap from an equivalent.

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 78 of file ParamMap.H.


Constructor & Destructor Documentation

ParamMap::ParamMap (  ) 

Default construct with an empty map.

Definition at line 347 of file ParamMap.C.

ParamMap::ParamMap ( const std::string fname  ) 

Construct and load() from fname.

Definition at line 352 of file ParamMap.C.

References load().

ParamMap::~ParamMap (  ) 

Destructor.

Definition at line 359 of file ParamMap.C.


Member Function Documentation

void ParamMap::clear (  ) 

Remove all params from the ParamMap.

Definition at line 729 of file ParamMap.C.

void ParamMap::erase ( const std::string paramname  ) 

Remove a single param from the ParamMap.

Definition at line 735 of file ParamMap.C.

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 486 of file ParamMap.C.

References format().

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 470 of file ParamMap.C.

Referenced by format(), and SingleChannelBeo::handleInput().

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 577 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 546 of file ParamMap.C.

Referenced by 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 586 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 557 of file ParamMap.C.

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 568 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 535 of file ParamMap.C.

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 524 of file ParamMap.C.

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

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

Query whether the parameter map is a leaf or not.

Definition at line 508 of file ParamMap.C.

ParamMap::key_iterator ParamMap::keys_begin (  )  const

Get an iterator to the beginning of the keys sequence.

Definition at line 366 of file ParamMap.C.

ParamMap::key_iterator ParamMap::keys_end (  )  const

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

Definition at line 375 of file ParamMap.C.

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 455 of file ParamMap.C.

References load().

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

Load in a parameter map from the given input stream.

Definition at line 383 of file ParamMap.C.

References max().

Referenced by SingleChannelBeoServer::check(), load(), and ParamMap().

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.

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 595 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 742 of file ParamMap.C.

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

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

Definition at line 688 of file ParamMap.C.

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

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

Add an integral value with a given name.

Definition at line 694 of file ParamMap.C.

Referenced by GaborChannel::writeTo().

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

Add a string value with a given name.

Definition at line 682 of file ParamMap.C.

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 676 of file ParamMap.C.

Referenced by lookupSubpmap(), ChannelFacetMap::writeFacetsTo(), ModelComponent::writeParamsTo(), ComplexChannel::writeTo(), and IntegerComplexChannel::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 631 of file ParamMap.C.

References CHANGED, 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 654 of file ParamMap.C.

References CHANGED, 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 608 of file ParamMap.C.

References CHANGED, MISSING, and UNCHANGED.

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

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

Replace double-param.

Definition at line 715 of file ParamMap.C.

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

Replace int-param.

Definition at line 722 of file ParamMap.C.

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

Replace string-param.

Definition at line 708 of file ParamMap.C.

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

Replace a submap.

Definition at line 700 of file ParamMap.C.


The documentation for this class was generated from the following files:
Generated on Sun May 8 08:43:38 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3