|
MNX Document Model
|
Provides type-safe ID-based lookup for elements in an MNX document. More...
#include <IdMapping.h>
Public Member Functions | |
| IdMapping (std::shared_ptr< json > documentRoot, const std::optional< ErrorHandler > &errorHandler=std::nullopt) | |
| Constructs the index for a given document. | |
| template<typename T , typename IdType > | |
| T | get (const IdType &id, const std::optional< Base > &errorLocation=std::nullopt) const |
| Looks up an object by string ID. | |
| template<typename T , typename IdType > | |
| bool | exists (const IdType &id) const |
| Returns whether the specified ID exists in the mapping. | |
| template<typename T , typename IdType > | |
| void | add (const IdType &id, const T &value) |
| Adds a key to the mapping. If there is no error handler, it throws mapping_error if there is a duplicate key. | |
Provides type-safe ID-based lookup for elements in an MNX document.
Constructed from an mnx::Document, the IdMapping scans the document to index all identifiable elements by ID or number. Supports lookup by type.
|
inlineexplicit |
Constructs the index for a given document.
| documentRoot | Shared pointer to the document's JSON root. |
| errorHandler | A optional callback function for handling errors. |
|
inline |
Adds a key to the mapping. If there is no error handler, it throws mapping_error if there is a duplicate key.
| T | The type to add |
| IdType | The type of id |
| id | The ID to add. |
| value | The value to index. |
| mapping_error | if the ID is a duplicate and there is no error handler. |
|
inline |
Looks up an object by string ID.
| T | The expected type (e.g., mnx::Part, mnx::Layout, mnx::sequence::Note). |
| IdType | The type of id |
| id | The ID to search for. |
| errorLocation | The location in the document for error reporting purposes. |
| mapping_error | if the ID is not found. |