ICAROUS
|
#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, stringCaseInsensitive > | paramtype |
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, ParameterEntry > | parse_parameter_value (const std::string &value) |
Private Attributes | |
bool | preserveUnits |
bool | unitCompatibility |
std::string | listPatternStr |
paramtype | parameters |
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.
void larcfm::ParameterData::clear | ( | ) |
Removes all stored parameters.
bool larcfm::ParameterData::contains | ( | const std::string & | key | ) | const |
Returns true if the parameter key was defined.
key | parameter key to check if it is in database |
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.
p | source ParameterData |
overwrite | if true and a key exists in both this object and p, then use p's value, otherwise keep the original value |
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.
prefix | prefix to add to each key |
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.
base | "base" or "default" ParameterData to compare this object to |
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.
pd | parameter database |
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.
prefix | prefix of each key returned |
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.
key | name of parameter |
std::string larcfm::ParameterData::getComment | ( | const std::string & | key | ) | const |
Return a parameter's comment field.
key | name of parameter |
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.
key | name of parameter |
std::vector< std::string > larcfm::ParameterData::getKeyList | ( | ) | const |
Returns an array of parameter strings encountered, alphabetically ordered
std::vector< std::string > larcfm::ParameterData::getKeyListEntryOrder | ( | ) | const |
Returns an array of parameter strings encountered, in the order entered
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.
std::vector< std::string > larcfm::ParameterData::getListFull | ( | ) | const |
Returns an array of parameter definition strings encountered.
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.
key | name of parameter |
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.
key | parameter name |
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.
key | name of parameter |
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.
key | parameter name |
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.
key | name of parameter |
defaultUnit | units to use if no units are in database |
bool larcfm::ParameterData::isBoolean | ( | const std::string & | key | ) | const |
Returns true if the stored value for key is likely a boolean
key | parameter name |
bool larcfm::ParameterData::isNumber | ( | const std::string & | key | ) | const |
Returns true if the stored value for key is likely a number
key | parameter name |
bool larcfm::ParameterData::isPreserveUnits | ( | ) |
Will the units in the database will be updated if a subsequent set operation changes them.
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.
key | parameter name |
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.
void larcfm::ParameterData::listCopy | ( | const ParameterData & | p, |
const std::vector< std::string > & | plist, | ||
bool | overwrite | ||
) |
Copy parameter entries from list of keys
p | database |
plist | list of keys |
overwrite | if 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 |
std::string larcfm::ParameterData::listToString | ( | const std::vector< std::string > & | keys | ) | const |
Returns a string listing of specified parameters in (original) key/value pairs
keys | list of parameter entries |
std::string larcfm::ParameterData::listToString | ( | const std::vector< std::string > & | keys, |
const std::string & | separator | ||
) | const |
Returns a string listing all parameters in keys
keys | list of parameter entries |
separator | the separator (e.g., a comma) to separate each key |
|
static |
A database of parameters. The database is initially empty.
|
private |
Parse a string, if it is a valid parameter, then add it to the database and return true, else false.
str | the string to parse |
|
private |
Doesn't do error checking, string should be "trimmed." this should always return a ParameterEntry
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.
separator | string used to separate definitions. If blank or null, use defaultEntrySeparator instead. |
line | String to be read. |
|
private |
Put entry in parameter map
key | |
entry |
void larcfm::ParameterData::remove | ( | const std::string & | key | ) |
Remove the given key from this database. If the key does not exist, do nothing.
key | key name |
Remove the given key from this database. If the key does not exist, do nothing.
key |
void larcfm::ParameterData::removeAll | ( | const std::vector< std::string > & | key | ) |
Remove all keys in the list from this database, if they exist.
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).
prefix | the prefix to look for |
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:
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.
key | name of parameter |
value | string representation of parameter |
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.
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.
key | the name of the parameter |
value | the value of the parameter in EXTERNAL units |
units | the units of the given parameter |
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:
s | the given string to parse |
bool larcfm::ParameterData::setBool | ( | const std::string & | key, |
bool | value | ||
) |
Associates a boolean value with a parameter key.
key | name of parameter |
value | boolean representation of parameter |
bool larcfm::ParameterData::setFalse | ( | const std::string & | key | ) |
Associates false value with a parameter key.
key | name of parameter |
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'
key | name of parameter |
value | integer representation of parameter |
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.
key | the name of the parameter |
value | the value of the parameter in INTERNAL units |
units | the typical units of the value (but no conversion takes place, if "unspecified" any old value is preserved) |
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.
key | the name of the parameter |
value | the value of the parameter in INTERNAL units |
units | the typical units of the value (but no conversion takes place, if "unspecified" any old value is preserved) |
prec | number of digits of precision to represent this value as a string |
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.
key | |
value | |
units |
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.
key | |
value | |
units |
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.
v | If true, then the units in the database should be preserved |
bool larcfm::ParameterData::setTrue | ( | const std::string & | key | ) |
Associates true value with a parameter key.
key | name of parameter |
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.
v | true when the units in a set method must be compatible with the database. |
int larcfm::ParameterData::size | ( | ) | const |
Number of parameters in this object
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()
separator | A 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. |
std::string larcfm::ParameterData::toString | ( | ) | const |
Returns a multi-line string listing all parameters and their (original string) values
std::string larcfm::ParameterData::toString | ( | const std::string & | separator | ) | const |
Returns a string listing all parameters
separator | the separator (e.g., a comma) to separate each key |
Returns a string listing all parameters in keys
keys | list of parameter entries @parame separator |
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
bool larcfm::ParameterData::updateComment | ( | const std::string & | key, |
const std::string & | msg | ||
) |
Updates entry's comment
key | name of parameter |
msg | the new comment of the parameter |
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.
key | name of parameter |
unit | unit for this parameter |
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.