A class encapsulating a lua table. More...

#include <ParameterSet.h>

Detailed Description

A class encapsulating a lua table.

All the items inside the table will be converted to plain C++ type, and can be accessed via the ParameterSet::get() functions.

Only the following types are supported:

Consider the following lua snippet:

  • ```lua { x = 91., y = "string", z = {10, 20, 30, 40} }
  • ```

    The resulting ParameterSet will encapsulates three values:

    • x of type double = 91.
    • y of type std::string = "string"
    • z of type std::vector<int64_t> = [10, 20, 30, 40]

    and you would use the following code to access the z value:

  • ``` std::vector<int64_t> values = set.get<std::vector<int64_t>>("z");
  • ```
Todo:
Document the freezing of the configuration in ConfigurationReader
Note
You should never try to create a ParameterSet yourself. Always use the ConfigurationReader class to parse the configuration file

Definition at line 77 of file ParameterSet.h.

Inheritance diagram for ParameterSet:

Classes

struct  Element
 A small wrapper around a boost::any value. More...
 

Public Member Functions

template<typename T >
const T & get (const std::string &name) const
 
template<typename T >
const T & get (const std::string &name, const T &defaultValue) const
 
bool exists (const std::string &name) const
 
template<typename T >
bool existsAs (const std::string &name) const
 
template<typename T >
std::enable_if< std::is_same< T, bool >::value||std::is_same< T, InputTag >::value >::type set (const std::string &name, const T &value)
 Change the value of a given parameter. If the parameter does not exist, it's first created. More...
 
template<typename T >
std::enable_if< is_string< T >::value >::type set (const std::string &name, const T &value)
 Change the value of a given parameter. If the parameter does not exist, it's first created. More...
 
template<typename T >
std::enable_if< std::is_integral< T >::value &&!std::is_same< T, bool >::value >::type set (const std::string &name, const T &value)
 Change the value of a given parameter. If the parameter does not exist, it's first created. More...
 
template<typename T >
std::enable_if< std::is_floating_point< T >::value >::type set (const std::string &name, const T &value)
 Change the value of a given parameter. If the parameter does not exist, it's first created. More...
 
void parse (lua_State *L, int index)
 Parse fields of a lua table. More...
 
std::string getModuleName () const
 
std::string getModuleType () const
 
const ParameterSetglobalParameters () const
 

Protected Member Functions

 ParameterSet (const std::string &module_type, const std::string &module_name)
 
virtual std::pair< boost::any, bool > parseItem (const std::string &key, lua_State *L, int index)
 
virtual void create (const std::string &name, const boost::any &value)
 Add a new element to the ParameterSet. More...
 
virtual void setInternal (const std::string &name, Element &element, const boost::any &value)
 
virtual void freeze ()
 

Protected Attributes

std::map< std::string, Elementm_set
 

Friends

class ConfigurationReader
 
class Configuration
 

Member Function Documentation

void ParameterSet::create ( const std::string &  name,
const boost::any &  value 
)
protectedvirtual

Add a new element to the ParameterSet.

Parameters
nameName of the new parameter
valueValue of the new parameter

Reimplemented in LazyParameterSet.

Definition at line 72 of file ParameterSet.cc.

void ParameterSet::parse ( lua_State *  L,
int  index 
)

Parse fields of a lua table.

Parameters
Lthe lua state
indexThe index on the stack of the table to parse

Definition at line 31 of file ParameterSet.cc.

Referenced by lua::to_any().

template<typename T >
std::enable_if<std::is_same<T, bool>::value || std::is_same<T, InputTag>::value>::type ParameterSet::set ( const std::string &  name,
const T &  value 
)
inline

Change the value of a given parameter. If the parameter does not exist, it's first created.

Parameters
nameThe name of the parameter to change
valueThe new value of the parameter
Warning
Vectors are currently not supported

Definition at line 113 of file ParameterSet.h.

template<typename T >
std::enable_if<is_string<T>::value>::type ParameterSet::set ( const std::string &  name,
const T &  value 
)
inline

Change the value of a given parameter. If the parameter does not exist, it's first created.

Specialization for string type, with implicit cast to std::string

Parameters
nameThe name of the parameter to change
valueThe new value of the parameter
Warning
Vectors are currently not supported

Definition at line 128 of file ParameterSet.h.

template<typename T >
std::enable_if<std::is_integral<T>::value && !std::is_same<T, bool>::value>::type ParameterSet::set ( const std::string &  name,
const T &  value 
)
inline

Change the value of a given parameter. If the parameter does not exist, it's first created.

Specialization for integral type, with implicit cast to int64_t

Parameters
nameThe name of the parameter to change
valueThe new value of the parameter
Warning
Vectors are currently not supported

Definition at line 143 of file ParameterSet.h.

template<typename T >
std::enable_if<std::is_floating_point<T>::value>::type ParameterSet::set ( const std::string &  name,
const T &  value 
)
inline

Change the value of a given parameter. If the parameter does not exist, it's first created.

Specialization for floating-point type, with implicit cast to double

Parameters
nameThe name of the parameter to change
valueThe new value of the parameter
Warning
Vectors are currently not supported

Definition at line 158 of file ParameterSet.h.


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