MNX Document Model
Loading...
Searching...
No Matches
MnxdomProvenance.h
1/*
2 * Copyright (C) 2025, Robert Patterson
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22#pragma once
23
24#include <chrono>
25#include <ctime>
26#include <iomanip>
27#include <sstream>
28#include <string_view>
29
30#include "BaseTypes.h"
31
32namespace mnx {
33
35inline constexpr std::string_view MNXDOM_PROVENANCE_KEY = "mnxdom";
37inline constexpr int MNXDOM_PROVENANCE_SCHEMA_VERSION = 1;
38
39namespace detail {
40
42[[nodiscard]] inline std::string makeUtcTimestamp()
43{
44 const auto now = std::chrono::system_clock::now();
45 const std::time_t nowTime = std::chrono::system_clock::to_time_t(now);
46 std::tm utcTime {};
47#if defined(_WIN32)
48 gmtime_s(&utcTime, &nowTime);
49#else
50 gmtime_r(&nowTime, &utcTime);
51#endif
52
53 std::ostringstream out;
54 out << std::put_time(&utcTime, "%Y-%m-%dT%H:%M:%SZ");
55 return out.str();
56}
57
58} // namespace detail
59
65{
66public:
67 using Object::Object;
68
69 MnxdomGeneratorInfo(Base& parent, std::string_view key)
70 : Object(parent, key)
71 {
72 set_version(MNXDOM_VERSION);
73 constexpr std::string_view commit = MNXDOM_GIT_COMMIT;
74 if constexpr (!commit.empty()) {
75 set_commit(std::string(commit));
76 }
77 constexpr std::string_view build = MNXDOM_BUILD_ID;
78 if constexpr (!build.empty()) {
79 set_build(std::string(build));
80 }
81 }
82
83 MNX_REQUIRED_PROPERTY(std::string, version);
84 MNX_OPTIONAL_PROPERTY(std::string, build);
85 MNX_OPTIONAL_PROPERTY(std::string, commit);
86};
87
93{
94public:
95 using Object::Object;
96
97 MNX_REQUIRED_PROPERTY(std::string, name);
98 MNX_OPTIONAL_PROPERTY(std::string, version);
99 MNX_OPTIONAL_PROPERTY(std::string, build);
100 MNX_OPTIONAL_PROPERTY(std::string, commit);
101};
102
108{
109public:
110 using Object::Object;
111
112 MNX_REQUIRED_PROPERTY(std::string, format);
113 MNX_OPTIONAL_PROPERTY(std::string, version);
114 MNX_OPTIONAL_PROPERTY(std::string, filename);
115};
116
125{
126public:
127 using Object::Object;
128
129 MnxdomExtensionData(Base& parent, std::string_view key)
130 : Object(parent, key)
131 {
132 set_provenanceSchemaVersion(MNXDOM_PROVENANCE_SCHEMA_VERSION);
133 set_mnxSchema(getMnxSchemaId());
134 create_mnxdom();
135 set_createdAt(detail::makeUtcTimestamp());
136 }
137
138 MNX_REQUIRED_PROPERTY(int, provenanceSchemaVersion);
139 MNX_REQUIRED_PROPERTY(std::string, mnxSchema);
143 MNX_REQUIRED_PROPERTY(std::string, createdAt);
144 MNX_OPTIONAL_PROPERTY(std::string, modifiedAt);
145 MNX_OPTIONAL_PROPERTY(std::string, documentId);
146};
147
148} // namespace mnx
Base class wrapper for all MNX JSON nodes.
Definition BaseTypes.h:212
T parent() const
Returns the parent object for this node.
Definition BaseTypes.h:260
Identifies the client application that requested the export.
Definition MnxdomProvenance.h:93
MNX_OPTIONAL_PROPERTY(std::string, commit)
Optional source control revision for the client.
MNX_OPTIONAL_PROPERTY(std::string, build)
Optional build number or build identifier.
MNX_OPTIONAL_PROPERTY(std::string, version)
The application version.
MNX_REQUIRED_PROPERTY(std::string, name)
The application name.
Provenance data stored under _x.mnxdom.
Definition MnxdomProvenance.h:125
MNX_OPTIONAL_PROPERTY(std::string, documentId)
Optional stable document identifier, such as a UUID URN.
MNX_REQUIRED_CHILD(MnxdomGeneratorInfo, mnxdom)
The component that wrote the JSON.
MNX_REQUIRED_PROPERTY(int, provenanceSchemaVersion)
Schema version for the _x.mnxdom payload.
Object()
Constructor fresh document or detached instance.
Definition BaseTypes.h:432
MNX_REQUIRED_PROPERTY(std::string, mnxSchema)
Full MNX schema identifier used by the document.
MNX_OPTIONAL_CHILD(MnxdomSourceInfo, source)
The imported or converted source.
MNX_OPTIONAL_CHILD(MnxdomClientInfo, client)
The client application that requested the export.
MNX_REQUIRED_PROPERTY(std::string, createdAt)
UTC timestamp when the payload was created.
MNX_OPTIONAL_PROPERTY(std::string, modifiedAt)
Optional UTC timestamp of the most recent write.
Identifies the software component that wrote the MNX JSON payload.
Definition MnxdomProvenance.h:65
MNX_OPTIONAL_PROPERTY(std::string, build)
Optional build number or build identifier.
MNX_REQUIRED_PROPERTY(std::string, version)
The version of the writing component.
Object()
Constructor fresh document or detached instance.
Definition BaseTypes.h:432
MNX_OPTIONAL_PROPERTY(std::string, commit)
Optional source control revision for the writer.
Describes the source material that was converted or imported.
Definition MnxdomProvenance.h:108
MNX_OPTIONAL_PROPERTY(std::string, version)
Optional source format version.
MNX_OPTIONAL_PROPERTY(std::string, filename)
Optional original source URI or path.
MNX_REQUIRED_PROPERTY(std::string, format)
The source format, such as musicxml, midi, or manual.
Represents an MNX object, encapsulating property access.
Definition BaseTypes.h:429
Object()
Constructor fresh document or detached instance.
Definition BaseTypes.h:432
object model for MNX format
constexpr int MNXDOM_PROVENANCE_SCHEMA_VERSION
Version of the provenance payload schema used under _x.mnxdom.
Definition MnxdomProvenance.h:37
const std::string & getMnxSchemaId()
Returns the MNX schema id from the embedded schema.
Definition SchemaValidate.cpp:76
constexpr std::string_view MNXDOM_PROVENANCE_KEY
Key used for the mnxdom provenance payload inside _x.
Definition MnxdomProvenance.h:35