FRIBParallelanalysis
1.0
FrameworkforMPIParalleldataanalysisatFRIB
|
#include <CItemConfiguration.h>
Classes | |
struct | _isListParameter |
struct | _ListSizeConstraint |
struct | flimit |
struct | limit |
Public Types | |
typedef std::pair< typeChecker, void * > | TypeCheckInfo |
typedef std::vector< std::pair< std::string, std::string > > | ConfigurationArray |
typedef std::pair< limit, limit > | Limits |
typedef std::set< std::string > | isEnumParameter |
typedef struct CItemConfiguration::_ListSizeConstraint | ListSizeConstraint |
typedef struct CItemConfiguration::_isListParameter | isListParameter |
typedef std::pair< flimit, flimit > | FloatingLimits |
Public Member Functions | |
CItemConfiguration (std::string name) | |
CItemConfiguration (const CItemConfiguration &rhs) | |
virtual | ~CItemConfiguration () |
CItemConfiguration & | operator= (const CItemConfiguration &rhs) |
int | operator== (const CItemConfiguration &rhs) const |
int | operator!= (const CItemConfiguration &rhs) const |
std::string | getName () const |
std::string | cget (std::string name) |
ConfigurationArray | cget () |
int | getIntegerParameter (std::string name) |
unsigned int | getUnsignedParameter (std::string name) |
bool | getBoolParameter (std::string name) |
double | getFloatParameter (std::string name) |
std::vector< int > | getIntegerList (std::string name) |
void | addParameter (std::string name, typeChecker checker, void *arg, std::string defaultValue=std::string("")) |
void | clearConfiguration () |
bool | isValid (std::string name, std::string value) |
void | configure (std::string name, std::string value) |
Static Public Member Functions | |
static bool | isInteger (std::string name, std::string value, void *arg) |
static bool | isBool (std::string name, std::string value, void *arg) |
static bool | isEnum (std::string name, std::string value, void *arg) |
static bool | isFloat (std::string name, std::string value, void *arg) |
static bool | isList (std::string name, std::string value, void *arg) |
static bool | isBoolList (std::string name, std::string value, void *arg) |
static bool | isIntList (std::string name, std::string value, void *arg) |
static bool | isStringList (std::string name, std::string value, void *arg) |
An Item configuration is a set of name value pairs. Each name value pair can have an associated validity checker who is responsible for ensuring that for any configuration value a candidate new value is legal. Type checkers are just unbound functions, or static member functions. See the typedef for typeChecker above.
For convenience, some of the static functions of this class provide commonly used type checkers.
How to use this:
In general, one would create an object that contains a CItemConfiguration object. That object would provide mechanisms to set/get the configuration. The object itself, would register the configuration names it needs. It would, in appropriate methods, get the values of the configuration names.
See e.g. CConfigurableObject for a base class that can be used and that has those properties.
The configuration subsystem would at some point call configure to set up the configuration (note subclassed objects can also call this to set up their default configuration).
The data taking system would then call subclass functions to inform it that configuration is complete. The subclass then would call cget to get and react to its configuration.
This class does not implement any policy about how the configuration is gotten. This can be done by manual parsing of data files, by internal data structures, by a Tcl interpreter reading scripts or any other practical means.
CItemConfiguration::CItemConfiguration | ( | const CItemConfiguration & | rhs | ) |
Copy construction. We can just copy the name and map. Copy construction should be rare as normally names are unique.
|
virtual |
Destruction probably will result in some memory leaks since it is possible that the typeChecker's will have parameters that are dynamically allocated. In a future life we can provide cleanup functions.. for now we just assume that destruction will be infrequent, and leaks will be small enough to be tolerated.
I think that destruction is not necessary since all the pairs will copyconstruct/assign into the map. This is a place holder for later code that can handle deletion of the typechecker args.
void CItemConfiguration::addParameter | ( | std::string | name, |
typeChecker | checker, | ||
void * | arg, | ||
std::string | defaultValue = std::string("") |
||
) |
Adds a configuration parameter to the configuration. If there is already a configuration parameter by this name, it is silently ovewritten.
name | : std::string Name of the parameter to add. |
checker | : typeChecker A type checker to validate the values proposed for the parameter, if NULL, no validation is performed. |
arg | : void Parameter passed without interpretation to the typechecker at validation time. |
defaultValue | : string (default = "") Initial value for the parameter. |
CItemConfiguration::ConfigurationArray CItemConfiguration::cget | ( | ) |
Get the values of all the configuration parameters.
A | vector of parameter name/value pairs. Given an element, ele of the vector, ele.first is the parameter name, ele.second the value. |
void CItemConfiguration::clearConfiguration | ( | ) |
clear the current configuration. The configuration map m_parameters map is emptied.
void CItemConfiguration::configure | ( | std::string | name, |
std::string | value | ||
) |
Configure the value of a parameter.
name | : std::string Name of the parameter to configure. |
value | : std::string New value of the parameter |
std::string("No | such parameter") if the parameter 'name' is not defined. \throw std::string("Validation failed for 'name' <- 'value'") if the value does not pass the validator for the parameter. |
bool CItemConfiguration::getBoolParameter | ( | std::string | name | ) |
Return the value of a bool parameter. This uses the same set of true values as the checker.. however any other value is assumed to be false.
name | : std::string Name of the value. |
the | boolean equivalent of the config param |
double CItemConfiguration::getFloatParameter | ( | std::string | name | ) |
Return a parameter decoded as a double.
name | : std::string Name of the parameter |
vector< int > CItemConfiguration::getIntegerList | ( | std::string | name | ) |
Return a parameter that is a list of integers.
name | - name of the parameter. |
Vector | containing the integers in the list. |
int CItemConfiguration::getIntegerParameter | ( | std::string | name | ) |
Return the value of an integer parameter.
name | : std::string Name of the value. |
the | integer equivalent of the config paramter. |
string CItemConfiguration::getName | ( | ) | const |
The | name of the object. |
unsigned int CItemConfiguration::getUnsignedParameter | ( | std::string | name | ) |
Same as above but for an integer. Needed because strtol for something bigger than MAXINT returns MAXINT.
|
static |
Validate a bool parameter. Bool parameters have any of the values:
name | : std::string Name of the parameter |
value | : std:: string proposed new value. |
ignored | : void* Ignored value parameter. |
true | If valid. |
false | If invalid. |
|
static |
Check that a list is a valid bool list. This is done by constructing the listValidity object with a list element checker set to the bool element checker.
name | : std::string Name of the parameter. |
value | : std:: string Proposed new value. |
sizes | : void* Actually a pointer to ListSizeConstraint if non null:
|
true | List validates. |
false | List is not valid. |
|
static |
Validate an enum parameter. An enumerated parameter is one that can be a string drawn from a limited set of keywords. Validation fails of the string is not one of the valid keywords.
name | : std::string Name of the parameter. |
value | : std::string Proposed parameter value. |
values | : void* Actually an std::set<string>* where the set elements are the valid keywords. |
true | If valid. |
false | If invalid. |
|
static |
Validate a floating point parameter. Floating parameters allow the implementor of a device to let the user specify values in 'real units' which are then converted transparently to device register values. Floating point values are actually handled as doubles, since C/C++ likes to upconvert floats to doubles in any event. The conversion fails if the string does not convert to a floating point value or the etire string is not used in the conversion. NAN's are also considered invali, and isnan is used to determine if the conversion resulted in an NAN.
The application can place limits on the floating point value as well. See the parameters below:
name | : std::string Parameter name (ignored). |
value | : std::string The value of the paramter. |
values | : void* Actually a ppointer to a FloatingLimits type which sets the limits on the parameter. If the FloatingLimits type is NULL, all floating values are allowed...except for NAN's... which are never allowed. |
true | - if Valid. |
false | - if not Valid. |
|
static |
Validate an integer parameter with optional limits.
name | : std::string Name of the parameter being checked (ignored). |
value | : std::string Proposed new value. |
arg | : void* This is actually a pointer to an Limits structure or NULL.
|
true | - Validation passed. |
false | - Validation failed. |
|
static |
Check that this is a valid list of integers. For string lists in this implementation we are not able to do range checking on the values of the list elements. We do, however enforce the integer-ness of each element of the list.
name | : std::string Name of the parameter. |
value | : std::string Proposed value of the parameter. |
sizes | : void* Actually a pointer to a ListSizeConstraint which, if non null places constraints on the number of elements in the list. |
true | - List validated. |
false | - List not validated |
|
static |
Validate a list parameter. To simplify; a list parameter is a Tcl formatted list. List validation can fail for the following reasons:
name | : std::string Name of the parameter being modified. |
value | : std::string Value proposed for the parameter. |
validity | : void* Actually an optional pointer to an isListParameter:
|
true | List is valid. |
fals | List is invalid. |
|
static |
Check for a string list. String lists are allowed to have just about anything as element values...therefore, if the validSizes parameter is present, we'll do list size checking only, otherwise on list syntax checking.
name | : std::string Name of the parameter being modified. |
value | ; std::string proposed new value for the parameter. |
validSizes | : void* Actually a pointer to a ListSizeConstraint structure that, if non-null defines the list size checking that will take place. If NULL, any sized list (including empty) is allowed. |
true | - List validated. |
false | - List not validated |
bool CItemConfiguration::isValid | ( | std::string | name, |
std::string | value | ||
) |
Returns true if a proposed configuration is valid. This will still throw if the name is not defined... but will
true | - The proposed configuration is acceptable. |
false | - The proposed configuration is not acceptable. |
name | - of the parameter to validate. |
value | - Proposed new value. |
int CItemConfiguration::operator!= | ( | const CItemConfiguration & | rhs | ) | const |
Inequality is the logical inverse of equality:
CItemConfiguration & CItemConfiguration::operator= | ( | const CItemConfiguration & | rhs | ) |
Assignement is similar to copy construction:
int CItemConfiguration::operator== | ( | const CItemConfiguration & | rhs | ) | const |
Equality is via item comparison.