• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef JSON_PARSER_PREFIXING_CALLBACKS_HPP
2 #define JSON_PARSER_PREFIXING_CALLBACKS_HPP
3 
4 #include <boost/property_tree/json_parser/detail/standard_callbacks.hpp>
5 
6 namespace constants
7 {
8     template <typename Ch> const Ch* null_prefix();
null_prefix()9     template <> inline const char* null_prefix() { return "_:"; }
null_prefix()10     template <> inline const wchar_t* null_prefix() { return L"_:"; }
11 
12     template <typename Ch> const Ch* boolean_prefix();
boolean_prefix()13     template <> inline const char* boolean_prefix() { return "b:"; }
boolean_prefix()14     template <> inline const wchar_t* boolean_prefix() { return L"b:"; }
15 
16     template <typename Ch> const Ch* number_prefix();
number_prefix()17     template <> inline const char* number_prefix() { return "n:"; }
number_prefix()18     template <> inline const wchar_t* number_prefix() { return L"n:"; }
19 
20     template <typename Ch> const Ch* string_prefix();
string_prefix()21     template <> inline const char* string_prefix() { return "s:"; }
string_prefix()22     template <> inline const wchar_t* string_prefix() { return L"s:"; }
23 
24     template <typename Ch> const Ch* array_prefix();
array_prefix()25     template <> inline const char* array_prefix() { return "a:"; }
array_prefix()26     template <> inline const wchar_t* array_prefix() { return L"a:"; }
27 
28     template <typename Ch> const Ch* object_prefix();
object_prefix()29     template <> inline const char* object_prefix() { return "o:"; }
object_prefix()30     template <> inline const wchar_t* object_prefix() { return L"o:"; }
31 }
32 
33 template <typename Ptree>
34 struct prefixing_callbacks
35         : boost::property_tree::json_parser::detail::standard_callbacks<Ptree> {
36     typedef boost::property_tree::json_parser::detail::standard_callbacks<Ptree>
37         base;
38     typedef typename base::string string;
39     typedef typename base::char_type char_type;
40 
on_nullprefixing_callbacks41     void on_null() {
42         base::on_null();
43         this->current_value().insert(0, constants::null_prefix<char_type>());
44     }
45 
on_booleanprefixing_callbacks46     void on_boolean(bool b) {
47         base::on_boolean(b);
48         this->current_value().insert(0, constants::boolean_prefix<char_type>());
49     }
50 
51     template <typename Range>
on_numberprefixing_callbacks52     void on_number(Range code_units) {
53         base::on_number(code_units);
54         this->current_value().insert(0, constants::number_prefix<char_type>());
55     }
on_begin_numberprefixing_callbacks56     void on_begin_number() {
57         base::on_begin_number();
58         this->current_value() = constants::number_prefix<char_type>();
59     }
60 
on_begin_stringprefixing_callbacks61     void on_begin_string() {
62         base::on_begin_string();
63         if (!this->is_key()) {
64             this->current_value() = constants::string_prefix<char_type>();
65         }
66     }
67 
on_begin_arrayprefixing_callbacks68     void on_begin_array() {
69         base::on_begin_array();
70         this->current_value() = constants::array_prefix<char_type>();
71     }
72 
on_begin_objectprefixing_callbacks73     void on_begin_object() {
74         base::on_begin_object();
75         this->current_value() = constants::object_prefix<char_type>();
76     }
77 };
78 
79 #endif
80