ConverterLogicalHardwareAddress.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #ifndef CONVERTER_LOGICAL_HARDWARE_ADDRESS_H_
00004 #define CONVERTER_LOGICAL_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 CH = "ch";
00019 const std::string LUN = "lun";
00020 const std::string TYPE = "type";
00021 
00027 template<>
00028 class Converter<LogicalHardwareAddress_DataType>
00029 {
00030   public:
00036     static void valueToString(LogicalHardwareAddress_DataType& value, std::string& str);
00037 
00043     static void stringToValue(const std::string& value, LogicalHardwareAddress_DataType* pVal);
00044 
00045 };
00046 
00047 inline void Converter<LogicalHardwareAddress_DataType>::valueToString(LogicalHardwareAddress_DataType& value,std::string& str)
00048 {
00049     std::stringstream ss;
00050 
00051     ss << CH << "=\"" << value.ch_ << "\" " << LUN << "=\"" << value.lun_ << "\" " << TYPE << "=\""
00052        << value.moduleType_ << "\"";
00053 
00054     str = ss.str();
00055 
00056 }
00057 
00058 inline void Converter<LogicalHardwareAddress_DataType>::stringToValue(const std::string& value,
00059                                                                       LogicalHardwareAddress_DataType* pVal)
00060 {
00061 
00062     std::vector<std::string> v;
00063     fesa::StringUtilities::tokenize(value, v);
00064 
00065     for (uint32_t i = 0; i < v.size(); i++)
00066     {
00067         std::size_t position = v[i].find(CH);
00068         if (position != std::string::npos)
00069         {
00070             std::string temp = v[i].substr(position + CH.length() + 1);
00071             // remove the quotes
00072             temp = temp.substr(1, temp.length() - 2);
00073             pVal->ch_ = atoi(temp.c_str());
00074 
00075         }
00076 
00077         position = v[i].find(LUN);
00078 
00079         if (position != std::string::npos)
00080         {
00081             std::string temp = v[i].substr(position + LUN.length() + 1);
00082             // remove the quotes
00083             temp = temp.substr(1, temp.length() - 2);
00084             pVal->lun_ = atoi(temp.c_str());
00085 
00086         }
00087 
00088         position = v[i].find(TYPE);
00089 
00090         if (position != std::string::npos)
00091         {
00092             std::string temp = v[i].substr(position + TYPE.length() + 1);
00093             // remove the quotes
00094             temp = temp.substr(1, temp.length() - 2);
00095             std::strcpy(pVal->moduleType_, temp.c_str());
00096 
00097         }
00098 
00099     }
00100 
00101 }
00102 
00103 } // fesa
00104 
00105 #endif // CONVERTER_LOGICAL_HARDWARE_ADDRESS_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1