ICAROUS
All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Modules Pages
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
larcfm::ParameterData Class Reference

#include <ParameterData.h>

Classes

class  comp_order
 

Public Member Functions

bool isPreserveUnits ()
 
void setPreserveUnits (bool v)
 
bool isUnitCompatibility ()
 
void setUnitCompatibility (bool v)
 
int size () const
 
std::vector< std::string > getKeyList () const
 
std::vector< std::string > getKeyListEntryOrder () const
 
std::vector< std::string > getKeyListWithFilter (Function< const std::string &, bool > &f) const
 
std::vector< std::string > getListFull () const
 
void clear ()
 
bool contains (const std::string &key) const
 
std::vector< std::string > matchList (const std::string &key) const
 
ParameterData copyWithPrefix (const std::string &prefix) const
 
ParameterData extractPrefix (const std::string &prefix) const
 
ParameterData removeKeysWithPrefix (const std::string &prefix) const
 
std::string getString (const std::string &key) const
 
double getValue (const std::string &key) const
 
double getValue (const std::string &key, const std::string &defaultUnit) const
 
std::string getUnit (const std::string &key) const
 
bool getBool (const std::string &key) const
 
int getInt (const std::string &key) const
 
long getLong (const std::string &key) const
 
bool set (const std::string &s)
 
bool set (const std::string &key, const std::string &value)
 
bool set (const std::string &key, char *value)
 
bool set (const std::string &key, const char *value)
 
bool setBool (const std::string &key, bool value)
 
bool setTrue (const std::string &key)
 
bool setFalse (const std::string &key)
 
bool setInt (const std::string &key, int value)
 
bool set (const std::string &key, double value, const std::string &unit)
 
bool setInternal (const std::string &key, double value, const std::string &units)
 
bool setInternal (const std::string &key, double value, const std::string &units, int prec)
 
bool updateUnit (const std::string &key, const std::string &unit)
 
bool updateComment (const std::string &key, const std::string &msg)
 
std::string getComment (const std::string &key) const
 
void setPreserveUnit (const std::string &key, double value, const std::string &units)
 
void setInternalPreserveUnit (const std::string &key, double value, const std::string &units)
 
std::vector< std::string > unrecognizedParameters (std::vector< std::string > c) const
 
std::vector< std::string > validateParameters (std::vector< std::string > c)
 
void listCopy (const ParameterData &p, const std::vector< std::string > &plist, bool overwrite)
 
void copy (const ParameterData &p, bool overwrite)
 
void remove (const std::string &key)
 
void removeAll (const std::vector< std::string > &key)
 
std::string toParameterList (const std::string &separator) const
 
bool parseParameterList (const std::string &separator, std::string line)
 
bool isBoolean (const std::string &key) const
 
bool isNumber (const std::string &key) const
 
bool isString (const std::string &key) const
 
std::string listToString (const std::vector< std::string > &keys) const
 
std::string listToString (const std::vector< std::string > &keys, const std::string &separator) const
 
std::string toString () const
 
std::string toString (const std::string &separator) const
 
bool equals (const ParameterData &pd) const
 
std::string diffString (const ParameterData &pd) const
 
ParameterData delta (const ParameterData &base) const
 
std::vector< int > getListInteger (const std::string &key) const
 
std::vector< double > getListDouble (const std::string &key) const
 
std::vector< std::string > getListString (const std::string &key) const
 
std::vector< bool > getListBool (const std::string &key) const
 
bool set (const std::string &key, const std::vector< int > &list)
 
bool set (const std::string &key, const std::vector< double > &list)
 
bool set (const std::string &key, const std::vector< std::string > &list)
 
bool setListBool (const std::string &key, const std::vector< bool > &list)
 

Static Public Member Functions

static ParameterData make ()
 

Static Public Attributes

static const std::string parenPattern = "[()]+"
 
static const std::string defaultEntrySeparator = "?"
 

Private Types

typedef std::map< std::string, ParameterEntry, stringCaseInsensitiveparamtype
 

Private Member Functions

int longestKey () const
 
int longestVal () const
 
bool parse_parameter_string (const std::string &str)
 
bool putParam (const std::string &key, const std::pair< bool, ParameterEntry > &entry)
 
bool putParam (const std::string &key, bool perform_conversion, ParameterEntry &entry)
 
std::pair< bool, ParameterEntryparse_parameter_value (const std::string &value)
 

Static Private Member Functions

static std::vector< std::string > stringList (const std::string &instring)
 
static std::vector< int > intList (const std::string &instring)
 
static std::vector< double > doubleList (const std::string &instring)
 
static std::vector< bool > boolList (const std::string &instring)
 

Private Attributes

bool preserveUnits
 
bool unitCompatibility
 
std::string listPatternStr
 
paramtype parameters
 

Detailed Description

This class stores a database of parameters. In addition, it performs various operations parameter strings, including parsing some more complicated parameter strings into various data structures.

All key accesses are case insensitive, however the actual key values are stored with case information intact. Methods returning the key values (getKeyList, getListFull) will reflect the capitalization scheme used for the initial assignment to a key.

Member Function Documentation

◆ clear()

void larcfm::ParameterData::clear ( )

Removes all stored parameters.

◆ contains()

bool larcfm::ParameterData::contains ( const std::string &  key) const

Returns true if the parameter key was defined.

Parameters
keyparameter key to check if it is in database
Returns
true, if parameter is in database

◆ copy()

void larcfm::ParameterData::copy ( const ParameterData p,
bool  overwrite 
)

Copy a ParameterData object into this object. That is, A.copy(B,true) means A <— B. If either units or comments are not defined in B, then the values in A are used.

Parameters
psource ParameterData
overwriteif true and a key exists in both this object and p, then use p's value, otherwise keep the original value

◆ copyWithPrefix()

ParameterData larcfm::ParameterData::copyWithPrefix ( const std::string &  prefix) const

Return a copy of this ParameterData object, with all key values being prepended with the string prefix. This is intended to create a unique ParameterData object representing the parameters of a particular instance (of many) of an object, that can then be collected along with others into a larger ParameterData object representing the containing object.

Parameters
prefixprefix to add to each key
Returns
copy of ParameterData with changes

◆ delta()

ParameterData larcfm::ParameterData::delta ( const ParameterData base) const

Compare this object with a base ParameterData object and return all parameters in this object that are different from parameters in the base object, either having different values or that are not present in the base. (Parameters that are only in the base are not included.) If the objects are the same, the result will be an empty ParameterData object.

Parameters
base"base" or "default" ParameterData to compare this object to
Returns
A ParameterData object containing all parameters that are in this object, but not in the base, or that are in both but have different values. This return may be empty.

◆ diffString()

std::string larcfm::ParameterData::diffString ( const ParameterData pd) const

Compare this ParameterData with another. Return a string listing all differences in stored values between the two.

Parameters
pdparameter database
Returns
string listing differences, or the empty string if the contents are the same.

◆ extractPrefix()

ParameterData larcfm::ParameterData::extractPrefix ( const std::string &  prefix) const

Return a copy of this ParameterData, with the string prefix removed from the beginning of all key values. If any key value in this object does not start with the given prefix, do not include it in the returned object. This is intended to filter out the parameters of a particular instance of a group of objects. The resulting ParameterData object will include an empty string parameter if a key exactly matches the prefix.

Parameters
prefixprefix of each key returned
Returns
copy of ParameterData with changes

◆ getBool()

bool larcfm::ParameterData::getBool ( const std::string &  key) const

Returns the Boolean value of the given parameter key. If the key is not present, or not representation of "true", return the empty string. Parameter keys may be case-sensitive.

Parameters
keyname of parameter
Returns
boolean representation of parameter

◆ getComment()

std::string larcfm::ParameterData::getComment ( const std::string &  key) const

Return a parameter's comment field.

Parameters
keyname of parameter
Returns
The comment string associated with the entry. If the entry does not exist, return the empty string.

◆ getInt()

int larcfm::ParameterData::getInt ( const std::string &  key) const

Returns the integer value of the given parameter key in internal units. If no units were specified in the file, then the defaultUnit parameter is used. If the key is not present or if the value is not a numeral, then return 0. This value is an integer version of the double value (see the related getParameterValue() method). If the double value is larger than an integer, behavior is undefined. Parameter keys may be case-sensitive.

Parameters
keyname of parameter
Returns
integer representation of parameter

◆ getKeyList()

std::vector< std::string > larcfm::ParameterData::getKeyList ( ) const

Returns an array of parameter strings encountered, alphabetically ordered

◆ getKeyListEntryOrder()

std::vector< std::string > larcfm::ParameterData::getKeyListEntryOrder ( ) const

Returns an array of parameter strings encountered, in the order entered

◆ getKeyListWithFilter()

std::vector< std::string > larcfm::ParameterData::getKeyListWithFilter ( Function< const std::string &, bool > &  f) const

Returns a list of parameter key strings encountered that satisfy the filter. Note that this will reflect the original capitalization of the keys when they were first stored.

Returns
list of parameter key names

◆ getListFull()

std::vector< std::string > larcfm::ParameterData::getListFull ( ) const

Returns an array of parameter definition strings encountered.

◆ getLong()

long larcfm::ParameterData::getLong ( const std::string &  key) const

Returns the long value of the given parameter key in internal units. If no units were specified in the file, then the defaultUnit parameter is used. If the key is not present or if the value is not a numeral, then return 0. This value is an integer version of the double value (see the related getParameterValue() method). If the double value is larger than an long, behavior is undefined.
Parameter keys may be case-sensitive.

Parameters
keyname of parameter
Returns
long representation of parameter

◆ getString()

std::string larcfm::ParameterData::getString ( const std::string &  key) const

Returns the string value of the given parameter key. This may be a space-delimited list. If the key is not present, return the empty string. Parameter keys may be case-sensitive.

Parameters
keyparameter name
Returns
string representation of parameter

◆ getUnit()

std::string larcfm::ParameterData::getUnit ( const std::string &  key) const

Returns the string representation of the specified unit of the given parameter key. If the key is not present or no unit was specified, return "unspecified". Parameter keys may be case-sensitive.

Parameters
keyname of parameter
Returns
units of parameter

◆ getValue() [1/2]

double larcfm::ParameterData::getValue ( const std::string &  key) const

Returns the double-precision value of the given parameter key in internal units. If the key is not present or if the value is not a numeral, then return 0. Parameter keys may be case-sensitive.

Parameters
keyparameter name
Returns
value of parameter (internal units)

◆ getValue() [2/2]

double larcfm::ParameterData::getValue ( const std::string &  key,
const std::string &  defaultUnit 
) const

Returns the double-precision value of the given parameter key in internal units. Only in the case when units were not specified in the database, will the defaultUnit parameter be used. If the key is not present or if the value is not a numeral, then return 0. Parameter keys may be case-sensitive.

Parameters
keyname of parameter
defaultUnitunits to use if no units are in database
Returns
value of parameter (internal units)

◆ isBoolean()

bool larcfm::ParameterData::isBoolean ( const std::string &  key) const

Returns true if the stored value for key is likely a boolean

Parameters
keyparameter name
Returns
true if key exists and the value is true/false/t/f, false otherwise

◆ isNumber()

bool larcfm::ParameterData::isNumber ( const std::string &  key) const

Returns true if the stored value for key is likely a number

Parameters
keyparameter name
Returns
true if key exists and the value is a parsable number

◆ isPreserveUnits()

bool larcfm::ParameterData::isPreserveUnits ( )

Will the units in the database will be updated if a subsequent set operation changes them.

Returns
true, if the units in the database will be preserved when a set method is called.

◆ isString()

bool larcfm::ParameterData::isString ( const std::string &  key) const

Returns true if the stored value for key is likely a string (or list). Note, the getString() method will always return a string (assuming a valid key is provided). This method returns a more narrow definition of a string, that is, something that is not a number or a boolean.

Parameters
keyparameter name
Returns
true if key exists and the value is not a parse-able number

◆ isUnitCompatibility()

bool larcfm::ParameterData::isUnitCompatibility ( )

Will set methods disallow updating a unit if the new unit is incompatible with the old unit. Meters and feet are compatible, whereas meters and kilograms are not. Most of the time, one wants the enforcement that compatible units are required, but there may be some situations where this is undesired.

Returns
true, if set methods must use compatible units with the units in the database

◆ listCopy()

void larcfm::ParameterData::listCopy ( const ParameterData p,
const std::vector< std::string > &  plist,
bool  overwrite 
)

Copy parameter entries from list of keys

Parameters
pdatabase
plistlist of keys
overwriteif a parameter key exists in both this object and p, if overwrite is true then p's value will be used, otherwise this object's value will be used

◆ listToString() [1/2]

std::string larcfm::ParameterData::listToString ( const std::vector< std::string > &  keys) const

Returns a string listing of specified parameters in (original) key/value pairs

Parameters
keyslist of parameter entries
Returns
multi-line string

◆ listToString() [2/2]

std::string larcfm::ParameterData::listToString ( const std::vector< std::string > &  keys,
const std::string &  separator 
) const

Returns a string listing all parameters in keys

Parameters
keyslist of parameter entries
separatorthe separator (e.g., a comma) to separate each key
Returns
string

◆ make()

ParameterData larcfm::ParameterData::make ( )
static

A database of parameters. The database is initially empty.

◆ parse_parameter_string()

bool larcfm::ParameterData::parse_parameter_string ( const std::string &  str)
private

Parse a string, if it is a valid parameter, then add it to the database and return true, else false.

Parameters
strthe string to parse
Returns
true if the database was updated, false otherwise. The database may not be updated because of an invalid parameter string was given, or incompatible units, etc.

◆ parse_parameter_value()

std::pair< bool, ParameterEntry > larcfm::ParameterData::parse_parameter_value ( const std::string &  value)
private

Doesn't do error checking, string should be "trimmed." this should always return a ParameterEntry

◆ parseParameterList()

bool larcfm::ParameterData::parseParameterList ( const std::string &  separator,
std::string  line 
)

Read in a set of parameters as created by toParameterList() with the same separator.

Parameters
separatorstring used to separate definitions. If blank or null, use defaultEntrySeparator instead.
lineString to be read.
Returns
true if string parsed successfully, false if an error occurred. If this returns false, one or more entries were not added to the database.

◆ putParam()

bool larcfm::ParameterData::putParam ( const std::string &  key,
const std::pair< bool, ParameterEntry > &  entry 
)
private

Put entry in parameter map

Parameters
key
entry
Returns
true, if parameter was added successfully

◆ remove()

void larcfm::ParameterData::remove ( const std::string &  key)

Remove the given key from this database. If the key does not exist, do nothing.

Parameters
keykey name

Remove the given key from this database. If the key does not exist, do nothing.

Parameters
key

◆ removeAll()

void larcfm::ParameterData::removeAll ( const std::vector< std::string > &  key)

Remove all keys in the list from this database, if they exist.

◆ removeKeysWithPrefix()

ParameterData larcfm::ParameterData::removeKeysWithPrefix ( const std::string &  prefix) const

Return a copy of this ParameterData, with all keys starting with the indicated prefix removed. Only include the key values that do not start with the given prefix (if any).

Parameters
prefixthe prefix to look for
Returns
copy of ParameterData without matching keys

◆ set() [1/4]

bool larcfm::ParameterData::set ( const std::string &  key,
const char *  value 
)

Associates a parameter key with a value (both represented as strings). Examples of string values include:

  • true
  • hello everyone!
  • 20
  • 10 [NM]

A note on this last example ('10 [NM]'). The value field may include a units descriptor in addition to the actual value. This is called the supplied units. If the supplied units are unspecified (e.g., '20'), then the units in the database for this parameter are used to interpret the value given.

Another note is that the string value stored is exactly what was supplied, except white space is trimmed off the beginning and end.

Parameters
keyname of parameter
valuestring representation of parameter
Returns
true, if the database was updated, false otherwise. The database may not be updated because of an invalid parameter string was given, or incompatible units, etc.

◆ set() [2/4]

bool larcfm::ParameterData::set ( const std::string &  key,
const std::string &  value 
)

Associates a parameter key with a value (both represented as strings). The value field may include a units descriptor in addition to the actual value, usually in a format similar to "10 [NM]", representing 10 nautical miles.

◆ set() [3/4]

bool larcfm::ParameterData::set ( const std::string &  key,
double  value,
const std::string &  unit 
)

Associates a value (in the given units) with a parameter key. If the supplied units are "unspecified," then the units in the database are used to interpret the value given. How the units in the database are updated depends on the value of the setPreserveUnits() parameter.

Parameters
keythe name of the parameter
valuethe value of the parameter in EXTERNAL units
unitsthe units of the given parameter
Returns
true, if the database was updated, false otherwise. The database may not be updated because of incompatible units, etc.

◆ set() [4/4]

bool larcfm::ParameterData::set ( const std::string &  s)

Parses the given string as a parameter assignment. If successful, returns a true value and adds the parameter. Otherwise returns a false value and makes no change to the parameter database. If the supplied units are unspecified, then the units in the database are used to interpret the value given.

Examples of valid strings include:

  • a = true
  • b = hello everyone!
  • c = 10 [NM]
Parameters
sthe given string to parse
Returns
true, if the database was updated, false otherwise. The database may not be updated because of an invalid parameter string was given, or incompatible units, etc.

◆ setBool()

bool larcfm::ParameterData::setBool ( const std::string &  key,
bool  value 
)

Associates a boolean value with a parameter key.

Parameters
keyname of parameter
valueboolean representation of parameter
Returns
true, if the database was updated, false otherwise. The database may not be updated because of incompatible units, etc.

◆ setFalse()

bool larcfm::ParameterData::setFalse ( const std::string &  key)

Associates false value with a parameter key.

Parameters
keyname of parameter
Returns
true, if the database was updated, false otherwise. The database may not be updated because of incompatible units, etc.

◆ setInt()

bool larcfm::ParameterData::setInt ( const std::string &  key,
int  value 
)

Associates an integer value with a parameter key. Integer values always have the unit of 'unitless'

Parameters
keyname of parameter
valueinteger representation of parameter
Returns
true, if the database was updated, false otherwise. The database may not be updated because of incompatible units, etc.

◆ setInternal() [1/2]

bool larcfm::ParameterData::setInternal ( const std::string &  key,
double  value,
const std::string &  units 
)

Associates a value (in internal units) with a parameter key. How the units in the database are updated, depends on the value of the setPreserveUnits() parameter.

Parameters
keythe name of the parameter
valuethe value of the parameter in INTERNAL units
unitsthe typical units of the value (but no conversion takes place, if "unspecified" any old value is preserved)
Returns
true, if the database was updated, false otherwise. The database may not be updated because of incompatible units, etc.

◆ setInternal() [2/2]

bool larcfm::ParameterData::setInternal ( const std::string &  key,
double  value,
const std::string &  units,
int  prec 
)

Associates a value (in internal units) with a parameter key. How the units in the database are updated, depends on the value of the setPreserveUnits() parameter.

Parameters
keythe name of the parameter
valuethe value of the parameter in INTERNAL units
unitsthe typical units of the value (but no conversion takes place, if "unspecified" any old value is preserved)
precnumber of digits of precision to represent this value as a string
Returns
true, if the database was updated, false otherwise. The database may not be updated because of incompatible units, etc.

◆ setInternalPreserveUnit()

void larcfm::ParameterData::setInternalPreserveUnit ( const std::string &  key,
double  value,
const std::string &  units 
)

Associates a value (in internal units) with a parameter key. If the parameter was already defined with a specified unit than the original unit is retained as the default unit for this parameter. If not, then the unit provided through this method becomes the default unit for this parameter.

Parameters
key
value
units

◆ setPreserveUnit()

void larcfm::ParameterData::setPreserveUnit ( const std::string &  key,
double  value,
const std::string &  units 
)

Associates a value (in the given units) with a parameter key. If the parameter was already defined with a specified unit than the original unit is retained as the default unit for this parameter. If not, then the unit provided through this method becomes the default unit for this parameter.

Parameters
key
value
units

◆ setPreserveUnits()

void larcfm::ParameterData::setPreserveUnits ( bool  v)

Controls whether all subsequent calls to "set.." methods will update the units in the database to the units supplied through a "set.." method. The "unspecified" unit is never preserved.

Parameters
vIf true, then the units in the database should be preserved

◆ setTrue()

bool larcfm::ParameterData::setTrue ( const std::string &  key)

Associates true value with a parameter key.

Parameters
keyname of parameter
Returns
true, if the database was updated, false otherwise. The database may not be updated because of incompatible units, etc.

◆ setUnitCompatibility()

void larcfm::ParameterData::setUnitCompatibility ( bool  v)

Controls whether set methods disallow updating a unit if the new unit is incompatible with the old unit. Meters and feet are compatible, whereas meters and kilograms are not. Most of the time, one wants the enforcement that compatible units are required, but there may be some situations where this is undesired.

Parameters
vtrue when the units in a set method must be compatible with the database.

◆ size()

int larcfm::ParameterData::size ( ) const

Number of parameters in this object

Returns
number of parameters

◆ toParameterList()

std::string larcfm::ParameterData::toParameterList ( const std::string &  separator) const

Return this ParameterData as a single line string that can subsequently be parsed by parseLine()

Parameters
separatorA unique (to the key and value set) character string to separate each entry. If this is null or the empty string, use the defaultEntrySeparator string instead.
Returns
Single-line string representation of this ParameterData object, possibly empty, or null if the separator is a substring of any key/value entry.

◆ toString() [1/2]

std::string larcfm::ParameterData::toString ( ) const

Returns a multi-line string listing all parameters and their (original string) values

◆ toString() [2/2]

std::string larcfm::ParameterData::toString ( const std::string &  separator) const

Returns a string listing all parameters

Parameters
separatorthe separator (e.g., a comma) to separate each key
Returns
A separated string of all parameters

Returns a string listing all parameters in keys

Parameters
keyslist of parameter entries @parame separator
Returns
string

◆ unrecognizedParameters()

std::vector< std::string > larcfm::ParameterData::unrecognizedParameters ( std::vector< std::string >  c) const

Checks the parameters against the supplied list, and returns a list of unrecognized parameters that have been read, possible empty

◆ updateComment()

bool larcfm::ParameterData::updateComment ( const std::string &  key,
const std::string &  msg 
)

Updates entry's comment

Parameters
keyname of parameter
msgthe new comment of the parameter
Returns
If the entry does not exist, this returns false, otherwise it returns true.

◆ updateUnit()

bool larcfm::ParameterData::updateUnit ( const std::string &  key,
const std::string &  unit 
)

Updates the unit for an existing entry. This ignores the setPreservedUnits() flag. You may create a blank entry in order to preemptively store a units value.

Parameters
keyname of parameter
unitunit for this parameter
Returns
If the unit was changed then return true, otherwise false. The unit may not be changed because it was duplicative, incompatible, not a unit, etc.

◆ validateParameters()

std::vector< std::string > larcfm::ParameterData::validateParameters ( std::vector< std::string >  c)

Checks the parameters against the supplied list, and returns a list of unrecognized parameters.


The documentation for this class was generated from the following files: