from_string.h

00001 #ifndef gridripper_util_from_string_h
00002 #define gridripper_util_from_string_h
00003 
00004 #include <sstream>
00005 #include <iostream>
00006 
00007 namespace gridripper {
00008 
00009 using namespace std;
00010 
00018 template <class T>
00019 static bool from_string(T& t, const string& s, ios_base& (*f)(ios_base&))
00020 {
00021     istringstream iss(s);
00022     if((iss >> f >> t).fail()) {
00023         return false;
00024     }
00025     string remains;
00026     iss >> remains;
00027     return remains.length() == 0;
00028 }
00029 
00030 template <class T>
00031 static bool from_string(T& t, const string& s)
00032 {
00033     istringstream iss(s);
00034     if((iss >> t).fail()) {
00035         return false;
00036     }
00037     string remains;
00038     iss >> remains;
00039     return remains.length() == 0;
00040 }
00041 
00042 } // namespace gridripper
00043 
00044 #endif /* gridripper_util_from_string_h */

Generated on Wed Jun 17 18:46:47 2009 for GridRipper by  doxygen 1.5.6