10 #define _gu_utils_hpp_
17 #include "gu_exception.hpp"
28 std::ios_base& (*f)(std::ios_base&) = std::dec)
30 std::ostringstream out;
31 out << std::showbase << f << x;
39 std::ios_base& (*f)(std::ios_base&))
41 std::ostringstream out;
42 out << std::boolalpha << x;
49 std::ios_base& (*f)(std::ios_base&))
51 const int sigdigits = std::numeric_limits<double>::digits10;
53 std::ostringstream out;
54 out << std::setprecision(sigdigits) << x;
60 template <
typename T>
inline T
62 std::ios_base& (*f)(std::ios_base&) = std::dec)
64 std::istringstream iss(s);
69 if ((iss >> f >> ret).fail())
throw NotFound();
80 template <>
inline std::string
81 from_string<std::string>(
const std::string& s,
82 std::ios_base& (*f)(std::ios_base&))
90 std::ios_base& (*f)(std::ios_base&))
92 std::istringstream iss(s);
95 if ((iss >> std::hex >> ret).fail())
throw NotFound();
100 extern "C" const char* gu_str2bool (
const char* str,
bool* bl);
105 std::ios_base& (*f)(std::ios_base&))
108 const char* endptr(gu_str2bool(s.c_str(), &ret));
109 if (endptr == 0 || *endptr !=
'\0')
throw NotFound();
119 template <
typename T>
class VLA
124 VLA& operator= (
const VLA&);
128 VLA (
size_t n) : array(
new T[n]) {}
130 ~
VLA () {
delete[] array; }
132 T* operator& () {
return array; }
134 T& operator[] (
size_t i) {
return array[i]; }
154 template <
class T>
void operator()(T* t) {
delete t; }
std::string to_string(const T &x, std::ios_base &(*f)(std::ios_base &)=std::dec)
Definition: gu_utils.hpp:27
T from_string(const std::string &s, std::ios_base &(*f)(std::ios_base &)=std::dec)
Definition: gu_utils.hpp:61
std::string to_string< double >(const double &x, std::ios_base &(*f)(std::ios_base &))
Definition: gu_utils.hpp:48
bool from_string< bool >(const std::string &s, std::ios_base &(*f)(std::ios_base &))
Definition: gu_utils.hpp:104
std::string to_string< bool >(const bool &x, std::ios_base &(*f)(std::ios_base &))
Definition: gu_utils.hpp:38
void * from_string< void * >(const std::string &s, std::ios_base &(*f)(std::ios_base &))
Definition: gu_utils.hpp:89
Definition: gu_exception.hpp:19
Definition: gu_exception.hpp:17
Definition: gu_utils.hpp:119
Definition: gu_utils.hpp:151