00001
00005 #ifndef FBwlex_castHH
00006 #define FBwlex_castHH 1
00007
00008 #include <FBwConfig.h>
00009 #include <sstream>
00010 #include <typeinfo>
00011
00012 namespace fbwrap
00013 {
00014
00016 class bad_lexical_cast : public std::bad_cast
00017 {
00018 public:
00019
00020
00021 virtual const char * what() const throw()
00022 {
00023 return "bad lexical cast: "
00024 "source type value could not be interpreted as target";
00025 }
00026 };
00027 template <typename Target, typename Source>
00028 Target lexical_cast(const Source arg)
00029 {
00030 std::stringstream interp;
00031 Target result;
00032 if(!(interp << arg) || !(interp >> result) )
00033 throw bad_lexical_cast();
00034 return result;
00035 }
00036
00037
00038
00039
00040 }
00041 #endif