#include <DynamicParam.h>
Public Member Functions | |
void | createParam (DynamicParamId dynamicParamId, const TupleAttributeDescriptor &attrDesc, bool failIfExists=true) |
Creates a new dynamic parameter. | |
void | createCounterParam (DynamicParamId dynamicParamId, bool failIfExists=true) |
Creates a new dynamic parameter that will be used as a counter. | |
void | deleteParam (DynamicParamId dynamicParamId) |
Deletes an existing dynamic parameter. | |
void | writeParam (DynamicParamId dynamicParamId, const TupleDatum &src) |
Writes a value to a dynamic parameter, overwriting any previous value. | |
DynamicParam const & | getParam (DynamicParamId dynamicParamId) |
Accesses a dynamic parameter by reference. | |
void | readParam (DynamicParamId dynamicParamId, TupleDatum &dest) |
Reads a dynamic parameter, copying the parameter into caller's TupleDatum. | |
void | incrementCounterParam (DynamicParamId dynamicParamId) |
Increments a dynamic parameter that corresponds to a counter. | |
void | decrementCounterParam (DynamicParamId dynamicParamId) |
Decrements a dynamic parameter that corresponds to a counter. | |
void | deleteAllParams () |
Deletes all dynamic parameters. | |
Private Types | |
typedef std::map< DynamicParamId, SharedDynamicParam > | ParamMap |
typedef ParamMap::const_iterator | ParamMapConstIter |
Private Member Functions | |
DynamicParam & | getParamInternal (DynamicParamId dynamicParamId) |
void | createParam (DynamicParamId dynamicParamId, SharedDynamicParam param, bool failIfExists) |
Private Attributes | |
StrictMutex | mutex |
ParamMap | paramMap |
It is multi-thread safe (but see warning on getParam).
Definition at line 67 of file DynamicParam.h.
typedef std::map<DynamicParamId, SharedDynamicParam> DynamicParamManager::ParamMap [private] |
Definition at line 69 of file DynamicParam.h.
typedef ParamMap::const_iterator DynamicParamManager::ParamMapConstIter [private] |
Definition at line 70 of file DynamicParam.h.
DynamicParam & DynamicParamManager::getParamInternal | ( | DynamicParamId | dynamicParamId | ) | [private] |
Definition at line 114 of file DynamicParam.cpp.
References paramMap.
Referenced by decrementCounterParam(), getParam(), incrementCounterParam(), readParam(), and writeParam().
00116 { 00117 ParamMapConstIter pExisting = paramMap.find(dynamicParamId); 00118 assert(pExisting != paramMap.end()); 00119 return *(pExisting->second.get()); 00120 }
void DynamicParamManager::createParam | ( | DynamicParamId | dynamicParamId, | |
SharedDynamicParam | param, | |||
bool | failIfExists | |||
) | [private] |
Definition at line 51 of file DynamicParam.cpp.
References paramMap.
Referenced by createCounterParam(), createParam(), and CalcExtDynamicVariableTest::testCalcExtDynamicVariable().
00055 { 00056 ParamMapConstIter pExisting = paramMap.find(dynamicParamId); 00057 if (pExisting != paramMap.end()) { 00058 permAssert(!failIfExists); 00059 assert(param->desc == pExisting->second->getDesc()); 00060 return; 00061 } 00062 paramMap.insert(ParamMap::value_type(dynamicParamId, param)); 00063 }
void DynamicParamManager::createParam | ( | DynamicParamId | dynamicParamId, | |
const TupleAttributeDescriptor & | attrDesc, | |||
bool | failIfExists = true | |||
) |
Creates a new dynamic parameter.
Initially, a dynamic parameter has value NULL.
dynamicParamId | unique ID of parameter within this manager; IDs need not be contiguous, and must be assigned by some other authority | |
attrDesc | descriptor for data values to be stored | |
failIfExists | if true (the default) an assertion failure will occur if dynamicParamId is already in use |
Definition at line 40 of file DynamicParam.cpp.
References createParam(), and mutex.
00044 { 00045 StrictMutexGuard mutexGuard(mutex); 00046 00047 SharedDynamicParam param(new DynamicParam(attrDesc)); 00048 createParam(dynamicParamId, param, failIfExists); 00049 }
void DynamicParamManager::createCounterParam | ( | DynamicParamId | dynamicParamId, | |
bool | failIfExists = true | |||
) |
Creates a new dynamic parameter that will be used as a counter.
Initializes the parameter value to 0. The counter parameter can be used to do atomic increments and decrements.
dynamicParamId | unique ID of parameter within this manager; IDs need not be contiguous, and must be assigned by some other authority | |
failIfExists | if true (the default) an assertion failure will occur if dynamicParamId is already in use |
Definition at line 65 of file DynamicParam.cpp.
References createParam(), mutex, StandardTypeDescriptorFactory::newDataType(), and STANDARD_TYPE_INT_64.
00068 { 00069 StrictMutexGuard mutexGuard(mutex); 00070 00071 StandardTypeDescriptorFactory stdTypeFactory; 00072 TupleAttributeDescriptor attrDesc( 00073 stdTypeFactory.newDataType(STANDARD_TYPE_INT_64)); 00074 SharedDynamicParam param(new DynamicParam(attrDesc, true)); 00075 createParam(dynamicParamId, param, failIfExists); 00076 00077 // initialize the parameter to zero 00078 PBuffer buf = param->pBuffer.get(); 00079 int64_t *pCounter = reinterpret_cast<int64_t *>(buf); 00080 *pCounter = 0; 00081 param->datum.pData = buf; 00082 param->datum.cbData = sizeof(int64_t); 00083 }
void DynamicParamManager::deleteParam | ( | DynamicParamId | dynamicParamId | ) |
Deletes an existing dynamic parameter.
dynamicParamId | ID with which parameter was created |
Definition at line 85 of file DynamicParam.cpp.
References mutex, and paramMap.
00086 { 00087 StrictMutexGuard mutexGuard(mutex); 00088 00089 assert(paramMap.find(dynamicParamId) != paramMap.end()); 00090 paramMap.erase(dynamicParamId); 00091 assert(paramMap.find(dynamicParamId) == paramMap.end()); 00092 }
void DynamicParamManager::writeParam | ( | DynamicParamId | dynamicParamId, | |
const TupleDatum & | src | |||
) |
Writes a value to a dynamic parameter, overwriting any previous value.
dynamicParamId | ID with which parameter was created | |
src | source data from which to copy |
Definition at line 94 of file DynamicParam.cpp.
References TupleDatum::cbData, TupleAttributeDescriptor::cbStorage, DynamicParam::datum, DynamicParam::getDesc(), getParamInternal(), TupleDatum::memCopyFrom(), mutex, DynamicParam::pBuffer, and TupleDatum::pData.
Referenced by CalcExtDynamicVariableTest::testCalcExtDynamicVariable().
00096 { 00097 StrictMutexGuard mutexGuard(mutex); 00098 00099 DynamicParam ¶m = getParamInternal(dynamicParamId); 00100 if (src.pData) { 00101 assert(src.cbData <= param.getDesc().cbStorage); 00102 } 00103 param.datum.pData = param.pBuffer.get(); 00104 param.datum.memCopyFrom(src); 00105 }
DynamicParam const & DynamicParamManager::getParam | ( | DynamicParamId | dynamicParamId | ) |
Accesses a dynamic parameter by reference.
dynamicParamId | ID with which parameter was created |
Definition at line 107 of file DynamicParam.cpp.
References getParamInternal(), and mutex.
00109 { 00110 StrictMutexGuard mutexGuard(mutex); 00111 return getParamInternal(dynamicParamId); 00112 }
void DynamicParamManager::readParam | ( | DynamicParamId | dynamicParamId, | |
TupleDatum & | dest | |||
) |
Reads a dynamic parameter, copying the parameter into caller's TupleDatum.
dynamicParamId | ID with which parameter was created | |
dest | destination tupledata for parameter |
Definition at line 122 of file DynamicParam.cpp.
References getParamInternal(), TupleDatum::memCopyFrom(), and mutex.
00124 { 00125 StrictMutexGuard mutexGuard(mutex); 00126 dest.memCopyFrom(getParamInternal(dynamicParamId).datum); 00127 }
void DynamicParamManager::incrementCounterParam | ( | DynamicParamId | dynamicParamId | ) |
Increments a dynamic parameter that corresponds to a counter.
dynamicParamId | ID with which the counter parameter was created |
Definition at line 129 of file DynamicParam.cpp.
References getParamInternal(), DynamicParam::isCounter, mutex, and DynamicParam::pBuffer.
00130 { 00131 StrictMutexGuard mutexGuard(mutex); 00132 00133 DynamicParam ¶m = getParamInternal(dynamicParamId); 00134 assert(param.isCounter); 00135 int64_t *pCounter = reinterpret_cast<int64_t *>(param.pBuffer.get()); 00136 (*pCounter)++; 00137 }
void DynamicParamManager::decrementCounterParam | ( | DynamicParamId | dynamicParamId | ) |
Decrements a dynamic parameter that corresponds to a counter.
dynamicParamId | ID with which the counter parameter was created |
Definition at line 139 of file DynamicParam.cpp.
References getParamInternal(), DynamicParam::isCounter, mutex, and DynamicParam::pBuffer.
00140 { 00141 StrictMutexGuard mutexGuard(mutex); 00142 00143 DynamicParam ¶m = getParamInternal(dynamicParamId); 00144 assert(param.isCounter); 00145 int64_t *pCounter = reinterpret_cast<int64_t *>(param.pBuffer.get()); 00146 (*pCounter)--; 00147 }
void DynamicParamManager::deleteAllParams | ( | ) |
Deletes all dynamic parameters.
Definition at line 149 of file DynamicParam.cpp.
References mutex, and paramMap.
00150 { 00151 StrictMutexGuard mutexGuard(mutex); 00152 paramMap.erase(paramMap.begin(), paramMap.end()); 00153 }
StrictMutex DynamicParamManager::mutex [private] |
Definition at line 72 of file DynamicParam.h.
Referenced by createCounterParam(), createParam(), decrementCounterParam(), deleteAllParams(), deleteParam(), getParam(), incrementCounterParam(), readParam(), and writeParam().
ParamMap DynamicParamManager::paramMap [private] |
Definition at line 74 of file DynamicParam.h.
Referenced by createParam(), deleteAllParams(), deleteParam(), and getParamInternal().