Xstring.h

Go to the documentation of this file.
00001 #ifndef XSTRING_H
00002 #define XSTRING_H
00003 
00004 #include <sstream>
00005 #include <string>
00006 
00007 template<class T>   class XString{
00008 
00009 public: 
00010         
00011         static  T convertFromString(const std::string& s)
00012         {
00013                 std::istringstream in(s);
00014                 T x;
00015                 if (in >> x)
00016                         return x;
00017                 // some sort of error handling goes here...
00018                 return 0;
00019                 /* Exemple:
00020                 Tango::DevShort attr_gain_write = XString<Tango::DevShort>::convertFromString(mem_value);
00021                 */
00022         } 
00023 //
00024         static  std::string convertToString(const T & t)
00025         {
00026                 std::ostringstream out ;
00027                 
00028                 if (out << std::fixed << t   )
00029                         return out.str();
00030                 // some sort of error handling goes here...
00031                 return 0;
00032                 /* Exemple:
00033                 string frequence = XString<Tango::DevDouble>::convertToString(attr_frequency_write);
00034                 */
00035         } 
00036 
00037 };
00038 #endif

Generated on Fri Jul 10 10:31:56 2009 for Utils Library by  doxygen 1.4.5