90 std::shared_ptr<util::IdMapping> m_idMapping;
120 inputStream >> *
root();
137 std::ifstream jsonFile;
138 jsonFile.exceptions(std::ios::failbit | std::ios::badbit);
139 jsonFile.open(inputPath);
140 if (!jsonFile.is_open()) {
141 throw std::runtime_error(
"Unable to open JSON file: " + inputPath.string());
152 void save(
const std::filesystem::path& outputPath, std::optional<int> indentSpaces)
const
155 file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
156 file.open(outputPath, std::ios::out | std::ios::binary);
157 if (!file.is_open()) {
158 throw std::runtime_error(
"Unable to write to JSON file: " + outputPath.string());
160 file <<
root()->dump(indentSpaces.value_or(-1));
167 void buildIdMapping(
const std::optional<ErrorHandler>& errorHandler = std::nullopt);
172 MNX_ASSERT_IF(!m_idMapping) {
173 throw std::logic_error(
"Call buildIdMapping before calling getIdMapping.");
182static_assert(std::is_move_constructible<mnx::Document>::value,
"Document must be move constructible");
Represents an MNX array, encapsulating property access.
Definition BaseTypes.h:483
Base class wrapper for all MNX JSON nodes.
Definition BaseTypes.h:210
T parent() const
Returns the parent object for this node.
Definition BaseTypes.h:258
const std::shared_ptr< json > & root() const
Returns the root.
Definition BaseTypes.h:288
Represents an MNX document and provides methods for loading and saving.
Definition Document.h:87
void save(const std::filesystem::path &outputPath, std::optional< int > indentSpaces) const
Saves the MNX document to a file.
Definition Document.h:152
const util::IdMapping & getIdMapping() const
Gets a reference to the ID mapping instance for the document.
Definition Document.h:170
MNX_OPTIONAL_CHILD(Array< Layout >, layouts)
List of layouts for the MNX document.
MNX_OPTIONAL_CHILD(Array< Score >, scores)
List of scores for the MNX document.
MNX_REQUIRED_CHILD(Array< Part >, parts)
List of parts for the MNX document.
void buildIdMapping(const std::optional< ErrorHandler > &errorHandler=std::nullopt)
Builds or rebuilds the ID mapping for the document, replacing any existing mapping.
Definition Implementations.cpp:75
static Document create(const std::filesystem::path &inputPath)
Creates a Document from a JSON file.
Definition Document.h:135
Document(const Document &src)
Copy constructor that zaps the id mapping, if any.
Definition Document.h:110
Document()
Constructs an empty MNX document. The resulting instance contains all required fields and should vali...
Definition Document.h:97
Document(const std::shared_ptr< json > &root)
Wrap a document around a root element.
Definition Document.h:107
Document(std::istream &inputStream)
Constructs a Document from an input stream.
Definition Document.h:118
bool hasIdMapping() const
Returns whether am ID mapping currently exists.
Definition Document.h:179
MNX_REQUIRED_CHILD(MnxMetaData, mnx)
Metadata for the MNX document.
const std::shared_ptr< json > & root() const
Returns the root.
Definition BaseTypes.h:288
MNX_REQUIRED_CHILD(Global, global)
Global data for the MNX document.
Represents the global section of an MNX document, containing global measures.
Definition Global.h:321
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:420
Object(const std::shared_ptr< json > &root, json_pointer pointer)
Wraps an Object class around an existing JSON object node.
Definition BaseTypes.h:425
Provides type-safe ID-based lookup for elements in an MNX document.
Definition IdMapping.h:54
object model for MNX format
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:197
constexpr int MNX_VERSION
The MNX version for files generated by the DOM.
Definition BaseTypes.h:194
nlohmann::ordered_json json
JSON class for MNX.
Definition BaseTypes.h:196