| 1 |
// file : cutl/xml/value-traits.hxx |
| 2 |
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC |
| 3 |
// license : MIT; see accompanying LICENSE file |
| 4 |
|
| 5 |
#ifndef CUTL_XML_VALUE_TRAITS_HXX |
| 6 |
#define CUTL_XML_VALUE_TRAITS_HXX |
| 7 |
|
| 8 |
#include <string> |
| 9 |
#include <cstddef> // std::size_t |
| 10 |
|
| 11 |
#include <cutl/details/export.hxx> |
| 12 |
|
| 13 |
namespace cutl |
| 14 |
{ |
| 15 |
namespace xml |
| 16 |
{ |
| 17 |
class parser; |
| 18 |
class serializer; |
| 19 |
|
| 20 |
template <typename T> |
| 21 |
struct default_value_traits |
| 22 |
{ |
| 23 |
static T |
| 24 |
parse (std::string, const parser&); |
| 25 |
|
| 26 |
static std::string |
| 27 |
serialize (const T&, const serializer&); |
| 28 |
}; |
| 29 |
|
| 30 |
template <> |
| 31 |
struct LIBCUTL_EXPORT default_value_traits<bool> |
| 32 |
{ |
| 33 |
static bool |
| 34 |
parse (std::string, const parser&); |
| 35 |
|
| 36 |
static std::string |
| 37 |
serialize (bool v, const serializer&) |
| 38 |
{ |
| 39 |
return v ? "true" : "false"; |
| 40 |
} |
| 41 |
}; |
| 42 |
|
| 43 |
template <> |
| 44 |
struct LIBCUTL_EXPORT default_value_traits<std::string> |
| 45 |
{ |
| 46 |
static std::string |
| 47 |
parse (std::string s, const parser&) |
| 48 |
{ |
| 49 |
return s; |
| 50 |
} |
| 51 |
|
| 52 |
static std::string |
| 53 |
serialize (const std::string& v, const serializer&) |
| 54 |
{ |
| 55 |
return v; |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
template <typename T> |
| 60 |
struct value_traits: default_value_traits<T> {}; |
| 61 |
|
| 62 |
template <typename T, std::size_t N> |
| 63 |
struct value_traits<T[N]>: default_value_traits<const T*> {}; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
#include <cutl/xml/value-traits.txx> |
| 68 |
|
| 69 |
#endif // CUTL_XML_VALUE_TRAITS_HXX |