MNX Document Model
Loading...
Searching...
No Matches
mnx::util::IdMapping Class Reference

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 >
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.
 
mnx::part::Measure getPartMeasure (const mnx::global::Measure &globalMeasure, const std::string &partId) const
 Returns the part::Measure instance associated with the input global::Measure.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ IdMapping()

mnx::util::IdMapping::IdMapping ( std::shared_ptr< json documentRoot,
const std::optional< ErrorHandler > &  errorHandler = std::nullopt 
)
inlineexplicit

Constructs the index for a given document.

Parameters
documentRootShared pointer to the document's JSON root.
errorHandlerA optional callback function for handling errors.

Member Function Documentation

◆ add()

template<typename T , typename IdType >
void mnx::util::IdMapping::add ( const IdType &  id,
const T &  value 
)
inline

Adds a key to the mapping. If there is no error handler, it throws mapping_error if there is a duplicate key.

Template Parameters
TThe type to add
IdTypeThe type of id
Parameters
idThe ID to add.
valueThe value to index.
Exceptions
mapping_errorif the ID is a duplicate and there is no error handler.

◆ get()

template<typename T , typename IdType >
T mnx::util::IdMapping::get ( const IdType &  id,
const std::optional< Base > &  errorLocation = std::nullopt 
) const
inline

Looks up an object by string ID.

Template Parameters
TThe expected type (e.g., mnx::Part, mnx::Layout, mnx::sequence::Note).
IdTypeThe type of id
Parameters
idThe ID to search for.
errorLocationThe location in the document for error reporting purposes.
Returns
An instance of T if found.
Exceptions
mapping_errorif the ID is not found.

◆ getPartMeasure()

mnx::part::Measure mnx::util::IdMapping::getPartMeasure ( const mnx::global::Measure globalMeasure,
const std::string &  partId 
) const
inline

Returns the part::Measure instance associated with the input global::Measure.

Parameters
globalMeasureThe global measure for which to find the associated part measure.
partIdID of the part to search.
Returns
The associated part measure.