GenericField.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/DataStore/GenericField.h>
00004 
00005 namespace fesa
00006 {
00007 
00008 GenericFieldString::GenericFieldString(const std::string& fieldName, bool multiplexed, DataStore* pDataStore,
00009                                        bool persistent, int32_t size, DataIntegrity bufferType) :
00010     FieldString (fieldName, Generic, multiplexed, false, persistent, bufferType, pDataStore, size)
00011 {
00012 }
00013 
00014 GenericFieldString::~GenericFieldString() {
00015 
00016 }
00017 
00018 const char* GenericFieldString::get(MultiplexingContext* context) {
00019     // throw exception in case of NULL pointer
00020     if (context == NULL)
00021         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00022     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00023         : this->multiplexingManager_->getSlot(*context);
00024     FieldValue<char[]>* pFV = this->getFieldValue(slot);
00025     return (const char*) pFV->activeBuffer((char*) pFV);
00026 }
00027 
00028 void GenericFieldString::set(const char* val,
00029                              MultiplexingContext* context) {
00030     // throw exception in case of NULL pointer
00031     if (context == NULL)
00032         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00033     // throw exception in case of NoneContext and multiplexed field.
00034     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00035         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00036                             this->name_.c_str());
00037     // Check against Max dimensions. Exception is thrown in case of out of bound
00038     uint32_t length = static_cast<uint32_t>(strlen(val));
00039     if (length > this->maxSize_) {
00040         throw FesaException(__FILE__, __LINE__,
00041                             FesaErrorFieldMaxDimensionOutOfBound.c_str(),
00042                             StringUtilities::toString(length).c_str(), this->name_.c_str(),
00043                             StringUtilities::toString(maxSize_).c_str());
00044     }
00045     // Retrieve the right FieldValue according to the slot
00046     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00047         : this->multiplexingManager_->requireSlot(*context);
00048     FieldValue<char[]>* pFV = this->getFieldValue(slot);
00049     // Set the pending buffer
00050     std::memcpy(pFV->pendingBuffer((char*) pFV), val, (length+1) * sizeof(char));
00051 }
00052 
00053 GenericFieldStringArray::GenericFieldStringArray(const std::string& fieldName,
00054                                                  bool multiplexed, DataStore* pDataStore, bool persistent,
00055                                                  int32_t size1, int32_t size2, DataIntegrity bufferType) :
00056     FieldStringArray(fieldName, Generic, multiplexed, false, persistent,
00057                      bufferType, pDataStore, size1, size2) {
00058 }
00059 
00060 GenericFieldStringArray::~GenericFieldStringArray() {
00061 
00062 }
00063 
00064 const char** GenericFieldStringArray::get(uint32_t& size,
00065                                           MultiplexingContext* context) {
00066     // throw exception in case of NULL pointer
00067     if (context == NULL)
00068         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00069     // throw exception in case of NoneContext and multiplexed field.
00070     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00071         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00072                             this->name_.c_str());
00073     // Retrieve the right FieldValue according to the slot
00074     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00075         : this->multiplexingManager_->getSlot(*context);
00076     FieldValue<char*[]>* pFV = this->getFieldValue(slot);
00077     // Return the current size get from the Active buffer
00078     size = pFV->getActiveCurrentSize();
00079     return (const char**) pointers_[slot][pFV->activeBuffer()];
00080 
00081 }
00082 
00083 const char* GenericFieldStringArray::getString(uint32_t index,
00084                                                MultiplexingContext* context) {
00085     // throw exception in case of NULL pointer
00086     if (context == NULL)
00087         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00088     // throw exception in case of NoneContext and multiplexed field.
00089     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00090         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00091                             this->name_.c_str());
00092     // Retrieve the right FieldValue according to the slot
00093     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00094         : this->multiplexingManager_->getSlot(*context);
00095     FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00096     // Check against dynamic dimensions. Exception is thrown in case of out of bound
00097     uint32_t size = pFV->getActiveCurrentSize();
00098     if ((index+1) > size) {
00099         throw FesaException(__FILE__, __LINE__,
00100                             FesaErrorFieldCurrentDimensionOutOfBound.c_str(),
00101                             StringUtilities::toString(index).c_str(), this->name_.c_str(),
00102                             StringUtilities::toString(size).c_str());
00103     }
00104     // Return the value from the Active buffer
00105     return (const char*) pointers_[slot][pFV->activeBuffer()][index];
00106 }
00107 
00108 void GenericFieldStringArray::set(const char ** val, uint32_t size1,
00109                                   MultiplexingContext* context) {
00110     // throw exception in case of NULL pointer
00111     if (context == NULL)
00112         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00113     // throw exception in case of NoneContext and multiplexed field.
00114     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00115         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00116                             this->name_.c_str());
00117     // Check against Max dimensions. Exception is thrown in case of out of bound
00118     uint32_t maxLength = 0;
00119     for (uint32_t i = 0; i < size1; i++) {
00120         maxLength = (strlen(val[i])>maxLength) ? static_cast<uint32_t>(strlen(val[i])) : maxLength;
00121     }
00122     if ((size1) > maxSize1_ || maxLength > maxSize2_) {
00123         throw FesaException(__FILE__, __LINE__,
00124                             FesaErrorFieldMaxDimensionsOutOfBound.c_str(),
00125                             StringUtilities::toString(size1).c_str(),
00126                             StringUtilities::toString(maxLength).c_str(),
00127                             this->name_.c_str(),
00128                             StringUtilities::toString(maxSize1_).c_str(),
00129                             StringUtilities::toString(maxSize2_).c_str());
00130     }
00131     // Retrieve the right FieldValue according to the slot
00132     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00133         : this->multiplexingManager_->requireSlot(*context);
00134     FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00135     pFV->setPendingCurrentSize(size1);
00136     for (uint32_t i = 0; i < size1; i++) {
00137         uint32_t length = static_cast<uint32_t>(strlen(val[i]));
00138         // copy the string including the null character(length+1)
00139         std::memcpy(pointers_[slot][pFV->pendingBuffer()][i], val[i],
00140                (length+1) * sizeof(char));
00141     }
00142 }
00143 
00144 void GenericFieldStringArray::setString(const char* val,
00145                                         uint32_t index, MultiplexingContext* context) {
00146     // throw exception in case of NULL pointer
00147     if (context == NULL)
00148         throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00149     // throw exception in case of NoneContext and multiplexed field.
00150     if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00151         throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00152                             this->name_.c_str());
00153     // Check against Max dimensions. Exception is thrown in case of out of bound
00154     uint32_t length = static_cast<uint32_t>(strlen(val));
00155     if ((index+1) > maxSize1_ || length > maxSize2_) {
00156         throw FesaException(__FILE__, __LINE__,
00157                             FesaErrorFieldMaxDimensionsOutOfBound.c_str(),
00158                             StringUtilities::toString(index+1).c_str(),
00159                             StringUtilities::toString(length).c_str(),
00160                             this->name_.c_str(),
00161                             StringUtilities::toString(maxSize1_).c_str(),
00162                             StringUtilities::toString(maxSize2_).c_str());
00163     }
00164     // Retrieve the right FieldValue according to the slot
00165     uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00166         : this->multiplexingManager_->requireSlot(*context);
00167     FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00168     // Adjust the dynamic dimension if it's required
00169     uint32_t size = pFV->getPendingCurrentSize();
00170     if ((index + 1) > size)
00171         pFV->setPendingCurrentSize(index+1);
00172     // Set the new string in the pending buffer
00173     std::memcpy(pointers_[slot][pFV->pendingBuffer()][index], val, (length+1)
00174            * sizeof(char));
00175 }
00176 
00177 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1