ConverterPortHostHardwareAddress.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #ifndef CONVERTER_PORT_HOST_HARDWARE_ADDRESS_H_
00004 #define CONVERTER_PORT_HOST_HARDWARE_ADDRESS_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 PORT = "port-number";
00019 const std::string HOST = "value";
00020 
00026 template<>
00027 class Converter<HostPortHardwareAddress_DataType>
00028 {
00029   public:
00035     static void valueToString(HostPortHardwareAddress_DataType& value,std::string& str);
00036 
00042     static void stringToValue(const std::string& value, HostPortHardwareAddress_DataType* pVal);
00043 
00044 };
00045 
00046 inline void Converter<HostPortHardwareAddress_DataType>::valueToString(
00047     HostPortHardwareAddress_DataType& value,std::string& str)
00048 {
00049     std::stringstream ss;
00050 
00051     ss << PORT << "=\"" << value.port_ << "\" " << HOST << "=\"" << value.host_ << "\"";
00052 
00053     str = ss.str();
00054 }
00055 
00056 inline void Converter<HostPortHardwareAddress_DataType>::stringToValue(const std::string& value,
00057                                                                        HostPortHardwareAddress_DataType* pVal)
00058 {
00059 
00060     std::vector<std::string> v;
00061     fesa::StringUtilities::tokenize(value, v);
00062 
00063     for (uint32_t i = 0; i < v.size(); i++)
00064     {
00065         std::size_t position = v[i].find(PORT);
00066         if (position != std::string::npos)
00067         {
00068             std::string temp = v[i].substr(position + PORT.length() + 1);
00069             // remove the quotes
00070             temp = temp.substr(1, temp.length() - 2);
00071             pVal->port_ = atoi(temp.c_str());
00072 
00073         }
00074 
00075         position = v[i].find(HOST);
00076 
00077         if (position != std::string::npos)
00078         {
00079             std::string temp = v[i].substr(position + HOST.length() + 1);
00080             // remove the quotes
00081             temp = temp.substr(1, temp.length() - 2);
00082             std::strcpy(pVal->host_, temp.c_str());
00083 
00084         }
00085 
00086     }
00087 
00088 }
00089 
00090 } // fesa
00091 
00092 #endif // CONVERTER_PORT_HOST_HARDWARE_ADDRESS_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1