![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 #ifndef WNS_CONVERSION_HPP 00002 #define WNS_CONVERSION_HPP 00003 00004 #include <string> 00005 #include <sstream> 00006 #include <boost/type_traits/is_pod.hpp> 00007 00008 namespace wns 00009 { 00010 00011 template <typename TO, typename FROM, bool POD> 00012 class Converter 00013 { 00014 public: 00015 TO 00016 operator ()(const FROM& from) 00017 { 00018 return from.template to<TO>(); 00019 } 00020 }; 00021 00022 template<typename FROM> 00023 class Converter<std::string, FROM, true> 00024 { 00025 public: 00026 std::string 00027 operator ()(FROM from) 00028 { 00029 std::stringstream ss; 00030 ss << from; 00031 return ss.str(); 00032 } 00033 }; 00034 00035 template<typename TO, typename FROM> 00036 TO 00037 to(const FROM& from) 00038 { 00039 Converter<TO, FROM, boost::is_pod<FROM>::value> converter; 00040 return converter(from); 00041 } 00042 } 00043 00044 #endif // NOT defined WNS_CONVERSION_HPP
1.5.5