|
metadata 0.2.0
Modern C++23 header-only metadata container (JSON-like)
|
Ordered-by-insertion-time-ish string-keyed map of Values, with transparent string-view lookup and JSON-flavored metadata helpers.
More...
#include <object.hpp>
Public Types | |
| using | map_type = std::unordered_map< std::string, Value, detail::TransparentStringHash, std::equal_to<> > |
| Underlying associative container type. | |
| using | key_type = map_type::key_type |
Key type (always std::string). | |
| using | mapped_type = map_type::mapped_type |
Mapped value type (always Value). | |
| using | value_type = map_type::value_type |
std::pair<const key_type, mapped_type>. | |
| using | size_type = map_type::size_type |
| Unsigned size type. | |
| using | difference_type = map_type::difference_type |
| Signed difference type for iterators. | |
| using | hasher = map_type::hasher |
| Hash functor type. | |
| using | key_equal = map_type::key_equal |
| Key-equality functor type. | |
| using | reference = map_type::reference |
Reference to a stored value_type. | |
| using | const_reference = map_type::const_reference |
Const reference to a stored value_type. | |
| using | pointer = map_type::pointer |
Pointer to a stored value_type. | |
| using | const_pointer = map_type::const_pointer |
Const pointer to a stored value_type. | |
| using | iterator = map_type::iterator |
| Mutable iterator type. | |
| using | const_iterator = map_type::const_iterator |
| Const iterator type. | |
Public Member Functions | |
| Object ()=default | |
Construct an empty Object. | |
| Object (const std::initializer_list< value_type > il) | |
| Construct from a braced list of key/value pairs. | |
| template<class InputIt > | |
| Object (InputIt first, InputIt last) | |
| Construct from an iterator range of key/value pairs. | |
| iterator | begin () noexcept |
| Iterator to the first element. | |
| const_iterator | begin () const noexcept |
| Const iterator to the first element. | |
| const_iterator | cbegin () const noexcept |
| Const iterator to the first element. | |
| iterator | end () noexcept |
| Iterator past the last element. | |
| const_iterator | end () const noexcept |
| Const iterator past the last element. | |
| const_iterator | cend () const noexcept |
| Const iterator past the last element. | |
| bool | empty () const noexcept |
| True if the object has no entries. | |
| size_type | size () const noexcept |
| Number of entries. | |
| void | clear () noexcept |
| Remove all entries. | |
| void | reserve (const size_type n) |
Reserve storage for at least n entries. | |
| Value & | operator[] (const std::string_view key) |
Access (and default-insert if missing) the value for key. | |
| Value & | operator[] (const std::string &key) |
Access (and default-insert if missing) the value for key. | |
| Value & | operator[] (std::string &&key) |
Access (and default-insert if missing) the value for key. | |
| Value & | operator[] (const char *key) |
Access (and default-insert if missing) the value for key. | |
| Value & | at (const std::string_view key) |
Access the value for key; throws std::out_of_range if missing. | |
| const Value & | at (const std::string_view key) const |
Access the value for key; throws std::out_of_range if missing. | |
| iterator | find (const std::string_view key) |
Find an entry by key, returning end() on miss. | |
| const_iterator | find (const std::string_view key) const |
Find an entry by key, returning end() on miss. | |
| size_type | count (const std::string_view key) const |
Return 1 if key is present, otherwise 0. | |
| template<class K , class V > | |
| std::pair< iterator, bool > | insert_or_assign (K &&k, V &&v) |
Insert or overwrite the entry for k. | |
| template<class K , class V > | |
| std::pair< iterator, bool > | emplace (K &&k, V &&v) |
Construct an entry in place; no effect if k already exists. | |
| std::pair< iterator, bool > | insert (const value_type &v) |
| Insert an entry; no effect if the key already exists. | |
| std::pair< iterator, bool > | insert (value_type &&v) |
| Insert an entry; no effect if the key already exists. | |
| size_type | erase (const std::string_view key) |
Erase the entry for key; returns 1 if removed, otherwise 0. | |
| iterator | erase (const const_iterator pos) |
Erase the entry at pos; returns the next iterator. | |
| bool | contains (const std::string_view key) const |
True if key is present in the object. | |
| Value * | find_ptr (const std::string_view key) |
Return a pointer to the value for key, or nullptr if absent. | |
| const Value * | find_ptr (const std::string_view key) const |
Return a pointer to the value for key, or nullptr if absent. | |
| Value & | require (const std::string_view key) |
Return the value for key; throws missing_key_error if absent. | |
| const Value & | require (const std::string_view key) const |
Return the value for key; throws missing_key_error if absent. | |
| std::string & | require_string (const std::string_view key) |
Return the string at key; throws on missing key or type mismatch. | |
| const std::string & | require_string (const std::string_view key) const |
Return the string at key; throws on missing key or type mismatch. | |
| Array & | require_array (const std::string_view key) |
Return the array at key; throws on missing key or type mismatch. | |
| const Array & | require_array (const std::string_view key) const |
Return the array at key; throws on missing key or type mismatch. | |
| Object & | require_object (const std::string_view key) |
Return the nested object at key; throws on missing key or type mismatch. | |
| const Object & | require_object (const std::string_view key) const |
Return the nested object at key; throws on missing key or type mismatch. | |
| const std::string * | get_string_if (const std::string_view key) const |
Pointer to the string at key, or nullptr if absent or wrong type. | |
| const Array * | get_array_if (const std::string_view key) const |
Pointer to the array at key, or nullptr if absent or wrong type. | |
| const Object * | get_object_if (const std::string_view key) const |
Pointer to the nested object at key, or nullptr if absent or wrong type. | |
| Value * | find_path (std::string_view path) |
Find a value by dotted path (e.g. "a.b[0].c"), or nullptr on miss. | |
| const Value * | find_path (std::string_view path) const |
Find a value by dotted path (e.g. "a.b[0].c"), or nullptr on miss. | |
| const Value & | require_path (std::string_view path) const |
Return the value at path; throws on miss or malformed path. | |
| Value & | require_path (std::string_view path) |
Return the value at path; throws on miss or malformed path. | |
| bool | contains_path (std::string_view path) const |
True if path resolves to a value in the object. | |
| void | merge (const Object &source) |
Deep-merge source into this object; nested objects recurse, other alternatives are overwritten, and arrays are replaced wholesale. | |
| map_type & | raw () noexcept |
Access the underlying std::unordered_map. | |
| const map_type & | raw () const noexcept |
Access the underlying std::unordered_map. | |
Friends | |
| bool | operator== (const Object &a, const Object &b) noexcept |
Deep value-equality compare two Objects. | |
| bool | operator!= (const Object &a, const Object &b) noexcept |
Negation of operator==. | |
Ordered-by-insertion-time-ish string-keyed map of Values, with transparent string-view lookup and JSON-flavored metadata helpers.