Base class wrapper for all MNX JSON nodes.
More...
#include <BaseTypes.h>
|
| Base (const Base &src) |
| Copy constructor.
|
|
| Base (Base &&src) noexcept |
| Move constructor.
|
|
Base & | operator= (const Base &src) |
| Copy assignment operator.
|
|
Base & | operator= (Base &&src) |
| Move assignment operator.
|
|
std::string | dump (int indents=-1) |
| Dumps the branch to a string. Useful in debugging.
|
|
template<typename T > |
T | parent () const |
| Returns the parent object for this node.
|
|
template<typename T > |
std::optional< T > | getEnclosingElement () const |
| Returns the enclosing array element for this instance.
|
|
json_pointer | pointer () const |
| Returns the json_pointer for this node.
|
|
|
json & | ref () const |
| Convert this node for retrieval.
|
|
json & | ref () |
| Access the JSON node for modification.
|
|
const std::shared_ptr< json > & | root () const |
| Returns the root.
|
|
| Base (const std::shared_ptr< json > &root, json_pointer pointer) |
| Wrap a Base instance around a specific JSON reference using a json_pointer.
|
|
| Base (json &&jsonRef, Base &parent, const std::string_view &key) |
| Construct a Base reference as a child inside a parent node.
|
|
template<typename T > |
T | getChild (const std::string_view &key) const |
| Retrieves and validates a required child node.
|
|
template<typename T > |
T | setChild (const std::string_view &key, const T &value) |
| Sets a child node.
|
|
template<typename T > |
std::optional< T > | getOptionalChild (const std::string_view &key) const |
| Retrieves an optional child node.
|
|
|
class | validation::SemanticValidator |
|
Base class wrapper for all MNX JSON nodes.
◆ Base() [1/2]
Wrap a Base instance around a specific JSON reference using a json_pointer.
- Parameters
-
root | Reference to the root JSON object. |
pointer | JSON pointer to the specific node. |
◆ Base() [2/2]
mnx::Base::Base |
( |
json && |
jsonRef, |
|
|
Base & |
parent, |
|
|
const std::string_view & |
key |
|
) |
| |
|
inlineprotected |
Construct a Base reference as a child inside a parent node.
- Parameters
-
jsonRef | Rvalue reference to a new JSON object or array. |
parent | Reference to the parent instance. |
key | The key under which the new node is stored. |
◆ dump()
std::string mnx::Base::dump |
( |
int |
indents = -1 | ) |
|
|
inline |
Dumps the branch to a string. Useful in debugging.
- Parameters
-
indents | Number of indents or -1 for no indents
|
◆ getChild()
template<typename T >
T mnx::Base::getChild |
( |
const std::string_view & |
key | ) |
const |
|
inlineprotected |
Retrieves and validates a required child node.
- Template Parameters
-
- Parameters
-
key | The key of the child node. |
- Returns
- An instance of the requested type.
- Exceptions
-
std::runtime_error | if the key is missing or the type is incorrect. |
◆ getEnclosingElement()
template<typename T >
std::optional< T > mnx::Base::getEnclosingElement |
( |
| ) |
const |
Returns the enclosing array element for this instance.
- Template Parameters
-
T | The type to find. A limited list of types are supported, including Part and Sequence. Others may be added as needed. |
- Returns
- the enclosing element, or std::nullopt if not found.
◆ getOptionalChild()
template<typename T >
std::optional< T > mnx::Base::getOptionalChild |
( |
const std::string_view & |
key | ) |
const |
|
inlineprotected |
Retrieves an optional child node.
- Template Parameters
-
- Parameters
-
key | The key of the child node. |
- Returns
- An
std::optional<T>
, or std::nullopt
if the node does not exist or is invalid.
- Exceptions
-
std::runtime_error | if the type is incorrect. |
◆ parent()
template<typename T >
T mnx::Base::parent |
( |
| ) |
const |
|
inline |
Returns the parent object for this node.
- Template Parameters
-
T | The type to create. Must correctly match whether it is an array or object. |
- Exceptions
-
std::invalid_argument | if the type of T does not match the type of the underlying pointer. |
◆ ref() [1/2]
json & mnx::Base::ref |
( |
| ) |
|
|
inlineprotected |
Access the JSON node for modification.
- Returns
- A reference to the JSON node.
◆ ref() [2/2]
json & mnx::Base::ref |
( |
| ) |
const |
|
inlineprotected |
Convert this node for retrieval.
- Returns
- A reference to the JSON node.
◆ setChild()
template<typename T >
T mnx::Base::setChild |
( |
const std::string_view & |
key, |
|
|
const T & |
value |
|
) |
| |
|
inlineprotected |
Sets a child node.
- Template Parameters
-
- Parameters
-
key | The key of the child node. |
value | The value to set. |
- Returns
- The newly created child.