ConverterBool.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #ifndef CONVERTER_BOOL_H_
00004 #define CONVERTER_BOOL_H_
00005 
00006 #include <fesa-core/DataStore/Converter.h>
00007 #include <fesa-core/Exception/FesaException.h>
00008 
00009 #include <string>
00010 
00011 namespace fesa
00012 {
00013 
00019 template<>
00020 class Converter<bool>
00021 {
00022   public:
00028     static void valueToString(bool value,std::string& str);
00029 
00035     static void stringToValue(const std::string& value, bool* pVal);
00036 
00037 };
00038 
00039 inline void Converter<bool>::valueToString(bool value,std::string& str)
00040 {
00041     if (value == true)
00042     {
00043         str = "true";
00044     }
00045     else
00046     {
00047         str = "false";
00048     }
00049 }
00050 
00051 inline void Converter<bool>::stringToValue(const std::string& value, bool* pVal)
00052 {
00053     if (!value.compare("false") || !value.compare("0"))
00054     {
00055         *pVal = false;
00056     }
00057     else if (!value.compare("true") || !value.compare("1"))
00058     {
00059         *pVal = true;
00060     }
00061     else
00062     {
00063         throw FesaException(__FILE__, __LINE__, FesaErrorWrongBooleanValue.c_str(), value.c_str());
00064     }
00065 }
00066 
00067 } // fesa
00068 
00069 #endif // CONVERTER_BOOL_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1