FieldString.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/DataStore/FieldString.h>
00004 
00005 #include <fesa-core/Synchronization/AbstractMultiplexingManager.h>
00006 #include <fesa-core/Utilities/ParserElements.h>
00007 #include <fesa-core/Exception/FesaException.h>
00008 
00009 #include <cstring>
00010 
00011 
00012 namespace fesa
00013 {
00014 
00015 FieldString::FieldString(const std::string& fieldName, const FieldCategory fieldCategory, bool multiplexed,
00016                          bool multiMultiplexed, bool persistent, DataIntegrity bufferType, DataStore* pDataStore, int32_t size) :
00017     AbstractField(fieldName, fieldCategory, multiplexed, multiMultiplexed, persistent,bufferType, pDataStore), maxSize_(size)
00018 
00019 {
00020 
00021 }
00022 
00023 FieldString::~FieldString()
00024 {
00025 }
00026 
00027 
00028 inline FieldValue<char[]>* FieldString::getFieldValue(int32_t slot)
00029 {
00030 
00031     char* address = (char*) this->fieldValue_;
00032     address += valueSize_ * slot;
00033     return (FieldValue<char[]>*) address;
00034 
00035 }
00036 
00037 void FieldString::setFieldValueAddress(char* pFV, bool initFieldsFlag)
00038 {
00039     int32_t depth = 1;
00040 
00041     if (this->multiplexingManager_ != NULL)
00042     {
00043         depth = this->multiplexingManager_->getDepth();
00044     }
00045 
00046 
00047 
00048     this->fieldValue_ = (FieldValue<char[]>*) pFV;
00049 
00050     if (initFieldsFlag)
00051     {
00052         for (int32_t i = 0; i < depth; i++)
00053         {
00054             FieldValue<char[]>* temp = new (pFV) FieldValue<char[]> (buffer_, maxSize_);
00055             if (!temp)
00056             {
00057                 throw FesaException(__FILE__, __LINE__, FesaErrorSettingFieldValueAddress.c_str(), name_.c_str());
00058             }
00059             pFV += this->valueSize_;
00060         }
00061     }
00062 
00063 }
00064 
00065 
00066 void FieldString::initialize(FieldElement& fieldElement)
00067 {
00068     if (fieldElement.dimension1_ > 0)
00069     {
00070         this->maxSize_ = fieldElement.dimension1_;
00071 
00072     }
00073 
00074 }
00075 
00076 uint32_t FieldString::getFieldValueSize()
00077 {
00078 
00079     if (valueSize_ == 0)
00080     {
00081         valueSize_ = static_cast<uint32_t>(sizeof(FieldValue<char[]>)) + static_cast<uint32_t>(sizeof(char)) * (this->maxSize_ + 1) * buffer_; // add +1 for the symbol '\0' at the end of the string
00082     }
00083     return valueSize_;
00084 }
00085 
00086 void FieldString::copyValue(uint32_t slot, std::string& str)
00087 {
00088     int32_t currentSize = str.size() < this->maxSize_ ? static_cast<uint32_t>(str.size()) : this->maxSize_;
00089 
00090 
00091     FieldValue<char[]>* pFV = this->getFieldValue(slot);
00092     //            pFV->setActiveCurrentSize(currentSize);
00093 
00094     std::memcpy(pFV->activeBuffer((char*)pFV), str.c_str(), currentSize * sizeof(char));
00095     pFV->activeBuffer((char*)pFV)[currentSize] = '\0';
00096     std::memcpy(pFV->pendingBuffer((char*)pFV), str.c_str(), currentSize * sizeof(char));
00097     pFV->pendingBuffer((char*)pFV)[currentSize] = '\0';
00098 
00099 }
00100 
00101 void FieldString::getValueToStore(int32_t slot,std::string& str)
00102 {
00103 
00104     FieldValue<char[]>* pFV = this->getFieldValue(slot);
00105 
00106     if (pFV->hasPendingChanged() || pFV->isToBeSync())
00107     {
00108         str = pFV->pendingBuffer((char*)pFV);
00109     }
00110     else
00111     {
00112         str = pFV->activeBuffer((char*)pFV);
00113     }
00114 
00115 }
00116 
00117 uint32_t FieldString::getMaxSize()
00118 {
00119     return this->maxSize_;
00120 }
00121 
00122 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1