|
1 | 1 | // Copyright (c) 2016 Dr. Colin Hirsch and Daniel Frey |
2 | 2 | // Please see LICENSE for license or visit https://github.com/taocpp/json/ |
3 | 3 |
|
4 | | -#ifndef TAOCPP_JSON_INCLUDE_JSON_NLOHMANN_TO_VALUE_HH |
5 | | -#define TAOCPP_JSON_INCLUDE_JSON_NLOHMANN_TO_VALUE_HH |
| 4 | +#ifndef TAOCPP_JSON_INCLUDE_JSON_NLOHMANN_TRAVERSE_VALUE_HH |
| 5 | +#define TAOCPP_JSON_INCLUDE_JSON_NLOHMANN_TRAVERSE_VALUE_HH |
6 | 6 |
|
7 | 7 | #include <cstdint> |
8 | 8 | #include <string> |
9 | 9 | #include <stdexcept> |
10 | 10 |
|
11 | | -#include "json.hpp" |
12 | | - |
13 | 11 | namespace tao |
14 | 12 | { |
15 | 13 | namespace json |
16 | 14 | { |
17 | 15 | namespace nlohmann |
18 | 16 | { |
19 | 17 | // SAX producer for an nlohmann/json value |
20 | | - template< typename Handler > |
21 | | - void traverse_nlohmann( const nlohmann::json & v, Handler & handler ) |
| 18 | + template< typename Value, typename Handler > |
| 19 | + void traverse_value( const Value & v, Handler & handler ) |
22 | 20 | { |
23 | 21 | switch( v.type() ) { |
24 | | - case nlohmann::json::value_t::null: |
| 22 | + case Value::value_t::null: |
25 | 23 | handler.null(); |
26 | 24 | break; |
27 | | - case nlohmann::json::value_t::boolean: |
| 25 | + case Value::value_t::boolean: |
28 | 26 | handler.boolean( v.get< bool >() ); |
29 | 27 | break; |
30 | | - case nlohmann::json::value_t::number_integer: |
| 28 | + case Value::value_t::number_integer: |
31 | 29 | handler.number( v.get< std::int64_t >() ); |
32 | 30 | break; |
33 | | - case nlohmann::json::value_t::number_unsigned: |
| 31 | + case Value::value_t::number_unsigned: |
34 | 32 | handler.number( v.get< std::uint64_t >() ); |
35 | 33 | break; |
36 | | - case nlohmann::json::value_t::number_float: |
| 34 | + case Value::value_t::number_float: |
37 | 35 | handler.number( v.get< double >() ); |
38 | 36 | break; |
39 | | - case nlohmann::json::value_t::string: |
| 37 | + case Value::value_t::string: |
40 | 38 | handler.string( v.get_ref< const std::string & >() ); |
41 | 39 | break; |
42 | | - case nlohmann::json::value_t::array: |
| 40 | + case Value::value_t::array: |
43 | 41 | handler.begin_array(); |
44 | 42 | for( const auto & e : v ) { |
45 | | - traverse_nlohmann( e, handler ); |
| 43 | + tao::json::nlohmann::traverse_value( e, handler ); |
46 | 44 | handler.element(); |
47 | 45 | } |
48 | 46 | handler.end_array(); |
49 | 47 | break; |
50 | | - case nlohmann::json::value_t::object: |
| 48 | + case Value::value_t::object: |
51 | 49 | handler.begin_object(); |
52 | | - for( nlohmann::json::const_iterator it = v.begin(); it != v.end(); ++it ) { |
| 50 | + for( Value::const_iterator it = v.begin(); it != v.end(); ++it ) { |
53 | 51 | handler.key( it.key() ); |
54 | | - traverse_nlohmann( it.value(), handler ); |
| 52 | + tao::json::nlohmann::traverse_value( it.value(), handler ); |
55 | 53 | handler.member(); |
56 | 54 | } |
57 | 55 | handler.end_object(); |
58 | 56 | break; |
59 | 57 | default: |
60 | | - throw std::logic_error( "invalid value for nohmann::json::type()" ); // LCOV_EXCL_LINE |
| 58 | + throw std::logic_error( "invalid value for type()" ); // LCOV_EXCL_LINE |
61 | 59 | } |
62 | 60 | } |
63 | 61 |
|
|
0 commit comments