ConverterFaultField.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #ifndef CONVERTER_FAULT_FIELD_H_
00004 #define CONVERTER_FAULT_FIELD_H_
00005 
00006 #include <fesa-core/DataStore/Converter.h>
00007 #include <fesa-core/DataStore/TypeDefinition.h>
00008 #include <fesa-core/Utilities/StringUtilities.h>
00009 
00010 #include <string>
00011 #include <vector>
00012 
00013 namespace fesa
00014 {
00015 
00021 template<>
00022 class Converter<FaultField_DataType>
00023 {
00024   public:
00030     static void valueToString(FaultField_DataType& value, std::string& str);
00031 
00037     static void stringToValue(const std::string& value, FaultField_DataType* pVal);
00038 
00039 };
00040 
00041 inline void Converter<FaultField_DataType>::valueToString(FaultField_DataType& value,std::string& str)
00042 {
00043     str = "{";
00044     std::string strStruct;
00045     // add element state_
00046     {
00047         Converter<bool> converter;
00048         converter.valueToString(value.state_,strStruct);
00049     }
00050     str = str + strStruct;
00051     str += ",";
00052 
00053     // add element timestamp_
00054     {
00055         Converter<int64_t> converter;
00056         converter.valueToString(value.timestamp_,strStruct);
00057     }
00058     str = str + strStruct;
00059     str += ",";
00060 
00061     // add element errorCode_
00062     {
00063         Converter<int32_t> converter;
00064         converter.valueToString(value.errorCode_,strStruct);
00065     }
00066     str = str + strStruct;
00067     str += "}";
00068 
00069 }
00070 
00071 inline void Converter<FaultField_DataType>::stringToValue(const std::string& value, FaultField_DataType* pVal)
00072 {
00073 
00074     std::string str;
00075     std::memset(pVal, 0, sizeof(FaultField_DataType));
00076     std::string temp = value.substr(1, value.length() - 2);
00077     std::vector<std::string> elements;
00078     fesa::StringUtilities::getElements(temp, elements);
00079     int32_t element = 0;
00080 
00081     // element state_
00082     {
00083         {
00084             Converter<bool> converter;
00085             converter.stringToValue(elements.at(element), &(pVal->state_));
00086         }
00087         element++;
00088     }
00089 
00090     // element timestamp_
00091     {
00092         {
00093             Converter<int64_t> converter;
00094             converter.stringToValue(elements.at(element), &(pVal->timestamp_));
00095         }
00096         element++;
00097     }
00098 
00099     // element errorCode_
00100     {
00101         {
00102             Converter<int32_t> converter;
00103             converter.stringToValue(elements.at(element), &(pVal->errorCode_));
00104         }
00105     }
00106 
00107 }
00108 
00109 } // fesa
00110 
00111 #endif // CONVERTER_FAULT_FIELD_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1