Skip to content

Commit e2e847c

Browse files
committed
Rename traverse_value to from_value
1 parent 2b626e3 commit e2e847c

File tree

9 files changed

+39
-173
lines changed

9 files changed

+39
-173
lines changed

contrib/nlohmann.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "nlohmann/json.hpp"
77
#include "nlohmann/to_value.hh"
8-
#include "nlohmann/traverse_value.hh"
8+
#include "nlohmann/from_value.hh"
99

1010
#include <tao/json/sax/from_string.hh>
1111
#include <tao/json/sax/to_string.hh>
@@ -40,7 +40,7 @@ namespace tao
4040
TEST_ASSERT( v[ 7 ].at( "c" ) == "d" );
4141

4242
tao::json::sax::to_string oss_handler;
43-
tao::json::nlohmann::traverse_value( v, oss_handler );
43+
tao::json::nlohmann::from_value( v, oss_handler );
4444

4545
TEST_ASSERT( oss_handler.value() == "[null,true,false,42,43.0,\"foo\",[1,2,3],{\"a\":\"b\",\"c\":\"d\"}]" );
4646
}

contrib/nlohmann/traverse_value.hh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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_TRAVERSE_VALUE_HH
5-
#define TAOCPP_JSON_INCLUDE_JSON_NLOHMANN_TRAVERSE_VALUE_HH
4+
#ifndef TAOCPP_JSON_INCLUDE_JSON_NLOHMANN_FROM_VALUE_HH
5+
#define TAOCPP_JSON_INCLUDE_JSON_NLOHMANN_FROM_VALUE_HH
66

77
#include <cstdint>
88
#include <string>
@@ -15,46 +15,46 @@ namespace tao
1515
namespace nlohmann
1616
{
1717
// SAX producer for an nlohmann/json value
18-
template< typename Value, typename Handler >
19-
void traverse_value( const Value & v, Handler & handler )
18+
template< typename Value, typename Consumer >
19+
void from_value( const Value & v, Consumer & consumer )
2020
{
2121
switch( v.type() ) {
2222
case Value::value_t::discarded:
2323
throw std::logic_error( "invalid discarded value" );
2424
case Value::value_t::null:
25-
handler.null();
25+
consumer.null();
2626
return;
2727
case Value::value_t::boolean:
28-
handler.boolean( v.template get< bool >() );
28+
consumer.boolean( v.template get< bool >() );
2929
return;
3030
case Value::value_t::number_integer:
31-
handler.number( v.template get< std::int64_t >() );
31+
consumer.number( v.template get< std::int64_t >() );
3232
return;
3333
case Value::value_t::number_unsigned:
34-
handler.number( v.template get< std::uint64_t >() );
34+
consumer.number( v.template get< std::uint64_t >() );
3535
return;
3636
case Value::value_t::number_float:
37-
handler.number( v.template get< double >() );
37+
consumer.number( v.template get< double >() );
3838
return;
3939
case Value::value_t::string:
40-
handler.string( v.template get_ref< const std::string & >() );
40+
consumer.string( v.template get_ref< const std::string & >() );
4141
return;
4242
case Value::value_t::array:
43-
handler.begin_array();
43+
consumer.begin_array();
4444
for( const auto & e : v ) {
45-
tao::json::nlohmann::traverse_value( e, handler );
46-
handler.element();
45+
tao::json::nlohmann::from_value( e, consumer );
46+
consumer.element();
4747
}
48-
handler.end_array();
48+
consumer.end_array();
4949
return;
5050
case Value::value_t::object:
51-
handler.begin_object();
51+
consumer.begin_object();
5252
for( typename Value::const_iterator it = v.begin(); it != v.end(); ++it ) {
53-
handler.key( it.key() );
54-
tao::json::nlohmann::traverse_value( it.value(), handler );
55-
handler.member();
53+
consumer.key( it.key() );
54+
tao::json::nlohmann::from_value( it.value(), consumer );
55+
consumer.member();
5656
}
57-
handler.end_object();
57+
consumer.end_object();
5858
return;
5959
}
6060
throw std::logic_error( "invalid value for type()" ); // LCOV_EXCL_LINE

include/tao/json.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//#include "json/sax/from_stream.hh" // includes PEGTL header/grammar
1212
#include "json/sax/from_string.hh" // includes PEGTL header/grammar
1313
#include "json/sax/parse_file.hh" // includes PEGTL header/grammar
14-
#include "json/sax/traverse_value.hh" // DOM to SAX
14+
#include "json/sax/from_value.hh" // DOM to SAX
1515

1616
// SAX consumers
1717
#include "json/sax/to_stream.hh"

include/tao/json/sax/traverse_value.hh

Lines changed: 0 additions & 133 deletions
This file was deleted.

include/tao/json/schema.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "reference.hh"
1010
#include "sax/compare.hh"
1111
#include "sax/hash.hh"
12-
#include "sax/traverse_value.hh"
12+
#include "sax/from_value.hh"
1313
#include "external/pegtl/parse.hh"
1414
#include "external/pegtl/contrib/uri.hh"
1515

@@ -1706,7 +1706,7 @@ namespace tao
17061706
// TODO: DOM validation should be implemented independently,
17071707
// as it could be more efficient than SAX validation!
17081708
const auto c = consumer();
1709-
sax::traverse_value( v, * c );
1709+
sax::from_value( v, * c );
17101710
return c->finalize();
17111711
}
17121712
};

include/tao/json/to_stream.hh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <cstddef>
99

1010
#include "value.hh"
11-
#include "sax/traverse_value.hh"
11+
#include "sax/from_value.hh"
1212
#include "sax/to_stream.hh"
1313
#include "sax/to_pretty_stream.hh"
1414

@@ -19,15 +19,15 @@ namespace tao
1919
template< template< typename ... > class Traits >
2020
void to_stream( std::ostream & os, const basic_value< Traits > & v )
2121
{
22-
sax::to_stream handler( os );
23-
sax::traverse_value( v, handler );
22+
sax::to_stream consumer( os );
23+
sax::from_value( v, consumer );
2424
}
2525

2626
template< template< typename ... > class Traits >
2727
void to_stream( std::ostream & os, const basic_value< Traits > & v, const std::size_t indent )
2828
{
29-
sax::to_pretty_stream handler( os, indent );
30-
sax::traverse_value( v, handler );
29+
sax::to_pretty_stream consumer( os, indent );
30+
sax::from_value( v, consumer );
3131
}
3232

3333
} // json

src/test/json/sax_compare.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <tao/json/value.hh>
77
#include <tao/json/sax/compare.hh>
8-
#include <tao/json/sax/traverse_value.hh>
8+
#include <tao/json/sax/from_value.hh>
99
#include <tao/json/sax/from_string.hh>
1010

1111
namespace tao
@@ -15,7 +15,7 @@ namespace tao
1515
bool test_value( const value & v, sax::compare & c )
1616
{
1717
c.reset();
18-
sax::traverse_value( v, c );
18+
sax::from_value( v, c );
1919
return c.match();
2020
}
2121

@@ -397,32 +397,32 @@ namespace tao
397397
value v = { { "foo", 0 }, { "bar", & b }, { "baz", value::array( { null, & b, false, 0, 1, & s } ) } };
398398

399399
sax::compare c( v );
400-
sax::traverse_value( v, c );
400+
sax::from_value( v, c );
401401
TEST_ASSERT( c.match() );
402402

403403
c.reset();
404404
v.at( "foo" ) = 42;
405-
sax::traverse_value( v, c );
405+
sax::from_value( v, c );
406406
TEST_ASSERT( ! c.match() );
407407

408408
c.reset();
409409
v.at( "foo" ) = 0;
410-
sax::traverse_value( v, c );
410+
sax::from_value( v, c );
411411
TEST_ASSERT( c.match() );
412412

413413
c.reset();
414414
v.at( "baz" ).at( 2 ) = 42;
415-
sax::traverse_value( v, c );
415+
sax::from_value( v, c );
416416
TEST_ASSERT( ! c.match() );
417417

418418
c.reset();
419419
v.at( "baz" ).at( 2 ) = true;
420-
sax::traverse_value( v, c );
420+
sax::from_value( v, c );
421421
TEST_ASSERT( ! c.match() );
422422

423423
c.reset();
424424
v.at( "baz" ).at( 2 ) = false;
425-
sax::traverse_value( v, c );
425+
sax::from_value( v, c );
426426
TEST_ASSERT( c.match() );
427427
}
428428

src/test/json/sax_hash.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <tao/json/value.hh>
77
#include <tao/json/sax/hash.hh>
8-
#include <tao/json/sax/traverse_value.hh>
8+
#include <tao/json/sax/from_value.hh>
99
#include <tao/json/sax/from_string.hh>
1010

1111
namespace tao
@@ -15,7 +15,7 @@ namespace tao
1515
std::string hash_value( const value & v )
1616
{
1717
sax::hash h;
18-
sax::traverse_value( v, h );
18+
sax::from_value( v, h );
1919
return h.value();
2020
}
2121

src/test/json/schema.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <tao/json/pointer.hh>
1111
#include <tao/json/schema.hh>
1212
#include <tao/json/parse_file.hh>
13-
#include <tao/json/sax/traverse_value.hh>
1413

1514
namespace tao
1615
{

0 commit comments

Comments
 (0)