Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

FBwlex_cast.h

Go to the documentation of this file.
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 // constructors, destructors, and assignment operator defaulted
00020 // function inlined for brevity and consistency with rest of library
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 // namespace end
00039 
00040 }
00041 #endif 

Generated on Fri Jan 31 08:30:01 2003 for fbwrap by doxygen1.2.17