Skip to content

Commit f98b38a

Browse files
committed
Add array_t and object_t
1 parent 195d570 commit f98b38a

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

doc/ref/basic_value.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Each instance is a JSON document. Each instance stores the type of the JSON docu
1414

1515
`Traits` - Conversion from and to other data types. Can be specialized or replaced by the user.
1616

17+
### Member types
18+
19+
| Member | Description |
20+
| --- | --- |
21+
| `array_t` | Type to store an embedded array, `std::vector<basic_value>` |
22+
| `object_t` | Type to store an embedded object, `std::map<std::string, basic_value>` |
23+
1724
### Member functions
1825

1926
| Method | Description |

include/tao/json/value.hh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ namespace tao
6969
internal::totally_ordered< basic_value< Traits >, std::nullptr_t, type::RAW_PTR >
7070
{
7171
public:
72+
using array_t = std::vector< basic_value >;
73+
using object_t = std::map< std::string, basic_value >;
74+
7275
basic_value() noexcept
7376
{ }
7477

@@ -270,25 +273,25 @@ namespace tao
270273
return unsafe_get_string();
271274
}
272275

273-
std::vector< basic_value > & get_array()
276+
array_t & get_array()
274277
{
275278
TAOCPP_JSON_CHECK_TYPE_ERROR( m_type, json::type::ARRAY );
276279
return unsafe_get_array();
277280
}
278281

279-
const std::vector< basic_value > & get_array() const
282+
const array_t & get_array() const
280283
{
281284
TAOCPP_JSON_CHECK_TYPE_ERROR( m_type, json::type::ARRAY );
282285
return unsafe_get_array();
283286
}
284287

285-
std::map< std::string, basic_value > & get_object()
288+
object_t & get_object()
286289
{
287290
TAOCPP_JSON_CHECK_TYPE_ERROR( m_type, json::type::OBJECT );
288291
return unsafe_get_object();
289292
}
290293

291-
const std::map< std::string, basic_value > & get_object() const
294+
const object_t & get_object() const
292295
{
293296
TAOCPP_JSON_CHECK_TYPE_ERROR( m_type, json::type::OBJECT );
294297
return unsafe_get_object();
@@ -379,22 +382,22 @@ namespace tao
379382
return m_union.s;
380383
}
381384

382-
std::vector< basic_value > & unsafe_get_array() noexcept
385+
array_t & unsafe_get_array() noexcept
383386
{
384387
return m_union.a;
385388
}
386389

387-
const std::vector< basic_value > & unsafe_get_array() const noexcept
390+
const array_t & unsafe_get_array() const noexcept
388391
{
389392
return m_union.a;
390393
}
391394

392-
std::map< std::string, basic_value > & unsafe_get_object() noexcept
395+
object_t & unsafe_get_object() noexcept
393396
{
394397
return m_union.o;
395398
}
396399

397-
const std::map< std::string, basic_value > & unsafe_get_object() const noexcept
400+
const object_t & unsafe_get_object() const noexcept
398401
{
399402
return m_union.o;
400403
}
@@ -806,13 +809,13 @@ namespace tao
806809
}
807810

808811
template< typename K, typename V >
809-
std::pair< typename std::map< std::string, basic_value >::iterator, bool > unsafe_emplace( K && k, V && v )
812+
std::pair< typename object_t::iterator, bool > unsafe_emplace( K && k, V && v )
810813
{
811814
return m_union.o.emplace( std::forward< K >( k ), std::forward< V >( v ) );
812815
}
813816

814817
template< typename K, typename V >
815-
std::pair< typename std::map< std::string, basic_value >::iterator, bool > emplace( K && k, V && v )
818+
std::pair< typename object_t::iterator, bool > emplace( K && k, V && v )
816819
{
817820
prepare_object();
818821
return unsafe_emplace( std::forward< K >( k ), std::forward< V >( v ) );

0 commit comments

Comments
 (0)