00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_PARAMETERMAP_HPP
00017 #define TORC_GENERIC_OM_PARAMETERMAP_HPP
00018
00019 #include "torc/generic/om/PointerTypes.hpp"
00020 #include <string>
00021
00022
00023 #include <boost/shared_ptr.hpp>
00024
00025 #include "torc/generic/om/ParameterContext.hpp"
00026 #include "torc/generic/om/SymTab.hpp"
00027
00028 namespace torc { namespace generic { class Parameter; } }
00029
00030 namespace torc {
00031
00032 namespace generic {
00033
00034
00035
00036
00037 class ParameterMap
00038 {
00039 public:
00040 typedef SymTab< std::string,
00041 ParameterSharedPtr, true> TabParams;
00042 typedef boost::shared_ptr<TabParams> TabParamsPtr;
00043
00044
00045
00046
00047 ParameterSharedPtr
00048 get(const ParameterContext &inContext,
00049 const std::string &inName) const throw();
00050
00051
00052
00053
00054
00055
00056
00057 void
00058 set(const ParameterContext &inContext,
00059 const std::string &inName,
00060 const ParameterSharedPtr &inParam) throw();
00061
00062
00063
00064
00065
00066
00067 void
00068 getAllParameters( const ParameterContext &inContext,
00069 std::map< std::string,ParameterSharedPtr > &outParams
00070 ) const throw();
00071
00072
00073
00074
00075
00076
00077 void
00078 getOverriddenParameters( const ParameterContext &inContext,
00079 std::map< std::string,ParameterSharedPtr > &outParams
00080 ) const throw();
00081
00082
00083
00084
00085
00086
00087
00088 template<typename _Action>
00089 inline void
00090 applyOnAllParameters( const ParameterContext &inContext,
00091 const _Action &action ) throw(Error);
00092
00093
00094
00095
00096
00097
00098
00099 template<typename _Action>
00100 inline void
00101 applyOnOverriddenParameters( const ParameterContext &inContext,
00102 const _Action &action ) throw(Error);
00103
00104 ParameterContext
00105 getNewContext() throw();
00106
00107 void
00108 registerContext(
00109 const ParameterContext &inContext,
00110 const ParameterContext &inParentContext = ParameterContext()
00111 ) throw(Error);
00112
00113 bool
00114 isContextRegistered(
00115 const ParameterContext &inContext ) const throw();
00116
00117 void
00118 unregisterContext( const ParameterContext &inContext ) throw();
00119
00120 ParameterMap();
00121
00122 ~ParameterMap() throw();
00123
00124 ParameterMap(const ParameterMap & source) throw();
00125
00126 ParameterMap &
00127 operator=(const ParameterMap & source) throw();
00128
00129 private:
00130 struct ParamData {
00131 TabParams mParams;
00132 ParameterContext mParentContext;
00133 ParamData()
00134 :mParams(),
00135 mParentContext() {
00136 }
00137 };
00138 typedef boost::shared_ptr<ParamData> ParamDataPtr;
00139 SymTab<ParameterContext, ParamDataPtr> mParameters;
00140 ParameterContext mNextContext;
00141 };
00142
00143 template<typename _Action>
00144 inline void
00145 ParameterMap::applyOnAllParameters(
00146 const ParameterContext &inContext,
00147 const _Action &action ) throw(Error)
00148 {
00149 if( !inContext )
00150 {
00151 return;
00152 }
00153 try
00154 {
00155 ParamDataPtr data;
00156 mParameters.get( inContext, data );
00157 if( !data )
00158 {
00159 return;
00160 }
00161 else
00162 {
00163 data->mParams.applyOnAll( action );
00164 applyOnAllParameters(
00165 data->mParentContext, action );
00166 }
00167 }
00168 catch(Error &e)
00169 {
00170 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00171 throw;
00172 }
00173 }
00174
00175 template<typename _Action>
00176 inline void
00177 ParameterMap::applyOnOverriddenParameters(
00178 const ParameterContext &inContext,
00179 const _Action &action ) throw(Error)
00180 {
00181 if( !inContext )
00182 {
00183 return;
00184 }
00185 try
00186 {
00187 ParamDataPtr data;
00188 mParameters.get( inContext, data );
00189 if( !data )
00190 {
00191 return;
00192 }
00193 else
00194 {
00195 data->mParams.applyOnAll( action );
00196 }
00197 }
00198 catch(Error &e)
00199 {
00200 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00201 throw;
00202 }
00203 }
00204
00205 }
00206
00207 }
00208 #endif // TORC_GENERIC_OM_PARAMETERMAP_HPP