00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Fennel_DynamicParam_Included
00025 #define Fennel_DynamicParam_Included
00026
00027 #include "fennel/common/SharedTypes.h"
00028 #include "fennel/tuple/TupleData.h"
00029 #include "fennel/tuple/TupleDescriptor.h"
00030 #include "fennel/synch/SynchObj.h"
00031
00032 #include <map>
00033 #include <boost/scoped_array.hpp>
00034
00035
00036 FENNEL_BEGIN_NAMESPACE
00037
00045 class FENNEL_EXEC_EXPORT DynamicParam
00046 {
00047 friend class DynamicParamManager;
00048
00049 boost::scoped_array<FixedBuffer> pBuffer;
00050 TupleAttributeDescriptor desc;
00051 TupleDatum datum;
00052 bool isCounter;
00053
00054 public:
00055 explicit DynamicParam(
00056 TupleAttributeDescriptor const &desc,
00057 bool isCounter = false);
00058 inline TupleDatum const &getDatum() const;
00059 inline TupleAttributeDescriptor const &getDesc() const;
00060 };
00061
00067 class FENNEL_EXEC_EXPORT DynamicParamManager
00068 {
00069 typedef std::map<DynamicParamId, SharedDynamicParam> ParamMap;
00070 typedef ParamMap::const_iterator ParamMapConstIter;
00071
00072 StrictMutex mutex;
00073
00074 ParamMap paramMap;
00075
00076 DynamicParam &getParamInternal(DynamicParamId dynamicParamId);
00077
00078 void createParam(
00079 DynamicParamId dynamicParamId,
00080 SharedDynamicParam param,
00081 bool failIfExists);
00082 public:
00095 void createParam(
00096 DynamicParamId dynamicParamId,
00097 const TupleAttributeDescriptor &attrDesc,
00098 bool failIfExists = true);
00099
00111 void createCounterParam(
00112 DynamicParamId dynamicParamId,
00113 bool failIfExists = true);
00114
00120 void deleteParam(DynamicParamId dynamicParamId);
00121
00130 void writeParam(DynamicParamId dynamicParamId, const TupleDatum &src);
00131
00139 DynamicParam const &getParam(DynamicParamId dynamicParamId);
00140
00149 void readParam(DynamicParamId dynamicParamId, TupleDatum &dest);
00150
00156 void incrementCounterParam(DynamicParamId dynamicParamId);
00157
00163 void decrementCounterParam(DynamicParamId dynamicParamId);
00164
00168 void deleteAllParams();
00169 };
00170
00171 inline TupleDatum const &DynamicParam::getDatum() const
00172 {
00173 return datum;
00174 }
00175
00176 inline TupleAttributeDescriptor const &DynamicParam::getDesc() const
00177 {
00178 return desc;
00179 }
00180
00181 FENNEL_END_NAMESPACE
00182
00183 #endif
00184
00185