torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::generic::ParameterMap Class Reference

#include <ParameterMap.hpp>

+ Collaboration diagram for torc::generic::ParameterMap:

Data Structures

struct  ParamData
 

Public Types

typedef SymTab< std::string,
ParameterSharedPtr, true > 
TabParams
 
typedef boost::shared_ptr
< TabParams
TabParamsPtr
 

Public Member Functions

ParameterSharedPtr get (const ParameterContext &inContext, const std::string &inName) const
 
void set (const ParameterContext &inContext, const std::string &inName, const ParameterSharedPtr &inParam)
 
void getAllParameters (const ParameterContext &inContext, std::map< std::string, ParameterSharedPtr > &outParams) const
 
void getOverriddenParameters (const ParameterContext &inContext, std::map< std::string, ParameterSharedPtr > &outParams) const
 
template<typename _Action >
void applyOnAllParameters (const ParameterContext &inContext, const _Action &action) throw (Error)
 
template<typename _Action >
void applyOnOverriddenParameters (const ParameterContext &inContext, const _Action &action) throw (Error)
 
ParameterContext getNewContext ()
 
void registerContext (const ParameterContext &inContext, const ParameterContext &inParentContext=ParameterContext()) throw (Error)
 
bool isContextRegistered (const ParameterContext &inContext) const
 
void unregisterContext (const ParameterContext &inContext)
 
 ParameterMap ()
 
 ~ParameterMap () throw ()
 
 ParameterMap (const ParameterMap &source)
 
ParameterMapoperator= (const ParameterMap &source)
 

Private Types

typedef boost::shared_ptr
< ParamData
ParamDataPtr
 

Private Attributes

SymTab< ParameterContext,
ParamDataPtr
mParameters
 
ParameterContext mNextContext
 

Detailed Description

Stores Name-Parameter mappings. This map can be used to get and set values for different parameters.

Definition at line 37 of file ParameterMap.hpp.

Member Typedef Documentation

typedef boost::shared_ptr<ParamData> torc::generic::ParameterMap::ParamDataPtr
private

Definition at line 115 of file ParameterMap.hpp.

Definition at line 39 of file ParameterMap.hpp.

Definition at line 40 of file ParameterMap.hpp.

Constructor & Destructor Documentation

torc::generic::ParameterMap::ParameterMap ( )

Definition at line 132 of file ParameterMap.cpp.

132 : mParameters(), mNextContext(1) {}
SymTab< ParameterContext, ParamDataPtr > mParameters
ParameterContext mNextContext
torc::generic::ParameterMap::~ParameterMap ( )
throw (
)

Definition at line 134 of file ParameterMap.cpp.

134 {}
torc::generic::ParameterMap::ParameterMap ( const ParameterMap source)

Definition at line 136 of file ParameterMap.cpp.

136  : mParameters(source.mParameters),
137  mNextContext(1) {}
SymTab< ParameterContext, ParamDataPtr > mParameters
ParameterContext mNextContext

Member Function Documentation

template<typename _Action >
void torc::generic::ParameterMap::applyOnAllParameters ( const ParameterContext inContext,
const _Action &  action 
)
throw (Error
)
inline

Apply action on all parameters.

Parameters
[in]inContextthe context for which the param is valid
[in]actionAction to be applied

Definition at line 120 of file ParameterMap.hpp.

121  {
122  if(!inContext) {
123  return;
124  }
125  try {
126  ParamDataPtr data;
127  mParameters.get(inContext, data);
128  if(!data) {
129  return;
130  } else {
131  data->mParams.applyOnAll(action);
132  applyOnAllParameters(data->mParentContext, action);
133  }
134  } catch(Error& e) {
135  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
136  throw;
137  }
138 }
void applyOnAllParameters(const ParameterContext &inContext, const _Action &action)
SymTab< ParameterContext, ParamDataPtr > mParameters
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
boost::shared_ptr< ParamData > ParamDataPtr

+ Here is the call graph for this function:

template<typename _Action >
void torc::generic::ParameterMap::applyOnOverriddenParameters ( const ParameterContext inContext,
const _Action &  action 
)
throw (Error
)
inline

Apply action on overridden parameters

Parameters
[in]inContextthe context for which the param is valid
[in]actionAction to be applied

Definition at line 140 of file ParameterMap.hpp.

141  {
142  if(!inContext) {
143  return;
144  }
145  try {
146  ParamDataPtr data;
147  mParameters.get(inContext, data);
148  if(!data) {
149  return;
150  } else {
151  data->mParams.applyOnAll(action);
152  }
153  } catch(Error& e) {
154  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
155  throw;
156  }
157 }
SymTab< ParameterContext, ParamDataPtr > mParameters
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
boost::shared_ptr< ParamData > ParamDataPtr

+ Here is the call graph for this function:

ParameterSharedPtr torc::generic::ParameterMap::get ( const ParameterContext inContext,
const std::string &  inName 
) const

Get a named parameter or null if none exists

Returns
The parameter

Definition at line 28 of file ParameterMap.cpp.

29  {
30  if(!inContext) {
31  return ParameterSharedPtr();
32  }
33  ParameterSharedPtr param;
34  ParamDataPtr data;
35  mParameters.get(inContext, data);
36  if(!data) {
37  return ParameterSharedPtr();
38  } else {
39  data->mParams.get(inName, param);
40  if(!param) //Get default param value from parent
41  {
42  return get(data->mParentContext, inName);
43  }
44  }
45  return param;
46 }
boost::shared_ptr< Parameter > ParameterSharedPtr
SymTab< ParameterContext, ParamDataPtr > mParameters
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
boost::shared_ptr< ParamData > ParamDataPtr

+ Here is the call graph for this function:

void torc::generic::ParameterMap::getAllParameters ( const ParameterContext inContext,
std::map< std::string, ParameterSharedPtr > &  outParams 
) const

Get all parameter name-value-pairs

Parameters
[in]inContextthe context for which the param is valid
[out]outParamsMap to be populated

Definition at line 60 of file ParameterMap.cpp.

61  {
62  typedef std::map<std::string, ParameterSharedPtr> DataMap;
63  ParamDataPtr data;
64  mParameters.get(inContext, data);
65  if(!data) {
66  return;
67  } else {
68  if(data->mParentContext) {
69  ParamDataPtr parentData;
70  mParameters.get(data->mParentContext, parentData);
71  parentData->mParams.getValueMap(outParams);
72  DataMap::iterator param = outParams.begin();
73  DataMap::iterator pEnd = outParams.end();
74  for(; param != pEnd; ++param) {
75  ParameterSharedPtr newValue;
76  data->mParams.get((*param).first, newValue);
77  //Value was overridden in child
78  if(newValue) {
79  outParams[(*param).first] = newValue;
80  }
81  }
82  } else {
83  //We have the cell context itself
84  data->mParams.getValueMap(outParams);
85  }
86  }
87 
88  return;
89 }
boost::shared_ptr< Parameter > ParameterSharedPtr
SymTab< ParameterContext, ParamDataPtr > mParameters
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
boost::shared_ptr< ParamData > ParamDataPtr

+ Here is the call graph for this function:

ParameterContext torc::generic::ParameterMap::getNewContext ( )

Definition at line 105 of file ParameterMap.cpp.

105  {
106  return mNextContext++;
107 }
ParameterContext mNextContext
void torc::generic::ParameterMap::getOverriddenParameters ( const ParameterContext inContext,
std::map< std::string, ParameterSharedPtr > &  outParams 
) const

Get all parameter name-value-pairs that have been overridden in this context. For a view context this will return an empty map.

Parameters
[in]inContextthe context for which the param is valid
[out]outParamsMap to be populated

Definition at line 91 of file ParameterMap.cpp.

92  {
93  typedef std::map<std::string, ParameterSharedPtr> DataMap;
94  ParamDataPtr data;
95  mParameters.get(inContext, data);
96  if(!data) {
97  return;
98  } else {
99  //We have the cell context itself
100  data->mParams.getValueMap(outParams);
101  }
102  return;
103 }
SymTab< ParameterContext, ParamDataPtr > mParameters
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
boost::shared_ptr< ParamData > ParamDataPtr

+ Here is the call graph for this function:

bool torc::generic::ParameterMap::isContextRegistered ( const ParameterContext inContext) const

Definition at line 122 of file ParameterMap.cpp.

122  {
123  ParamDataPtr data;
124  mParameters.get(inContext, data);
125  return data;
126 }
SymTab< ParameterContext, ParamDataPtr > mParameters
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
boost::shared_ptr< ParamData > ParamDataPtr

+ Here is the call graph for this function:

ParameterMap & torc::generic::ParameterMap::operator= ( const ParameterMap source)

Definition at line 139 of file ParameterMap.cpp.

139  {
140  if(this != &source) {
141  mParameters = source.mParameters;
142  mNextContext = 1;
143  }
144  return *this;
145 }
SymTab< ParameterContext, ParamDataPtr > mParameters
ParameterContext mNextContext
void torc::generic::ParameterMap::registerContext ( const ParameterContext inContext,
const ParameterContext inParentContext = ParameterContext() 
)
throw (Error
)

Definition at line 109 of file ParameterMap.cpp.

110  {
111  ParamDataPtr data;
112  mParameters.get(inContext, data);
113  if(data) {
114  //TBD::ERROR
115  } else {
116  data = boost::shared_ptr < ParamData > (new ParamData());
117  data->mParentContext = inParentContext;
118  mParameters.set(inContext, data);
119  }
120 }
bool set(const KeyType &inKey, const ValueType &inValue)
Definition: SymTab.hpp:132
SymTab< ParameterContext, ParamDataPtr > mParameters
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
boost::shared_ptr< ParamData > ParamDataPtr
void torc::generic::ParameterMap::set ( const ParameterContext inContext,
const std::string &  inName,
const ParameterSharedPtr inParam 
)

Saves a parameter by name. Overrides existing parameters if it exists.

Parameters
[in]inContextthe context for which the param is valid
[in]inNamename of param
[in]inParampointer to the parameter

Definition at line 48 of file ParameterMap.cpp.

49  {
50  ParamDataPtr data;
51  mParameters.get(inContext, data);
52  if(!data) {
53  return;
54  } else {
55  data->mParams.set(inName, inParam);
56  }
57  return;
58 }
SymTab< ParameterContext, ParamDataPtr > mParameters
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
boost::shared_ptr< ParamData > ParamDataPtr

+ Here is the call graph for this function:

void torc::generic::ParameterMap::unregisterContext ( const ParameterContext inContext)

Definition at line 128 of file ParameterMap.cpp.

128  {
129  mParameters.remove(inContext);
130 }
bool remove(const KeyType &inKey)
Definition: SymTab.hpp:153
SymTab< ParameterContext, ParamDataPtr > mParameters

+ Here is the call graph for this function:

Field Documentation

ParameterContext torc::generic::ParameterMap::mNextContext
private

Definition at line 117 of file ParameterMap.hpp.

SymTab<ParameterContext, ParamDataPtr> torc::generic::ParameterMap::mParameters
private

Definition at line 116 of file ParameterMap.hpp.


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