SConfigurableObject

Name

SConfigurableObject -- Scripted Readout Configuration database

Synopsis


            
#include <CConfigurableObject.h>  // Note different name.
            
            SConfigurableObject : public CTCLProcessor
           
  SConfigurableObject (const  std::string& rName, CTCLInterpreter& rInterp)
          throws ;
           
           
  const std::string  getName()
          throws ;
              virtual    int       operator() (CTCLInterpreter&  rInterp, CTCLResult&  rResult, int  nArgs, char** pArgs)
          throws ;
              virtual    int       Configure (CTCLInterpreter&  rInterp, CTCLResult& rResult, int nArgs, char** pArgs)
          throws ;
  
              virtual    int       ListConfiguration (CTCLInterpreter& rInterp, CTCLResult& rResult, int nArgs, char** pArgs)
          throws ;
  
                SConfigurableObject::ParameterIterator  AddParameter(CConfigurationParameter* pConfigParam)
          throws ;
                SConfigurableObject::ParameterIterator   AddIntParam (const  std::string&  sParamName, int  nDefault = =0)
          throws ;
                 SConfigurableObject::ParameterIterator  AddBoolParam (const  std::string& rName, bool  fDefault)
          throws ;
  
                SConfigurableObject::ParameterIterator  AddStringParam (const  std::string& rName)
          throws ;
  
                SConfigurableObject::ParameterIterator  AddIntArrayParam (const  std::string& rParameterName, int  nArraySize, int  nDefault = =0)
          throws ;
                SConfigurableObject::ParameterIterator  AddStringArrayParam (const std::string& rName, int nArraySize)
          throws ;
                SConfigurableObject::ParameterIterator AddEnumParam( std::string name, std::vector<std::pair<std::string, int> > values, std::string  defaultValue)
          throws ;
  
                SConfigurableObject::ParameterIterator  Find (const std::string&  rKeyword)
          throws ;
                SConfigurableObject::ParameterIterator  begin()
          throws ;
                SConfigurableObject::ParameterIterator  end()
          throws ;
                int  size()
          throws ;
                std::string  ListParameters (const std::string& rPattern)
          throws ;
                std::string   ListKeywords();
  
                int  getIntegerValue(std::string name)
          throws ;
  
                bool  getBoolValue(std::string  name)
          throws ;
                CIntArrayParam*  getIntArray(std::string  name)
          throws ;
                int getEnumValue(std::string name)
          throws ;
  
        

DESCRIPTION

This class is an eventual base class for the CDigitizerModule and is responsible for managing the command dispatching and configuration management for classes derived from that class.

Configuration parameters are held in a searchable container. The class can produce SConfigurableParameter::ParameterIterator objects which are essentially pointers to CConfigurationParameter*. The iterator refers to pointers so that the actual parameter can polymorph (recall that CConfigurationParameter is an abstract base class).

Convenience methods are also provided to locate and perform common operations on parameters of well known types.

METHODS

SConfigurableObject (const std::string& rName, CTCLInterpreter& rInterp) throws ;

Constructs a new configurable object. rName is the name of the new object. This is normally the name of the digitizer module that is being created.

The SConfigurableObject registers rName as a new Tcl command in rInterp.

const std::string getName() throws ;

Returns the name of this object. This is also a command that is registered in the interpreter that processes the configuration script.

virtual int operator() (CTCLInterpreter& rInterp, CTCLResult& rResult, int nArgs, char** pArgs) throws ;

Performs command processing of the command words specified by nArgs (number of words) and pArgs (Pointer to array of null terminated strings that make up the command words). rInterp is the interpreter that is processing the command and rResult contains the final result string.

This method recognizes and processes the config, cget and help sub-commands. Derived classes can override this method. If they do so, and still want the command configurability, they should attempt to recognize their own keywords and, if that fails, invoke this base class method to ensure the standard sub-commands are executed.

virtual int Configure (CTCLInterpreter& rInterp, CTCLResult& rResult, int nArgs, char** pArgs) throws ;

This method is dispatched to in response to the config subcommand. It ensures that nArgs and pArgs are consistent with a configuration command (an even number of addition parameters with at least one configuration keyword and its value).

The configuration changes are performed in a single pass from left to right on the command line. this means that if there are errors either in configuration parameter keywords or their values, any configuration operations performed prior to the failing operation will not be rolled back to their prior values.

virtual int ListConfiguration (CTCLInterpreter& rInterp, CTCLResult& rResult, int nArgs, char** pArgs) throws ;

Dispatched to by operator() if the subcommand was cget. The current object's configuration is marshalled and returned int rResult in a form that is easily interpreted by Tcl scripts. The form is a Tcl list of two element sublists. Each sublist contains, in order, a configuration parmameter name and its value.

SConfigurableObject::ParameterIterator AddParameter(CConfigurationParameter* pConfigParam) throws ;

Creates a configuration parameter. This method is intended to create custom parameter types. See the convenience method below for methods that produce specific parameter types. pConfigParam is the parameter that will be added. Recall that a CConfigurationParameter has a name. That name will be the configuration parameter keyword.

The return value is a SConfigurableObject::ParameterIterator. This is a pointer-like object which, when dereferenced provides a pointer to the actual configuration parameter. Note that normally prior to use, the returned pointer will have to be cast to be a pointer to the actual type of the parameter.

SConfigurableObject::ParameterIterator AddIntParam (const std::string& sParamName, int nDefault = =0) throws ;

Creates an integer configuration parameter ( CIntConfigParam). sParamName is the name of the parameter and nDefault will be the initial value of the parameter.

The method returns a SConfigurableObject::ParameterIterator which, when dereferenced returns a pointer to a CConfigurationParameter. Prior to use, this should be cast to a pointer to a CIntConfigtParam. For example, when called within a method of a class derived from a SConfigurableObject:


CIntConfigParam* pParam = reinterpret_cast<CIntConfigParam*>(*AddIntParam("someParam"));
                        

SConfigurableObject::ParameterIterator AddBoolParam (const std::string& rName, bool fDefault) throws ;

Adds a boolean parameter CBoolConfigParam named rName with the default value fDefault. The return value is a SConfigurableObject::ParameterIterator. See the documentation of the AddIntParam for more information about how to use the return value.

SConfigurableObject::ParameterIterator AddStringParam (const std::string& rName) throws ;

Adds a string valued parameter (CStringConfigParam) to the configuration database for this object. The name of the parameter will be rName. The initial value of the string will be empty. The return value is a SConfigurableObject::ParameterIterator which can be used as described in AddIntParam.

SConfigurableObject::ParameterIterator AddIntArrayParam (const std::string& rParameterName, int nArraySize, int nDefault = =0) throws ;

Adds a configuration parameter that is a fixed sized array of integers (CIntArrayParam). The array will be named rParameterName and contains nArraySize elements each initialized to nDefault

The return value of the method is a SConfigurableObject::ParameterIterator.

SConfigurableObject::ParameterIterator AddStringArrayParam (const std::string& rName, int nArraySize) throws ;

Adds a parameter that is an array of strings (CStringArrayParam). The parameter's name is rName. The array is fixed size containing nArraySize elements.

As with other parameter creation methods, the return value is a SConfigurableObject::ParameterIterator

SConfigurableObject::ParameterIterator AddEnumParam( std::string name, std::vector<std::pair<std::string, int> > values, std::string defaultValue) throws ;

Adds an enumerated parameter (CEnumParameter) to the configuration database. The name of the parameter is name. The values vector contains the legal string values and the corresponding integer values. The defaultValue must be set to the default value which should be one of the elements of the values vector.

SConfigurableObject::ParameterIterator Find (const std::string& rKeyword) throws ;

Returns a SConfigurableObject::ParameterIterator pointer like object to a pointer to the configuration object named rKeyword. If the configuration database does not contain an object named, rKeyword the method returns the value that would be returned from end below.

SConfigurableObject::ParameterIterator begin() throws ;

Returns a pointer like object (SConfigurableObject::ParameterIterator) that points to a pointer to the first configuration parameter object in the object's configuration database. Note that if there are not yet any configuration objects, this will return the value returned from end below.

SConfigurableObject::ParameterIterator objects are pointer-like. When dereferenced, they produce a CConfigurationParameter*. They can also be incremented via ++ to point to the next object in the container that represents the configuration database. If there are no more elements in the container ++ will produce an object equal to the return value for end below.

SConfigurableObject::ParameterIterator end() throws ;

Returns a SConfigurableObject::ParameterIterator that does not point to anything but represents an iterator that has stepped off the end of the container. Thus you can iterate over all configuration objects in the container via a loop like:


SConfigurableObject::ParameterIterator p = begin()
while (p != end()) {
   CConfiguationParameter* pParam = *p;
   ...
   p++;
}
                        

int size() throws ;

Returns the number of configuration items in the configuration database. This provides an alternative mechanism for iterating through the collection:


SConfigurableObject::ParameterIterator p = begin();
for (int = 0; i <  size(); i++) {
    CConfigurationParameter* pParam = *p;
    ...
    p++;
}
                        

std::string ListParameters (const std::string& rPattern) throws ;

Produces a string that is a properly formatted Tcl list of parameters that match the glob pattern in rPattern. If required, elements of the list are properly quoted. The list consists of two element sublists that contain in order the name of a configuration parameter and its value.

std::string ListKeywords();

Returns a string that consists of configuration parameter names followed by the format required of that parameter. The output of this method is intended for human consumption.

int getIntegerValue(std::string name) throws ;

Returns the value of the integer parameter named name. If that parameter does not exists, a std::string exception is thrown indicating that. Note that the operation of this method is not well defined if name is not a CIntConfigParam.

bool getBoolValue (std::string name) throws ;

Returns the boolean parameter named by name. If name is not the name of a configuration parameter for this object, a std::string exception is raised whose value is a human readable error message.

The return value of this methdo is not well defined if name is not a CBoolConfigParam object.

CIntArrayParam* getIntArray(std::string name) throws ;

Returns a pointer to the CIntArrayParam integer array parameter named name. If there is no parameter named name a std::string exception is thrown containing a human readable error message.

The behavior of invoking methods on the return value if name does not identify a CIntArrayParam is not well defined.

int getEnumValue(std::string name) throws ;

Returns the value of an enumerated parameter name. If there is no configuration parameter name, a std::string exception is thrown with a human readable error message.

The value returned is the integer value that corresponds to the current std::string configured for name. The behavior of this method is not well defined if name does not identify a CEnumParameter.

PUBLIC VARIABLES, TYPES and CONSTANTS

typedef std::list<CConfigurationParameter*> ConfigArray;

This is the type of the container that holds the configuration database. Publicizing this type is required to publicize the next type.

typedef ConfigArray::iterator ParameterIterator;

A pointer like object which when dereferenced returns a CConfigurationParameter*. Iterators can also be incremented to 'point' to the next item in the container of configuration parameters.

std::vector<std::pair<std::string, int> >

This vector type contains legal values for enumerated parameters. The first item of each pair is a valid text string that can be configured into enumerated parameters while the second item is the integer equivalent that will be returned from getEnumValue when the parameter is configured with the std::string value of the pair.