AcquisitionField.cpp

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

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1