20void raise (
const char* name,
const std::string& exception);
24 typedef std::ios_base::fmtflags fmtflags;
26#define fmtzero fmtflags(0)
39 ToString () { reset_modifiers(); }
41 void reset_modifiers ()
43 precision_set = setf_set = unsetf_set =
false;
45 setf = unsetf = fmtzero;
48 void set_precision (
unsigned p) { precision = p; precision_set =
true; }
49 void set_setf (fmtflags f) { setf = f; setf_set =
true; }
50 void set_unsetf (fmtflags f) { unsetf = f; unsetf_set =
true; }
53 std::string operator () (
const T& input)
const
55 std::ostringstream ost;
64 ost.precision (precision);
66 ost.precision (std::numeric_limits<T>::digits10);
72 "failed to convert "+ std::string(
typeid(T).name()) +
" to string");
83extern unsigned tostring_precision;
84extern std::ios_base::fmtflags tostring_setf;
85extern std::ios_base::fmtflags tostring_unsetf;
87#define FMTFLAGS_ZERO std::ios_base::fmtflags(0)
90std::string tostring (
const T& input,
91 unsigned precision = std::numeric_limits<T>::digits10,
92 std::ios_base::fmtflags set = FMTFLAGS_ZERO,
93 std::ios_base::fmtflags unset = FMTFLAGS_ZERO)
98 tostr.set_setf (tostring_setf);
100 tostr.set_setf (set);
103 tostr.set_unsetf (tostring_unsetf);
105 tostr.set_unsetf (unset);
107 if (tostring_precision)
108 tostr.set_precision (tostring_precision);
110 tostr.set_precision (precision);
112 return tostr( input );
116T fromstring (
const std::string& input)
118 std::istringstream ist;
127 raise (
"fromstring",
"failed to parse '"+ input +
"'");
133inline std::string tostring (
const std::string& input)
140inline std::string fromstring<std::string> (
const std::string& input)
146inline std::string tostring (
const char* input)
160template<
typename Type,
typename String2Type>
161std::istream& extraction (std::istream& is, Type& t, String2Type string2type)
163 std::streampos pos = is.tellg();
168 t = string2type (ss);
171 is.setstate(std::istream::failbit);
A convenient exception handling class.
Definition Error.h:54