ConverterDeviceRelations.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #ifndef CONVERTER_DEVICE_RELATIONS_H_
00004 #define CONVERTER_DEVICE_RELATIONS_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 <cstring>
00012 #include <vector>
00013 #include <sstream>
00014 
00015 namespace fesa
00016 {
00017 
00018 const std::string DEVICE = "device";
00019 const std::string PROPERTY = "property";
00020 
00026 template<>
00027 class Converter<DeviceRelation_DataType>
00028 {
00029   public:
00035     static void valueToString(DeviceRelation_DataType& value,std::string& str);
00036 
00042     static void stringToValue(const std::string& value, DeviceRelation_DataType* pVal);
00043 
00044 };
00045 
00046 inline void Converter<DeviceRelation_DataType>::valueToString(DeviceRelation_DataType& value, std::string& str)
00047 {
00048 
00049     std::stringstream ss;
00050 
00051     ss << "device=" << value.device_ << " " << "property=" << value.property_;
00052     str = ss.str();
00053 
00054 }
00055 
00056 inline void Converter<DeviceRelation_DataType>::stringToValue(const std::string& value, DeviceRelation_DataType* pVal)
00057 {
00058 
00059     std::vector<std::string> v;
00060     fesa::StringUtilities::tokenize(value, v);
00061 
00062     for (uint32_t i = 0; i < v.size(); i++)
00063     {
00064         std::size_t position = v[i].find(DEVICE);
00065         if (position != std::string::npos)
00066         {
00067             std::string temp = v[i].substr(position + DEVICE.length() + 1);
00068             std::strcpy(pVal->device_, temp.c_str());
00069 
00070         }
00071 
00072         position = v[i].find(PROPERTY);
00073 
00074         if (position != std::string::npos)
00075         {
00076             std::string temp = v[i].substr(position + PROPERTY.length() + 1);
00077             std::strcpy(pVal->property_, temp.c_str());
00078 
00079         }
00080     }
00081 
00082 }
00083 
00084 } // fesa
00085 
00086 #endif // CONVERTER_DEVICE_RELATIONS_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1