Skip to content

Commit 5caaa76

Browse files
committed
Fixed typos, generalize
1 parent 94d0149 commit 5caaa76

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

contrib/nlohmann/to_value.hh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@
99
#include <cstdint>
1010
#include <utility>
1111

12-
#include "json.hpp"
13-
1412
namespace tao
1513
{
1614
namespace json
1715
{
1816
namespace nlohmann
1917
{
2018
// SAX consumer to build an nlohmann/json value
19+
template< typename Value >
2120
class to_value
2221
{
2322
private:
24-
std::vector< ::nlohmann::json > stack_;
23+
std::vector< Value > stack_;
2524
std::vector< std::string > keys_;
2625

2726
public:
28-
::nlohmann::json value;
27+
Value value;
2928

3029
void null()
3130
{
@@ -65,7 +64,7 @@ namespace tao
6564
// array
6665
void begin_array()
6766
{
68-
stack_.push_back( ::nlohmann::json::array() );
67+
stack_.push_back( Value::array() );
6968
}
7069

7170
void element()
@@ -82,7 +81,7 @@ namespace tao
8281
// object
8382
void begin_object()
8483
{
85-
stack_.push_back( ::nlohmann::json::object() );
84+
stack_.push_back( Value::object() );
8685
}
8786

8887
void key( const std::string & v )
@@ -97,7 +96,7 @@ namespace tao
9796

9897
void member()
9998
{
100-
stack_.back().push_back( ::nlohmann::json::object_t::value_type( std::move( keys_.back() ), std::move( value ) ) );
99+
stack_.back().push_back( Value::object_t::value_type( std::move( keys_.back() ), std::move( value ) ) );
101100
keys_.pop_back();
102101
}
103102

contrib/nlohmann/traverse_value.hh

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,61 @@
11
// Copyright (c) 2016 Dr. Colin Hirsch and Daniel Frey
22
// Please see LICENSE for license or visit https://github.com/taocpp/json/
33

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
66

77
#include <cstdint>
88
#include <string>
99
#include <stdexcept>
1010

11-
#include "json.hpp"
12-
1311
namespace tao
1412
{
1513
namespace json
1614
{
1715
namespace nlohmann
1816
{
1917
// 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 )
2220
{
2321
switch( v.type() ) {
24-
case nlohmann::json::value_t::null:
22+
case Value::value_t::null:
2523
handler.null();
2624
break;
27-
case nlohmann::json::value_t::boolean:
25+
case Value::value_t::boolean:
2826
handler.boolean( v.get< bool >() );
2927
break;
30-
case nlohmann::json::value_t::number_integer:
28+
case Value::value_t::number_integer:
3129
handler.number( v.get< std::int64_t >() );
3230
break;
33-
case nlohmann::json::value_t::number_unsigned:
31+
case Value::value_t::number_unsigned:
3432
handler.number( v.get< std::uint64_t >() );
3533
break;
36-
case nlohmann::json::value_t::number_float:
34+
case Value::value_t::number_float:
3735
handler.number( v.get< double >() );
3836
break;
39-
case nlohmann::json::value_t::string:
37+
case Value::value_t::string:
4038
handler.string( v.get_ref< const std::string & >() );
4139
break;
42-
case nlohmann::json::value_t::array:
40+
case Value::value_t::array:
4341
handler.begin_array();
4442
for( const auto & e : v ) {
45-
traverse_nlohmann( e, handler );
43+
tao::json::nlohmann::traverse_value( e, handler );
4644
handler.element();
4745
}
4846
handler.end_array();
4947
break;
50-
case nlohmann::json::value_t::object:
48+
case Value::value_t::object:
5149
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 ) {
5351
handler.key( it.key() );
54-
traverse_nlohmann( it.value(), handler );
52+
tao::json::nlohmann::traverse_value( it.value(), handler );
5553
handler.member();
5654
}
5755
handler.end_object();
5856
break;
5957
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
6159
}
6260
}
6361

0 commit comments

Comments
 (0)