19#include <initializer_list>
34class object_node_handle;
52 constexpr value_storage() :
69 public std::logic_error
109 typedef std::size_t size_type;
110 typedef std::ptrdiff_t difference_type;
113 template <
typename T,
typename TArrayView>
117 using iterator_category = std::random_access_iterator_tag;
118 using value_type = T;
119 using difference_type = std::ptrdiff_t;
121 using reference = T&;
132 template <
typename U,
typename UArrayView>
134 typename std::enable_if<std::is_convertible<U*, T*>::value>::type* = 0
166 template <
typename U,
typename UArrayView>
169 return _owner ==
other._owner && _index ==
other._index;
172 template <
typename U,
typename UArrayView>
175 return !operator==(
other);
180 return _owner->operator[](_index);
183 T* operator->()
const
185 return &_owner->operator[](_index);
216 return difference_type(_index) - difference_type(
other._index);
221 return _index <
rhs._index;
226 return _index <=
rhs._index;
231 return _index >
rhs._index;
236 return _index >=
rhs._index;
239 T& operator[](size_type
n)
const
241 return _owner->operator[](_index +
n);
244 template <
typename U,
typename UArrayView>
263 typedef detail::basic_view<array_iterator, const_array_iterator>
array_view;
264 typedef detail::basic_view<const_array_iterator> const_array_view;
265 typedef detail::basic_owning_view<value, array_iterator, const_array_iterator> owning_array_view;
270 template <
typename T,
typename TIterator>
274 using iterator_category = std::bidirectional_iterator_tag;
275 using value_type = T;
276 using difference_type = std::ptrdiff_t;
278 using reference = T&;
289 template <
typename U,
typename UIterator>
291 typename std::enable_if<std::is_convertible<U*, T*>::value>::type* = 0
302 template <
typename U,
typename UIterator>
303 typename std::enable_if<std::is_convertible<U*, T*>::value, basic_object_iterator&>::type
306 return operator=(basic_object_iterator(
source));
309 basic_object_iterator& operator++()
315 basic_object_iterator operator++(
int)
const
317 basic_object_iterator clone(*
this);
322 basic_object_iterator& operator--()
328 basic_object_iterator operator--(
int)
const
330 basic_object_iterator clone(*
this);
335 template <
typename U,
typename UIterator>
336 bool operator ==(
const basic_object_iterator<U, UIterator>& other)
const
338 return _impl == other._impl;
341 template <
typename U,
typename UIterator>
342 bool operator !=(
const basic_object_iterator<U, UIterator>& other)
const
344 return _impl != other._impl;
347 T& operator *()
const
352 T* operator ->()
const
360 template <
typename UIterator>
361 explicit basic_object_iterator(
const UIterator& iter) :
396 typedef detail::basic_view<object_iterator, const_object_iterator>
object_view;
397 typedef detail::basic_view<const_object_iterator> const_object_view;
398 typedef detail::basic_owning_view<value, object_iterator, const_object_iterator> owning_object_view;
460 #define JSONV_VALUE_INTEGER_ALTERNATIVE_CTOR_PROTO_GENERATOR(type_) \
559 value& at_path(std::string_view
p);
560 value& at_path(size_type
p);
562 const value& at_path(std::string_view
p)
const;
563 const value& at_path(size_type
p)
const;
573 size_type count_path(std::string_view
p)
const;
574 size_type count_path(size_type
p)
const;
666 const_array_view as_array()
const &;
667 owning_array_view as_array() &&;
678 inline const value& operator[](
int idx)
const {
return operator[](size_type(
idx)); }
688 const value& at(size_type
idx)
const;
713 template <
typename TForwardIterator>
731 template <
typename TForwardIterator>
735 auto iter = begin_array();
789 const_object_view as_object()
const &;
790 owning_object_view as_object() &&;
869 void insert(std::initializer_list<std::pair<std::string, value>>
items);
870 void insert(std::initializer_list<std::pair<std::wstring, value>>
items);
878 size_type
erase(
const std::string& key);
879 size_type erase(
const std::wstring& key);
965 detail::value_storage _data;
1012template <
typename TForwardIterator>
1060 enum class purposeful_construction
1063 explicit object_node_handle(purposeful_construction, key_type, mapped_type)
noexcept;
1069 mutable key_type _key;
1070 mutable mapped_type _value;
1089 std::size_t operator()(
const jsonv::value& val)
const noexcept;
Copyright (c) 2014-2020 by Travis Gockel.
An adapter for enumeration types.
Thrown from various value methods when attempting to perform an operation which is not valid for the ...
A node handle used when a value is kind::object to access elements of the object in potentially destr...
key_type & key() const
Returns a non-const reference to the key_type member of the element.
mapped_type & mapped() const
Returns a non-const reference to the mapped_type member of the element.
std::string key_type
The key type of the object.
Represents an exact path in some JSON structure.
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
void assign(TForwardIterator first, TForwardIterator last)
Assign the contents of range [first, last) to this array.
value(const std::string_view &value)
Create a kind::string with the given value.
constexpr value()
Default-construct this to null.
value(std::nullptr_t)=delete
The nullptr overload will fail to compile – use jsonv::null if you want a kind::null.
array_iterator erase(const_array_iterator first, const_array_iterator last)
Erase the range [first, last) from this array.
value(float value)
Create a kind::decimal with the given value.
value & at_path(const path &p)
Get the value specified by the path p.
value & path(const path &p)
Get or create the value specified by the path p.
friend std::ostream & operator<<(std::ostream &stream, const value &val)
Output this value to a stream.
basic_object_iterator< object_value_type, std::map< std::string, value >::iterator > object_iterator
The object_iterator is applicable when kind is kind::object.
void assign(size_type count, const value &val)
Assign count elements to this array with val.
object_iterator erase(const_object_iterator position)
Erase the item at the given position.
size_type count_path(const path &p) const
Similar to count, but walks the given path p to determine its presence.
bool operator!=(const value &other) const
Compares two JSON values for inequality.
detail::basic_view< object_iterator, const_object_iterator > object_view
If kind is kind::object, an object_view allows you to access a value as an associative container.
object_iterator end_object()
Get an iterator to the one past the end of this object.
int compare(const value &other) const
Used to build a strict-ordering of JSON values.
object_node_handle extract(const_object_iterator position)
detail::basic_view< array_iterator, const_array_iterator > array_view
If kind is kind::array, an array_view allows you to access a value as a sequence container.
object_node_handle extract(const std::string &key)
If the container has an element with the given key, unlinks the node that contains that element from ...
value(const wchar_t *value)
Create a kind::string with the given value.
object_insert_return_type insert(object_node_handle &&handle)
Insert the contents of handle.
object_iterator insert(const_object_iterator hint, object_node_handle &&handle)
If handle is an empty node handle, does nothing and returns end_object.
array_iterator erase(const_array_iterator position)
Erase the item at this array's position.
bool operator==(const value &other) const
Compares two JSON values for equality.
array_iterator insert(const_array_iterator position, TForwardIterator first, TForwardIterator last)
Insert the range defined by [first, last) at position in this array.
void push_back(value &&item)
void resize(size_type count, const value &val=value())
Resize the length of this array to count items.
value & at(size_type idx)
value(const std::wstring &value)
Create a kind::string with the given value.
value(bool value)
Create a kind::boolean with the given value.
basic_array_iterator< value, value > array_iterator
The array_iterator is applicable when kind is kind::array.
~value() noexcept
Destruction will never throw.
value(const value &source)
Copy the contents of source into a new instance.
std::pair< const std::string, value > object_value_type
The type of value stored when kind is kind::object.
const_object_iterator position
The position of the inserted node or node with the duplicate key.
value(const std::string &value)
Create a kind::string with the given value.
void swap(value &other) noexcept
Swap the value this instance represents with other.
object_iterator begin_object()
Get an iterator to the first key-value pair in this object.
void insert(std::initializer_list< std::pair< std::string, value > > items)
Insert items into this object.
bool inserted
Did the insert operation perform an insert? A value of false indicates there was a key already presen...
object_view as_object() &
View this instance as an object.
bool empty() const noexcept
Is the underlying structure empty?
friend std::string to_string(const value &)
Get a string representation of the given value.
value(const char *value)
Create a kind::string with the given value.
void pop_back()
Pop an item off the back of this array.
object_iterator erase(const_object_iterator first, const_object_iterator last)
Erase the range defined by [first, last).
array_iterator insert(const_array_iterator position, value item)
Insert an item into position on this array.
size_type erase(const std::string &key)
array_iterator begin_array()
array_iterator end_array()
value(double value)
Create a kind::decimal with the given value.
void assign(std::initializer_list< value > items)
Assign the given items to this array.
value(int64_t value)
Create a kind::integer with the given value.
void reserve(size_type count)
Reserve at least count elements in the array.
Type returned from insert operations when this has kind::object.
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_INTEGER_ALTERNATES_LIST(item)
An item list of types to also consider as an integer.
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
T extract(const value &from, const formats &fmts)
Extract a C++ value from from using the provided fmts.
@ insert
Insert the correct key/value pair as part of serialization.
kind
Describes the kind of data a value holds.
JSONV_PUBLIC value object()
Create an empty object.
JSONV_PUBLIC const value null
An instance with kind::null.
JSONV_PUBLIC value array()
Create an empty array value.
Copyright (c) 2019-2020 by Travis Gockel.
The base type for iterating over array values.
The base iterator type for iterating over object types.
basic_object_iterator(const basic_object_iterator< U, UIterator > &source, typename std::enable_if< std::is_convertible< U *, T * >::value >::type *=0)
This allows assignment from an object_iterator to a const_object_iterator.