Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

StreamParser.hpp

Go to the documentation of this file.
00001 #ifndef StreamParser_HPP
00002 #define StreamParser_HPP
00003 
00004 // This code was taken from here:
00005 // http://www.parashift.com/c++-faq-lite/misc-technical-issues.html
00006 
00007 #include <stdexcept>
00008 #include <sstream>
00009 
00013 class BadConversion : public std::runtime_error {
00014  public:
00015    BadConversion(const std::string& s)
00016      : std::runtime_error(s) { }
00017  };
00018  
00019  template<typename T>
00020  inline void convert(const std::string& s, T& x,
00021                      bool failIfLeftoverChars = true)
00022  {
00023    std::istringstream i(s);
00024    char c;
00025    if (!(i >> x) || (failIfLeftoverChars && i.get(c)))
00026      throw BadConversion(s);
00027  }
00028 
00029 #endif

Generated on Sun Sep 17 17:50:40 2006 for FIM environment by  doxygen 1.4.4