Skip to content

Commit 8600a3e

Browse files
committed
Rename add() to insert(), improve signature
1 parent 0cb0a92 commit 8600a3e

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

include/tao/json/patch.hh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace tao
2626
value.erase( path );
2727
}
2828
else if( op == "add" ) {
29-
value.add( path ) = entry.at( "value" );
29+
value.insert( path, entry.at( "value" ) );
3030
}
3131
else if( op == "replace" ) {
3232
value.at( path ) = entry.at( "value" );
@@ -35,12 +35,11 @@ namespace tao
3535
const json_pointer from( entry.at( "from" ).get_string() );
3636
auto v = std::move( value.at( from ) );
3737
value.erase( from );
38-
value.add( path ) = std::move( v );
38+
value.insert( path, std::move( v ) );
3939
}
4040
else if( op == "copy" ) {
4141
const json_pointer from( entry.at( "from" ).get_string() );
42-
auto v = value.at( from );
43-
value.add( path ) = std::move( v );
42+
value.insert( path, value.at( from ) );
4443
}
4544
else {
4645
throw std::runtime_error( "unknown patch operation: '" + op + '\'' );

include/tao/json/value.hh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,10 @@ namespace tao
478478
}
479479
}
480480

481-
basic_value & add( const json_pointer & k )
481+
basic_value & insert( const json_pointer & k, basic_value value )
482482
{
483483
if ( ! k ) {
484-
return * this;
484+
throw "TODO: Clarify with RFC!!!";
485485
}
486486
const auto sp = k.split();
487487
basic_value & v = internal::json_pointer_at( this, sp.first );
@@ -490,11 +490,11 @@ namespace tao
490490
{
491491
const auto & t = sp.second;
492492
if ( t == "-" ) {
493-
v.unsafe_emplace_back( null );
493+
v.unsafe_emplace_back( std::move( value ) );
494494
return v.m_union.a.back();
495495
}
496496
const auto i = internal::json_pointer_token_to_index( t );
497-
v.m_union.a.insert( v.m_union.a.begin() + i, null );
497+
v.m_union.a.insert( v.m_union.a.begin() + i, std::move( value ) );
498498
return v.m_union.a.at( i );
499499
}
500500
break;
@@ -503,10 +503,11 @@ namespace tao
503503
auto & t = sp.second;
504504
const auto it = v.m_union.o.find( t );
505505
if ( it == v.m_union.o.end() ) {
506-
const auto r = v.unsafe_emplace( std::move( t ), null );
506+
const auto r = v.unsafe_emplace( std::move( t ), std::move( value ) );
507507
assert( r.second );
508508
return r.first->second;
509509
}
510+
it->second = std::move( value );
510511
return it->second;
511512
}
512513
break;

0 commit comments

Comments
 (0)