16 #include <type_traits>
36 class decorator_t =
void >
48 throw std::invalid_argument(
"Value identifier must be non-empty");
59 const decorator_t* decorator)
const;
71 nlohmann::json encoded;
73 if (
id.volume() != 0
u) {
74 encoded[
"volume"] =
id.volume();
76 if (
id.boundary() != 0
u) {
77 encoded[
"boundary"] =
id.boundary();
80 encoded[
"layer"] =
id.layer();
82 if (
id.approach() != 0
u) {
83 encoded[
"approach"] =
id.approach();
85 if (
id.sensitive() != 0
u) {
86 encoded[
"sensitive"] =
id.sensitive();
88 if (
id.extra() != 0
u) {
89 encoded[
"extra"] =
id.extra();
108 static constexpr
const char*
kHeaderKey =
"acts-geometry-hierarchy-map";
121 template <
typename T,
class decorator_t>
125 template <
class T,
class decorator_t>
127 [[maybe_unused]]
const T& src,
128 [[maybe_unused]] nlohmann::json&
dest) {
132 "Explicit specialization needed for each decorator_t and src T");
134 template <
class T,
class decorator_t>
136 [[maybe_unused]]
const T* src,
137 [[maybe_unused]] nlohmann::json&
dest) {
141 "Explicit specialization needed for each decorator_t and src T");
144 template <
typename value_t,
class decorator_t>
147 [[maybe_unused]]
const decorator_t* decorator)
const {
149 nlohmann::json encoded = nlohmann::json::object();
150 encoded[kHeaderKey] = nlohmann::json::object();
151 encoded[kHeaderKey][
"format-version"] = kFormatVersion;
152 encoded[kHeaderKey][
"value-identifier"] = m_valueIdentifier;
155 for (std::size_t
i = 0;
i < container.
size(); ++
i) {
156 auto entry = encodeIdentifier(container.
idAt(
i));
157 auto value_json = nlohmann::json(container.
valueAt(
i));
164 encoded[kEntriesKey] =
std::move(entries);
168 template <
typename value_t,
class decorator_t>
170 const nlohmann::json& encoded)
const ->
Container {
172 auto header = encoded.
find(kHeaderKey);
173 if (header == encoded.end()) {
174 throw std::invalid_argument(
175 "Missing header entry in json geometry hierarchy map");
177 if (header->at(
"format-version").get<
int>() != kFormatVersion) {
178 throw std::invalid_argument(
179 "Invalid format version in json geometry hierarchy map");
181 if (header->at(
"value-identifier").get<
std::string>() != m_valueIdentifier) {
182 throw std::invalid_argument(
183 "Inconsistent value identifier in Json geometry hierarchy map");
186 if (not encoded.contains(kEntriesKey)) {
187 throw std::invalid_argument(
188 "Missing entries in json geometry hierarchy map");
190 std::vector<std::pair<GeometryIdentifier, Value>> elements;
191 for (
const auto&
entry : encoded.at(kEntriesKey)) {
192 auto id = decodeIdentifier(
entry);