Debian Codegraph @

cutl/xml/value-traits.txx

raw
1 // file : cutl/xml/value-traits.txx
2 // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
3 // license : MIT; see accompanying LICENSE file
4
5 #include <sstream>
6
7 #include <cutl/xml/parser.hxx>
8 #include <cutl/xml/serializer.hxx>
9
10 namespace cutl
11 {
12 namespace xml
13 {
14 template <typename T>
15 T default_value_traits<T>::
16 parse (std::string s, const parser& p)
17 {
18 T r;
19 std::istringstream is (s);
20 if (!(is >> r && is.eof ()) )
21 throw parsing (p, "invalid value '" + s + "'");
22 return r;
23 }
24
25 template <typename T>
26 std::string default_value_traits<T>::
27 serialize (const T& v, const serializer& s)
28 {
29 std::ostringstream os;
30 if (!(os << v))
31 throw serialization (s, "invalid value");
32 return os.str ();
33 }
34 }
35 }