FDL Core Library
ASC Framing Decision List — C/C++ Reference Implementation
Loading...
Searching...
No Matches
fdl_doc.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024-present American Society Of Cinematographers
2// SPDX-License-Identifier: Apache-2.0
10#ifndef FDL_DOC_INTERNAL_H
11#define FDL_DOC_INTERNAL_H
12
13#include <jsoncons/json.hpp>
14#include <mutex>
15#include <string>
16
17#include "fdl_handles.h"
18
19namespace fdl::detail {
20
22using ojson = jsoncons::ojson;
23
25class Document {
26public:
27 Document() = default;
28
33 explicit Document(ojson data) : data_(std::move(data)) {}
34
41 static Document parse(const char* json_str, size_t json_len);
42
47 [[nodiscard]] const ojson& data() const { return data_; }
52 [[nodiscard]] ojson& data() { return data_; }
53
58 [[nodiscard]] std::string get_uuid() const;
63 [[nodiscard]] std::string get_fdl_creator() const;
64
73 [[nodiscard]] std::string to_canonical_json(int indent = constants::kDefaultJsonIndent) const;
74
75private:
76 ojson data_;
77};
78
79} // namespace fdl::detail
80
87
94struct doc_lock {
95 std::unique_lock<std::mutex> lock_;
101 explicit doc_lock(const fdl_doc* doc) {
102 if (doc != nullptr) {
103 lock_ = std::unique_lock<std::mutex>(doc->mtx);
104 }
105 }
106};
107
108#endif // FDL_DOC_INTERNAL_H
Internal document class wrapping the JSON data tree.
Definition fdl_doc.h:25
std::string get_fdl_creator() const
Get fdl_creator from the document.
Definition fdl_doc.cpp:27
Document(ojson data)
Construct from an existing JSON tree.
Definition fdl_doc.h:33
std::string get_uuid() const
Get UUID from the document.
Definition fdl_doc.cpp:20
ojson & data()
Access the internal JSON data (mutable).
Definition fdl_doc.h:52
const ojson & data() const
Access the internal JSON data (const).
Definition fdl_doc.h:47
std::string to_canonical_json(int indent=constants::kDefaultJsonIndent) const
Canonical JSON serialization.
Definition fdl_doc.cpp:34
static Document parse(const char *json_str, size_t json_len)
Parse JSON string.
Definition fdl_doc.cpp:15
jsoncons::ojson ojson
Alias for ordered JSON type.
Definition fdl_accessors_api.cpp:23
jsoncons::ojson ojson
Use ojson (ordered JSON) to preserve key insertion order for canonical serialization.
Definition fdl_builder.h:22
Internal handle types and handle cache for opaque FDL sub-objects.
RAII lock helper for per-document synchronization.
Definition fdl_doc.h:94
doc_lock(const fdl_doc *doc)
Acquire the document's mutex.
Definition fdl_doc.h:101
std::unique_lock< std::mutex > lock_
Held lock (empty if doc was null).
Definition fdl_doc.h:95
Opaque handle definition — shared across ABI translation units.
Definition fdl_doc.h:82
fdl::detail::Document doc
Document data tree.
Definition fdl_doc.h:83
fdl_handle_cache handles
Cache of sub-object handles.
Definition fdl_doc.h:84
std::mutex mtx
Per-document mutex for thread safety.
Definition fdl_doc.h:85
Cache container for all handle types — lives on fdl_doc.
Definition fdl_handles.h:121