diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/property_tree/test/prefixing_callbacks.hpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/property_tree/test/prefixing_callbacks.hpp')
-rw-r--r-- | src/boost/libs/property_tree/test/prefixing_callbacks.hpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/boost/libs/property_tree/test/prefixing_callbacks.hpp b/src/boost/libs/property_tree/test/prefixing_callbacks.hpp new file mode 100644 index 00000000..d993fb59 --- /dev/null +++ b/src/boost/libs/property_tree/test/prefixing_callbacks.hpp @@ -0,0 +1,79 @@ +#ifndef JSON_PARSER_PREFIXING_CALLBACKS_HPP +#define JSON_PARSER_PREFIXING_CALLBACKS_HPP + +#include <boost/property_tree/json_parser/detail/standard_callbacks.hpp> + +namespace constants +{ + template <typename Ch> const Ch* null_prefix(); + template <> inline const char* null_prefix() { return "_:"; } + template <> inline const wchar_t* null_prefix() { return L"_:"; } + + template <typename Ch> const Ch* boolean_prefix(); + template <> inline const char* boolean_prefix() { return "b:"; } + template <> inline const wchar_t* boolean_prefix() { return L"b:"; } + + template <typename Ch> const Ch* number_prefix(); + template <> inline const char* number_prefix() { return "n:"; } + template <> inline const wchar_t* number_prefix() { return L"n:"; } + + template <typename Ch> const Ch* string_prefix(); + template <> inline const char* string_prefix() { return "s:"; } + template <> inline const wchar_t* string_prefix() { return L"s:"; } + + template <typename Ch> const Ch* array_prefix(); + template <> inline const char* array_prefix() { return "a:"; } + template <> inline const wchar_t* array_prefix() { return L"a:"; } + + template <typename Ch> const Ch* object_prefix(); + template <> inline const char* object_prefix() { return "o:"; } + template <> inline const wchar_t* object_prefix() { return L"o:"; } +} + +template <typename Ptree> +struct prefixing_callbacks + : boost::property_tree::json_parser::detail::standard_callbacks<Ptree> { + typedef boost::property_tree::json_parser::detail::standard_callbacks<Ptree> + base; + typedef typename base::string string; + typedef typename base::char_type char_type; + + void on_null() { + base::on_null(); + this->current_value().insert(0, constants::null_prefix<char_type>()); + } + + void on_boolean(bool b) { + base::on_boolean(b); + this->current_value().insert(0, constants::boolean_prefix<char_type>()); + } + + template <typename Range> + void on_number(Range code_units) { + base::on_number(code_units); + this->current_value().insert(0, constants::number_prefix<char_type>()); + } + void on_begin_number() { + base::on_begin_number(); + this->current_value() = constants::number_prefix<char_type>(); + } + + void on_begin_string() { + base::on_begin_string(); + if (!this->is_key()) { + this->current_value() = constants::string_prefix<char_type>(); + } + } + + void on_begin_array() { + base::on_begin_array(); + this->current_value() = constants::array_prefix<char_type>(); + } + + void on_begin_object() { + base::on_begin_object(); + this->current_value() = constants::object_prefix<char_type>(); + } +}; + +#endif |