00001
00002
00003 #ifndef SETTING_FIELD_H_
00004 #define SETTING_FIELD_H_
00005
00006 #include <fesa-core/DataStore/Field.h>
00007 #include <fesa-core/DataStore/FieldArray.h>
00008 #include <fesa-core/DataStore/FieldArray2D.h>
00009 #include <fesa-core/DataStore/FieldString.h>
00010 #include <fesa-core/DataStore/FieldStringArray.h>
00011 #include <fesa-core/Synchronization/MultiplexingContext.h>
00012
00013 namespace fesa
00014 {
00015
00020 template<typename T>
00021 class SettingFieldScalar: public Field<T> {
00022 public:
00027 SettingFieldScalar(const std::string& fieldName, bool multiplexed,
00028 bool multiMultiplexed, DataStore* pDataStore, bool persistent, bool shared,
00029 const DataIntegrity bufferType = DoubleBuffered);
00033 ~SettingFieldScalar();
00034
00040 T get(MultiplexingContext*);
00041
00048 T getPending(MultiplexingContext*);
00049
00055 void set(T val, MultiplexingContext*);
00056
00057 };
00058
00059 template<typename T>
00060 SettingFieldScalar<T>::SettingFieldScalar(const std::string& fieldName,
00061 bool multiplexed, bool multiMultiplexed, DataStore* pDataStore,
00062 bool isPersistent, bool shared,
00063 const DataIntegrity bufferType) :
00064 Field<T> (fieldName, Setting, multiplexed, multiMultiplexed,
00065 isPersistent, bufferType, pDataStore) {
00066
00067 this->isShared_ = shared;
00068 }
00069
00070 template<typename T>
00071 SettingFieldScalar<T>::~SettingFieldScalar() {
00072
00073 }
00074
00075 template<typename T>
00076 T SettingFieldScalar<T>::get(MultiplexingContext* context) {
00077
00078 if (context == NULL)
00079 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00080
00081 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00082 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00083 this->name_.c_str());
00084
00085 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00086 : this->multiplexingManager_->getSlot(*context);
00087 FieldValue<T>* pFV = this->getFieldValue(slot);
00088 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00089 {
00090
00091 return (pFV->pendingBuffer((char*) pFV));
00092 }
00093 else
00094 {
00095
00096 return (pFV->activeBuffer((char*) pFV));
00097 }
00098 }
00099
00100 template<typename T>
00101 T SettingFieldScalar<T>::getPending(MultiplexingContext* context) {
00102
00103 if (context == NULL)
00104 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00105
00106 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00107 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00108 this->name_.c_str());
00109
00110 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00111 : this->multiplexingManager_->getSlot(*context);
00112 FieldValue<T>* pFV = this->getFieldValue(slot);
00113
00114 return (pFV->pendingBuffer((char*) pFV));
00115 }
00116
00117 template<typename T>
00118 void SettingFieldScalar<T>::set(T val, MultiplexingContext* context) {
00119
00120 if (context == NULL)
00121 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00122
00123 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00124 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00125 this->name_.c_str());
00126
00127 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00128 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00129 this->name_.c_str());
00130
00131 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00132 : this->multiplexingManager_->requireSlot(*context);
00133 FieldValue<T>* pFV = this->getFieldValue(slot);
00134
00135 this->resetToBeSync(slot);
00136
00137
00138 pFV->pendingBuffer((char*) pFV) = val;
00139 this->registerModifiedField(pFV, context);
00140 }
00141
00142
00143
00148 template<typename T>
00149 class SettingFieldStruct: public Field<T> {
00150 public:
00156 SettingFieldStruct(const std::string& fieldName, bool multiplexed,
00157 bool multiMultiplexed, DataStore* pDataStore, bool persistent, bool shared,
00158 const DataIntegrity bufferType = DoubleBuffered);
00162 ~SettingFieldStruct();
00163
00169 const T* get(MultiplexingContext*);
00170
00177 const T* getPending(MultiplexingContext*);
00178
00184 void set(T* val, MultiplexingContext*);
00185
00186 protected:
00187
00188 void checkContext(MultiplexingContext* context);
00189 };
00190
00191 template<typename T>
00192 SettingFieldStruct<T>::SettingFieldStruct(const std::string& fieldName,
00193 bool multiplexed, bool multiMultiplexed, DataStore* pDataStore,
00194 bool isPersistent, bool shared,
00195 const DataIntegrity bufferType) :
00196 Field<T> (fieldName, Setting, multiplexed, multiMultiplexed,
00197 isPersistent, bufferType, pDataStore) {
00198
00199 this->isShared_ = shared;
00200 }
00201
00202 template<typename T>
00203 SettingFieldStruct<T>::~SettingFieldStruct() {
00204
00205 }
00206
00207 template<typename T>
00208 const T* SettingFieldStruct<T>::get(MultiplexingContext* context) {
00209
00210 if (context == NULL)
00211 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00212
00213 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00214 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00215 this->name_.c_str());
00216
00217 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00218 : this->multiplexingManager_->getSlot(*context);
00219 FieldValue<T>* pFV = this->getFieldValue(slot);
00220 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00221 {
00222
00223
00224 return (const T*) (&(pFV->pendingBuffer((char*) pFV)));
00225 }
00226 else
00227 {
00228
00229
00230 return (const T*) (&(pFV->activeBuffer((char*) pFV)));
00231 }
00232 }
00233
00234 template<typename T>
00235 const T* SettingFieldStruct<T>::getPending(MultiplexingContext* context) {
00236
00237 if (context == NULL)
00238 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00239
00240 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00241 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00242 this->name_.c_str());
00243
00244 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00245 : this->multiplexingManager_->getSlot(*context);
00246 FieldValue<T>* pFV = this->getFieldValue(slot);
00247
00248 return (const T*) (&(pFV->pendingBuffer((char*) pFV)));
00249 }
00250
00251 template<typename T>
00252 void SettingFieldStruct<T>::set(T* val, MultiplexingContext* context) {
00253
00254 if (context == NULL)
00255 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00256
00257 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00258 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00259 this->name_.c_str());
00260
00261 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00262 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00263 this->name_.c_str());
00264
00265 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00266 : this->multiplexingManager_->requireSlot(*context);
00267 FieldValue<T>* pFV = this->getFieldValue(slot);
00268
00269 this->resetToBeSync(slot);
00270
00271
00272 std::memcpy(&pFV->pendingBuffer((char*) pFV), val, sizeof(T));
00273 this->registerModifiedField(pFV, context);
00274 }
00275
00276 template<typename T>
00277 void SettingFieldStruct<T>::checkContext(MultiplexingContext* context) {
00278
00279 if (context == NULL)
00280 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00281
00282 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00283 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00284 this->name_.c_str());
00285
00286 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00287 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00288 this->name_.c_str());
00289 }
00290
00291
00292
00293 template<typename T>
00294 class SettingFieldArray: public FieldArray<T> {
00295 public:
00300 SettingFieldArray(const std::string& fieldName, bool multiplexed,
00301 bool multiMultiplexed, DataStore* pDataStore, bool persistent, bool shared, int32_t size,
00302 const DataIntegrity bufferType = DoubleBuffered);
00303
00307 ~SettingFieldArray();
00308
00314 const T* get(uint32_t& size, MultiplexingContext* context);
00315
00322 void set(const T* val, uint32_t size, MultiplexingContext* context);
00323
00329 uint32_t getSize(MultiplexingContext* context);
00330
00331 protected:
00332
00333 void checkContext(MultiplexingContext* context);
00334 };
00335
00336 template<typename T>
00337 SettingFieldArray<T>::SettingFieldArray(const std::string& fieldName,
00338 bool multiplexed, bool multiMultiplexed, DataStore* pDataStore,
00339 bool isPersistent, bool shared, int32_t size,
00340 const DataIntegrity bufferType) :
00341 FieldArray<T> (fieldName, Setting, multiplexed, multiMultiplexed,
00342 isPersistent, bufferType, pDataStore, size) {
00343
00344 this->isShared_ = shared;
00345 }
00346
00347 template<typename T>
00348 SettingFieldArray<T>::~SettingFieldArray() {
00349
00350 }
00351
00352 template<typename T>
00353 const T* SettingFieldArray<T>::get(uint32_t& size,
00354 MultiplexingContext* context) {
00355
00356 if (context == NULL)
00357 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00358
00359 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00360 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00361 this->name_.c_str());
00362
00363 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00364 : this->multiplexingManager_->getSlot(*context);
00365 FieldValue<T[]>* pFV = this->getFieldValue(slot);
00366
00367 size = pFV->getActiveCurrentSize();
00368 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00369 {
00370
00371 return (const T*) (pFV->pendingBuffer((char*) pFV));
00372 }
00373 else
00374 {
00375
00376 return (const T*) (pFV->activeBuffer((char*) pFV));
00377 }
00378 }
00379
00380 template<typename T>
00381 void SettingFieldArray<T>::set(const T* val, uint32_t size,
00382 MultiplexingContext* context) {
00383
00384 if (context == NULL)
00385 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00386
00387 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00388 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00389 this->name_.c_str());
00390 this->checkContext(context);
00391
00392 this->checkMaxDimension(size);
00393
00394 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00395 : this->multiplexingManager_->requireSlot(*context);
00396 FieldValue<T[]>* pFV = this->getFieldValue(slot);
00397
00398 this->resetToBeSync(slot);
00399
00400
00401 pFV->setPendingCurrentSize(size);
00402 std::memcpy(pFV->pendingBuffer((char*) pFV), val, size * sizeof(T));
00403 this->registerModifiedField(pFV, context);
00404 }
00405
00406 template<typename T>
00407 uint32_t SettingFieldArray<T>::getSize(MultiplexingContext* context) {
00408
00409 if (context == NULL)
00410 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00411 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00412 : this->multiplexingManager_->requireSlot(*context);
00413 FieldValue<T[]>* pFV = this->getFieldValue(slot);
00414 return pFV->getActiveCurrentSize();
00415 }
00416
00417 template<typename T>
00418 void SettingFieldArray<T>::checkContext(MultiplexingContext* context) {
00419
00420 if (context == NULL)
00421 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00422
00423 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00424 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00425 this->name_.c_str());
00426
00427 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00428 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00429 this->name_.c_str());
00430 }
00431
00432
00433
00434 template<typename T>
00435 class SettingFieldScalarArray: public SettingFieldArray<T> {
00436 public:
00441 SettingFieldScalarArray(const std::string& fieldName, bool multiplexed,
00442 bool multiMultiplexed, DataStore* pDataStore,
00443 bool persistent, bool shared, int32_t size,
00444 const DataIntegrity bufferType = DoubleBuffered);
00445
00449 ~SettingFieldScalarArray();
00450
00457 T getCell(uint32_t index, MultiplexingContext* context);
00458
00465 void setCell(T val, uint32_t index, MultiplexingContext* context);
00466 };
00467
00468 template<typename T>
00469 SettingFieldScalarArray<T>::SettingFieldScalarArray(
00470 const std::string& fieldName, bool multiplexed, bool multiMultiplexed,
00471 DataStore* pDataStore, bool isPersistent, bool shared, int32_t size,
00472 const DataIntegrity bufferType) :
00473 SettingFieldArray<T> (fieldName, multiplexed, multiMultiplexed, pDataStore,
00474 isPersistent, shared, size, bufferType) {
00475
00476 }
00477
00478 template<typename T>
00479 SettingFieldScalarArray<T>::~SettingFieldScalarArray() {
00480
00481 }
00482
00483 template<typename T>
00484 T SettingFieldScalarArray<T>::getCell(uint32_t index,
00485 MultiplexingContext* context) {
00486
00487 if (context == NULL)
00488 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00489
00490 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00491 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00492 this->name_.c_str());
00493
00494 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00495 : this->multiplexingManager_->getSlot(*context);
00496 FieldValue<T[]>* pFV = this->getFieldValue(slot);
00497
00498 uint32_t size = pFV->getActiveCurrentSize();
00499 if ((index+1) > size) {
00500 throw FesaException(__FILE__, __LINE__,
00501 FesaErrorFieldCurrentDimensionOutOfBound.c_str(),
00502 StringUtilities::toString(index).c_str(), this->name_.c_str(),
00503 StringUtilities::toString(size).c_str());
00504 }
00505 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00506 {
00507
00508 return pFV->pendingBuffer((char*) pFV)[index];
00509 }
00510 else
00511 {
00512
00513 return pFV->activeBuffer((char*) pFV)[index];
00514 }
00515 }
00516
00517 template<typename T>
00518 void SettingFieldScalarArray<T>::setCell(T val, uint32_t index,
00519 MultiplexingContext* context) {
00520
00521 if (context == NULL)
00522 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00523
00524 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00525 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00526 this->name_.c_str());
00527 this->checkContext(context);
00528
00529 this->checkMaxDimension(index+1);
00530
00531 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00532 : this->multiplexingManager_->requireSlot(*context);
00533 FieldValue<T[]>* pFV = this->getFieldValue(slot);
00534
00535 this->resetToBeSync(slot);
00536 uint32_t size = 0;
00537
00538 if (!pFV->hasPendingChanged()) {
00539 size = pFV->getActiveCurrentSize();
00540 pFV->setPendingCurrentSize(size);
00541 std::memcpy(pFV->pendingBuffer((char*) pFV), pFV->activeBuffer(
00542 (char*) pFV), size * sizeof(T));
00543 }
00544
00545
00546 size = pFV->getPendingCurrentSize();
00547 if ((index + 1) > size)
00548 pFV->setPendingCurrentSize(index+1);
00549
00550 pFV->pendingBuffer((char*) pFV)[index] = val;
00551 this->registerModifiedField(pFV, context);
00552 }
00553
00554
00555
00556 template<typename T>
00557 class SettingFieldStructArray: public SettingFieldArray<T> {
00558 public:
00563 SettingFieldStructArray(const std::string& fieldName, bool multiplexed,
00564 bool multiMultiplexed, DataStore* pDataStore, bool persistent, bool shared, int32_t size,
00565 const DataIntegrity bufferType = DoubleBuffered);
00566
00570 ~SettingFieldStructArray();
00571
00578 const T* getCell(uint32_t index, MultiplexingContext* context);
00579
00586 void setCell(T* val, uint32_t index, MultiplexingContext* context);
00587
00588 };
00589
00590 template<typename T>
00591 SettingFieldStructArray<T>::SettingFieldStructArray(
00592 const std::string& fieldName, bool multiplexed, bool multiMultiplexed,
00593 DataStore* pDataStore, bool isPersistent, bool shared, int32_t size,
00594 const DataIntegrity bufferType) :
00595 SettingFieldArray<T> (fieldName, multiplexed, multiMultiplexed, pDataStore,
00596 isPersistent, shared, size, bufferType) {
00597 }
00598
00599 template<typename T>
00600 SettingFieldStructArray<T>::~SettingFieldStructArray() {
00601
00602 }
00603
00604 template<typename T>
00605 const T* SettingFieldStructArray<T>::getCell(uint32_t index,
00606 MultiplexingContext* context) {
00607
00608 if (context == NULL)
00609 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00610
00611 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00612 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00613 this->name_.c_str());
00614
00615 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00616 : this->multiplexingManager_->getSlot(*context);
00617 FieldValue<T[]>* pFV = this->getFieldValue(slot);
00618
00619 uint32_t size = pFV->getActiveCurrentSize();
00620 if ((index+1) > size) {
00621 throw FesaException(__FILE__, __LINE__,
00622 FesaErrorFieldCurrentDimensionOutOfBound.c_str(),
00623 StringUtilities::toString(index).c_str(), this->name_.c_str(),
00624 StringUtilities::toString(size).c_str());
00625 }
00626 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00627 {
00628
00629 return &(pFV->pendingBuffer((char*) pFV)[index]);
00630 }
00631 else
00632 {
00633
00634 return &(pFV->activeBuffer((char*) pFV)[index]);
00635 }
00636 }
00637
00638 template<typename T>
00639 void SettingFieldStructArray<T>::setCell(T* val, uint32_t index,
00640 MultiplexingContext* context) {
00641
00642 if (context == NULL)
00643 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00644
00645 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00646 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00647 this->name_.c_str());
00648 this->checkContext(context);
00649
00650 this->checkMaxDimension(index+1);
00651
00652 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00653 : this->multiplexingManager_->requireSlot(*context);
00654 FieldValue<T[]>* pFV = this->getFieldValue(slot);
00655
00656 this->resetToBeSync(slot);
00657
00658 uint32_t size = 0;
00659 if (!pFV->hasPendingChanged()) {
00660 size = pFV->getActiveCurrentSize();
00661 pFV->setPendingCurrentSize(size);
00662 std::memcpy(pFV->pendingBuffer((char*) pFV), pFV->activeBuffer(
00663 (char*) pFV), size * sizeof(T));
00664 }
00665
00666
00667 size = pFV->getPendingCurrentSize();
00668 if ((index + 1) > size)
00669 pFV->setPendingCurrentSize(index+1);
00670
00671 std::memcpy(&(pFV->pendingBuffer((char*) pFV)[index]), val, sizeof(T));
00672 this->registerModifiedField(pFV, context);
00673 }
00674
00675
00676
00677 template<typename T>
00678 class SettingFieldArray2D: public FieldArray2D<T> {
00679 public:
00685 SettingFieldArray2D(const std::string& fieldName, bool multiplexed,
00686 bool multiMultiplexed, DataStore* pDataStore, bool persistent, bool shared,
00687 int32_t size1, int32_t size2,
00688 const DataIntegrity bufferType = DoubleBuffered);
00689 ~SettingFieldArray2D();
00690
00698 const T** get(uint32_t& size1, uint32_t& size2,
00699 MultiplexingContext* context);
00700
00709 void getColumn(uint32_t index, uint32_t size, T* column, uint32_t& currentSize,
00710 MultiplexingContext* context);
00711
00719 const T* getRow(uint32_t index, uint32_t& size,
00720 MultiplexingContext* context);
00721
00729 void set(const T* const * val, uint32_t size1, uint32_t size2,
00730 MultiplexingContext* context);
00731
00739 void setColumn(const T* val, uint32_t index, uint32_t size,
00740 MultiplexingContext* context);
00741
00749 void setRow(const T* val, uint32_t index, uint32_t size,
00750 MultiplexingContext* context);
00751
00758 void getSize(uint32_t& size1, uint32_t& size2, MultiplexingContext* context);
00759
00760 protected:
00761
00762 void checkContext(MultiplexingContext* context);
00763 };
00764
00765 template<typename T>
00766 SettingFieldArray2D<T>::SettingFieldArray2D(const std::string& fieldName,
00767 bool multiplexed, bool multiMultiplexed, DataStore* pDataStore,
00768 bool isPersistent, bool shared, int32_t size1, int32_t size2,
00769 const DataIntegrity bufferType) :
00770 FieldArray2D<T> (fieldName, Setting, multiplexed, multiMultiplexed,
00771 isPersistent, bufferType, pDataStore, size1, size2) {
00772
00773 this->isShared_ = shared;
00774 }
00775
00776 template<typename T>
00777 SettingFieldArray2D<T>::~SettingFieldArray2D() {
00778
00779 }
00780
00781 template<typename T>
00782 const T** SettingFieldArray2D<T>::get(uint32_t& size1,
00783 uint32_t& size2, MultiplexingContext* context) {
00784
00785 if (context == NULL)
00786 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00787
00788 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00789 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00790 this->name_.c_str());
00791
00792 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00793 : this->multiplexingManager_->getSlot(*context);
00794 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
00795
00796 pFV->getActiveCurrentSize(size1, size2);
00797 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00798 {
00799
00800 return (const T**) (pFV->pendingBuffer((char*) pFV));
00801 }
00802 else
00803 {
00804
00805 return (const T**) (pFV->activeBuffer((char*) pFV));
00806 }
00807 }
00808
00809 template<typename T>
00810 void SettingFieldArray2D<T>::getColumn(uint32_t index,
00811 uint32_t size, T* column, uint32_t& currentSize, MultiplexingContext* context) {
00812
00813 if (context == NULL)
00814 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00815
00816 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00817 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00818 this->name_.c_str());
00819
00820 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00821 : this->multiplexingManager_->getSlot(*context);
00822 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
00823
00824 uint32_t size1, size2;
00825 pFV->getActiveCurrentSize(size1, size2);
00826 if ((index+1) > size2 || size < size1) {
00827 throw FesaException(__FILE__, __LINE__,
00828 FesaErrorFieldCurrentDimensionsOutOfBound.c_str(),
00829 StringUtilities::toString(index).c_str(),
00830 StringUtilities::toString(size).c_str(),
00831 this->name_.c_str(),
00832 StringUtilities::toString(size1).c_str(),
00833 StringUtilities::toString(size2).c_str());
00834 }
00835
00836 currentSize = size1;
00837 T(*activeVal)[size2];
00838 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00839 {
00840
00841 activeVal = (T(*)[size2]) pFV->pendingBuffer((char*) pFV);
00842 }
00843 else
00844 {
00845
00846 activeVal = (T(*)[size2]) pFV->activeBuffer((char*) pFV);
00847 }
00848 for (uint32_t i = 0; i < size1; i++) {
00849 column[i] = activeVal[i][index];
00850 }
00851 }
00852
00853 template<typename T>
00854 const T* SettingFieldArray2D<T>::getRow(uint32_t index,
00855 uint32_t& size, MultiplexingContext* context) {
00856
00857 if (context == NULL)
00858 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00859
00860 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00861 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00862 this->name_.c_str());
00863
00864 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00865 : this->multiplexingManager_->getSlot(*context);
00866 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
00867
00868
00869 uint32_t size1, size2;
00870 pFV->getActiveCurrentSize(size1, size2);
00871 if ((index+1) > size1) {
00872 throw FesaException(__FILE__, __LINE__,
00873 FesaErrorFieldCurrentDimensionOutOfBound.c_str(),
00874 StringUtilities::toString(index).c_str(), this->name_.c_str(),
00875 StringUtilities::toString(size1).c_str());
00876 }
00877
00878 size = size2;
00879 T(*activeVal)[size2];
00880 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
00881 {
00882
00883 activeVal = (T(*)[size2]) pFV->pendingBuffer((char*) pFV);
00884 }
00885 else
00886 {
00887
00888 activeVal = (T(*)[size2]) pFV->activeBuffer((char*) pFV);
00889 }
00890 return activeVal[index];
00891 }
00892
00893 template<typename T>
00894 void SettingFieldArray2D<T>::set(const T* const * val, uint32_t size1,
00895 uint32_t size2, MultiplexingContext* context) {
00896
00897 if (context == NULL)
00898 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00899
00900 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00901 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00902 this->name_.c_str());
00903 this->checkContext(context);
00904
00905 this->checkMaxDimensions(size1, size2);
00906
00907 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00908 : this->multiplexingManager_->requireSlot(*context);
00909 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
00910
00911 this->resetToBeSync(slot);
00912
00913
00914 pFV->setPendingCurrentSize(size1, size2);
00915 std::memcpy(pFV->pendingBuffer((char*) pFV), val, size1 * size2 * sizeof(T));
00916 this->registerModifiedField(pFV, context);
00917 }
00918
00919 template<typename T>
00920 void SettingFieldArray2D<T>::setColumn(const T* val, uint32_t index,
00921 uint32_t size, MultiplexingContext* context) {
00922
00923 if (context == NULL)
00924 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00925
00926 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00927 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00928 this->name_.c_str());
00929 this->checkContext(context);
00930
00931 this->checkMaxDimensions(size, index+1);
00932
00933 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00934 : this->multiplexingManager_->requireSlot(*context);
00935 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
00936
00937 this->resetToBeSync(slot);
00938 uint32_t size1=0, size2=0;
00939
00940 if (!pFV->hasPendingChanged()) {
00941 pFV->getActiveCurrentSize(size1, size2);
00942 pFV->setPendingCurrentSize(size1, size2);
00943 std::memcpy(pFV->pendingBuffer((char*) pFV), pFV->activeBuffer(
00944 (char*) pFV), size1 * size2
00945 * sizeof(T));
00946 }
00947
00948
00949
00950 pFV->getPendingCurrentSize(size1, size2);
00951 uint32_t newSize1 = (size > size1) ? size : size1;
00952 uint32_t newSize2 = ((index+1) > size2) ? (index+1) : size2;
00953 pFV->setPendingCurrentSize(newSize1, newSize2);
00954
00955 T(*pendingVal)[newSize2];
00956 pendingVal = (T(*)[newSize2]) pFV->pendingBuffer((char*) pFV);
00957 for (uint32_t i = 0; i < size; i++) {
00958 pendingVal[i][index] = val[i];
00959 }
00960 this->registerModifiedField(pFV, context);
00961 }
00962
00963 template<typename T>
00964 void SettingFieldArray2D<T>::setRow(const T* val, uint32_t index,
00965 uint32_t size, MultiplexingContext* context) {
00966
00967 if (context == NULL)
00968 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00969
00970 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
00971 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
00972 this->name_.c_str());
00973 this->checkContext(context);
00974
00975 this->checkMaxDimensions(index+1, size);
00976
00977 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00978 : this->multiplexingManager_->requireSlot(*context);
00979 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
00980
00981 this->resetToBeSync(slot);
00982 uint32_t size1=0, size2=0;
00983
00984 if (!pFV->hasPendingChanged()) {
00985 pFV->getActiveCurrentSize(size1, size2);
00986 pFV->setPendingCurrentSize(size1, size2);
00987 std::memcpy(pFV->pendingBuffer((char*) pFV), pFV->activeBuffer(
00988 (char*) pFV), size1 * size2
00989 * sizeof(T));
00990 }
00991
00992
00993
00994 pFV->getPendingCurrentSize(size1, size2);
00995 uint32_t newSize1 = ((index+1) > size1) ? (index+1) : size1;
00996 uint32_t newSize2 = ( size > size2) ? size : size2;
00997 pFV->setPendingCurrentSize(newSize1, newSize2);
00998
00999
01000 T(*pendingVal)[newSize2];
01001 pendingVal = (T(*)[newSize2]) pFV->pendingBuffer((char*) pFV);
01002 std::memcpy(pendingVal[index], val, size * sizeof(T));
01003 this->registerModifiedField(pFV, context);
01004 }
01005
01006 template<typename T>
01007 void SettingFieldArray2D<T>::getSize(uint32_t& size1, uint32_t& size2, MultiplexingContext* context) {
01008
01009 if (context == NULL)
01010 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
01011
01012 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
01013 : this->multiplexingManager_->requireSlot(*context);
01014 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
01015 pFV->getActiveCurrentSize(size1, size2);
01016 }
01017
01018 template<typename T>
01019 void SettingFieldArray2D<T>::checkContext(MultiplexingContext* context) {
01020
01021 if (context == NULL)
01022 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
01023
01024 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
01025 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
01026 this->name_.c_str());
01027
01028 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
01029 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
01030 this->name_.c_str());
01031 }
01032
01033
01034
01035 template<typename T>
01036 class SettingFieldScalarArray2D: public SettingFieldArray2D<T> {
01037 public:
01043 SettingFieldScalarArray2D(const std::string& fieldName,
01044 bool multiplexed, bool multiMultiplexed,
01045 DataStore* pDataStore, bool persistent, bool shared, int32_t size1, int32_t size2,
01046 const DataIntegrity bufferType = DoubleBuffered);
01047 ~SettingFieldScalarArray2D();
01048
01056 T getCell(uint32_t index1, uint32_t index2,
01057 MultiplexingContext* context = 0);
01058
01066 void setCell(T val, uint32_t index1, uint32_t index2,
01067 MultiplexingContext* context);
01068
01069 };
01070
01071 template<typename T>
01072 SettingFieldScalarArray2D<T>::SettingFieldScalarArray2D(
01073 const std::string& fieldName, bool multiplexed, bool multiMultiplexed,
01074 DataStore* pDataStore, bool isPersistent, bool shared, int32_t size1, int32_t size2,
01075 const DataIntegrity bufferType) :
01076 SettingFieldArray2D<T> (fieldName, multiplexed, multiMultiplexed,
01077 pDataStore, isPersistent, shared, size1, size2, bufferType) {
01078 }
01079
01080 template<typename T>
01081 SettingFieldScalarArray2D<T>::~SettingFieldScalarArray2D() {
01082
01083 }
01084
01085 template<typename T>
01086 T SettingFieldScalarArray2D<T>::getCell(uint32_t index1,
01087 uint32_t index2, MultiplexingContext* context) {
01088
01089 if (context == NULL)
01090 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
01091
01092 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
01093 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
01094 this->name_.c_str());
01095
01096 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
01097 : this->multiplexingManager_->getSlot(*context);
01098 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
01099
01100 uint32_t size1, size2;
01101 pFV->getActiveCurrentSize(size1, size2);
01102 if ( ((index1+1) > size1) || ((index2+1) > size2) ) {
01103 throw FesaException(__FILE__, __LINE__,
01104 FesaErrorFieldCurrentDimensionsOutOfBound.c_str(),
01105 StringUtilities::toString(index1).c_str(),
01106 StringUtilities::toString(index2).c_str(),
01107 this->name_.c_str(),
01108 StringUtilities::toString(size1).c_str(),
01109 StringUtilities::toString(size2).c_str());
01110 }
01111
01112 T(*activeVal)[size2];
01113 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
01114 {
01115
01116 activeVal = (T(*)[size2]) pFV->pendingBuffer((char*) pFV);
01117 }
01118 else
01119 {
01120
01121 activeVal = (T(*)[size2]) pFV->activeBuffer((char*) pFV);
01122 }
01123 return activeVal[index1][index2];
01124 }
01125
01126 template<typename T>
01127 void SettingFieldScalarArray2D<T>::setCell(T val, uint32_t index1,
01128 uint32_t index2, MultiplexingContext* context) {
01129
01130 if (context == NULL)
01131 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
01132
01133 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
01134 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
01135 this->name_.c_str());
01136 this->checkContext(context);
01137
01138 this->checkMaxDimensions((index1+1), (index2+1));
01139
01140 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
01141 : this->multiplexingManager_->requireSlot(*context);
01142 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
01143
01144 this->resetToBeSync(slot);
01145 uint32_t size1=0, size2=0;
01146
01147
01148 if (!pFV->hasPendingChanged()) {
01149 pFV->getActiveCurrentSize(size1, size2);
01150 pFV->setPendingCurrentSize(size1, size2);
01151 std::memcpy(pFV->pendingBuffer((char*) pFV), pFV->activeBuffer(
01152 (char*) pFV), size1 * size2
01153 * sizeof(T));
01154 }
01155
01156
01157 pFV->getPendingCurrentSize(size1, size2);
01158 uint32_t newSize1 = ((index1+1) > size1) ? (index1+1) : size1;
01159 uint32_t newSize2 = ((index2+1) > size2) ? (index2+1) : size2;
01160 pFV->setPendingCurrentSize(newSize1, newSize2);
01161
01162 T(*activeVal)[newSize2];
01163 activeVal = (T(*)[newSize2]) pFV->pendingBuffer((char*) pFV);
01164 activeVal[index1][index2] = val;
01165 this->registerModifiedField(pFV, context);
01166 }
01167
01168
01169
01170 template<typename T>
01171 class SettingFieldStructArray2D: public SettingFieldArray2D<T> {
01172 public:
01178 SettingFieldStructArray2D(const std::string& fieldName,
01179 bool multiplexed, bool multiMultiplexed,
01180 DataStore* pDataStore, bool persistent, bool shared, int32_t size1, int32_t size2,
01181 const DataIntegrity bufferType = DoubleBuffered);
01182 ~SettingFieldStructArray2D();
01183
01191 const T* getCell(uint32_t index1, uint32_t index2,
01192 MultiplexingContext* context = 0);
01193
01201 void setCell(T* val, uint32_t index1, uint32_t index2,
01202 MultiplexingContext* context);
01203
01204 };
01205
01206 template<typename T>
01207 SettingFieldStructArray2D<T>::SettingFieldStructArray2D(
01208 const std::string& fieldName, bool multiplexed, bool multiMultiplexed,
01209 DataStore* pDataStore, bool isPersistent, bool shared, int32_t size1, int32_t size2,
01210 const DataIntegrity bufferType) :
01211 SettingFieldArray2D<T> (fieldName, multiplexed, multiMultiplexed,
01212 pDataStore, isPersistent, shared, size1, size2, bufferType) {
01213 this->isPersistent_ = isPersistent;
01214 }
01215
01216 template<typename T>
01217 SettingFieldStructArray2D<T>::~SettingFieldStructArray2D() {
01218
01219 }
01220
01221 template<typename T>
01222 const T* SettingFieldStructArray2D<T>::getCell(uint32_t index1,
01223 uint32_t index2, MultiplexingContext* context) {
01224
01225 if (context == NULL)
01226 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
01227
01228 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
01229 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
01230 this->name_.c_str());
01231
01232 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
01233 : this->multiplexingManager_->getSlot(*context);
01234 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
01235
01236 uint32_t size1, size2;
01237 pFV->getActiveCurrentSize(size1, size2);
01238 if ( ((index1+1) > size1) || ((index2+1) > size2) ) {
01239 throw FesaException(__FILE__, __LINE__,
01240 FesaErrorFieldCurrentDimensionsOutOfBound.c_str(),
01241 StringUtilities::toString(index1).c_str(),
01242 StringUtilities::toString(index2).c_str(),
01243 this->name_.c_str(),
01244 StringUtilities::toString(size1).c_str(),
01245 StringUtilities::toString(size2).c_str());
01246 }
01247
01248 T(*activeVal)[size2];
01249 if ((context->getSettingAccessMask() & MultiplexingContext::CHECK_FLAG_TO_BE_SYNC) && pFV->isToBeSync())
01250 {
01251
01252 activeVal = (T(*)[size2]) pFV->pendingBuffer((char*) pFV);
01253 }
01254 else
01255 {
01256
01257 activeVal = (T(*)[size2]) pFV->activeBuffer((char*) pFV);
01258 }
01259 return &(activeVal[index1][index2]);
01260 }
01261
01262 template<typename T>
01263 void SettingFieldStructArray2D<T>::setCell(T* val, uint32_t index1,
01264 uint32_t index2, MultiplexingContext* context) {
01265
01266 if (context == NULL)
01267 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
01268
01269 if (!(context->getSettingAccessMask() & MultiplexingContext::SET_ALLOWED))
01270 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextSettingField.c_str(),
01271 this->name_.c_str());
01272 this->checkContext(context);
01273
01274 this->checkMaxDimensions((index1+1), (index2+1));
01275
01276 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
01277 : this->multiplexingManager_->requireSlot(*context);
01278 FieldValue<T[][1]>* pFV = this->getFieldValue(slot);
01279
01280 this->resetToBeSync(slot);
01281 uint32_t size1=0, size2=0;
01282
01283 if (!pFV->hasPendingChanged()) {
01284 pFV->getActiveCurrentSize(size1, size2);
01285 pFV->setPendingCurrentSize(size1, size2);
01286 std::memcpy(pFV->pendingBuffer((char*) pFV), pFV->activeBuffer(
01287 (char*) pFV), size1 * size2
01288 * sizeof(T));
01289 }
01290
01291
01292 pFV->getPendingCurrentSize(size1, size2);
01293 uint32_t newSize1 = ((index1+1) > size1) ? (index1+1) : size1;
01294 uint32_t newSize2 = ((index2+1) > size2) ? (index2+1) : size2;
01295 pFV->setPendingCurrentSize(newSize1, newSize2);
01296 T(*pendingVal)[newSize2];
01297 pendingVal = (T(*)[newSize2]) pFV->pendingBuffer((char*) pFV);
01298 std::memcpy(&(pendingVal[index1][index2]), val, sizeof(T));
01299 this->registerModifiedField(pFV, context);
01300 }
01301
01302
01303
01304 class SettingFieldString: public FieldString {
01305 public:
01310 SettingFieldString(const std::string& fieldName, bool multiplexed,
01311 bool multiMultiplexed, DataStore* pDataStore, bool persistent, bool shared, int32_t size,
01312
01313 const DataIntegrity bufferType = DoubleBuffered);
01314
01318 ~SettingFieldString();
01319
01325 const char* get(MultiplexingContext* context);
01326
01332 void set(const char* val, MultiplexingContext* context);
01333 };
01334
01335
01336
01337 class SettingFieldStringArray: public FieldStringArray {
01338 public:
01343 SettingFieldStringArray(const std::string& fieldName,
01344 bool multiplexed, bool multiMultiplexed,
01345 DataStore* pDataStore, bool persistent, bool shared, int32_t size1, int32_t size2,
01346 const DataIntegrity bufferType = DoubleBuffered);
01347
01348 ~SettingFieldStringArray();
01349
01355 const char** get(uint32_t& size1, MultiplexingContext* context);
01356
01362 const char** get(uint32_t& size1, uint32_t& size2,
01363 MultiplexingContext* context);
01364
01371 const char* getString(uint32_t index, MultiplexingContext* context);
01372
01378 void set(const char** val, uint32_t size1,
01379 MultiplexingContext* context);
01380
01387 void setString(const char* val, uint32_t index,
01388 MultiplexingContext* context);
01389 };
01390
01391
01392
01393 }
01394
01395 #endif // SETTING_FIELD_H_