00001
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
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
00033 if (context == NULL)
00034 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00035
00036 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00037 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00038 this->name_.c_str());
00039
00040 if (!(context->getAcquisitionAccessMask() & MultiplexingContext::SET_ALLOWED))
00041 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextAcquisitionField.c_str(),
00042 this->name_.c_str());
00043
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
00052 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00053 : this->multiplexingManager_->requireSlot(*context);
00054 FieldValue<char[]>* pFV = this->getFieldValue(slot);
00055
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
00073 if (context == NULL)
00074 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00075
00076 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00077 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00078 this->name_.c_str());
00079
00080 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00081 : this->multiplexingManager_->getSlot(*context);
00082 FieldValue<char*[]>* pFV = this->getFieldValue(slot);
00083
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
00092 if (context == NULL)
00093 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00094
00095 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00096 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00097 this->name_.c_str());
00098
00099 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00100 : this->multiplexingManager_->getSlot(*context);
00101 FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00102
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
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
00117 if (context == NULL)
00118 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00119
00120 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00121 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00122 this->name_.c_str());
00123
00124 if (!(context->getAcquisitionAccessMask() & MultiplexingContext::SET_ALLOWED))
00125 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextAcquisitionField.c_str(),
00126 this->name_.c_str());
00127
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
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
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
00157 if (context == NULL)
00158 throw FesaException(__FILE__, __LINE__, FesaErrorNULLPointerToContext.c_str());
00159
00160 if (this->multiplexingManager_ && context->getType() == MultiplexingContext::NoneCtxt)
00161 throw FesaException(__FILE__, __LINE__, FesaErrorNoneContextforMuxedField.c_str(),
00162 this->name_.c_str());
00163
00164 if (!(context->getAcquisitionAccessMask() & MultiplexingContext::SET_ALLOWED))
00165 throw FesaException(__FILE__, __LINE__, FesaErrorWrongSourceContextAcquisitionField.c_str(),
00166 this->name_.c_str());
00167
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
00179 uint32_t slot = (this->multiplexingManager_ == NULL) ? 0
00180 : this->multiplexingManager_->requireSlot(*context);
00181 FieldValue<char *[]>* pFV = this->getFieldValue(slot);
00182
00183 uint32_t size = pFV->getPendingCurrentSize();
00184 if ((index + 1) > size)
00185 pFV->setPendingCurrentSize(index+1);
00186
00187 std::memcpy(pointers_[slot][pFV->pendingBuffer()][index], val, (length+1)
00188 * sizeof(char));
00189 }
00190
00191 }