Skip to content

Commit d99840f

Browse files
committed
Use our yaml wrapper to emit yaml
1 parent a1b580d commit d99840f

File tree

5 files changed

+139
-128
lines changed

5 files changed

+139
-128
lines changed

src/core/io/src/4C_io_input_spec.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ void Core::IO::InputSpec::emit_metadata(YamlNodeRef yaml) const
8888
{
8989
FOUR_C_ASSERT(pimpl_, "InputSpec is empty.");
9090

91-
auto root = yaml.node;
92-
pimpl_->emit_metadata(root);
91+
pimpl_->emit_metadata(yaml);
9392
}
9493

9594
Core::IO::Internal::InputSpecImpl& Core::IO::InputSpec::impl()

src/core/io/src/4C_io_input_spec_builders.cpp

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "4C_utils_string.hpp"
1111

1212
#include <format>
13-
#include <iostream>
1413
#include <numeric>
1514
#include <set>
1615
#include <unordered_map>
@@ -751,25 +750,25 @@ void Core::IO::Internal::GroupSpec::print(std::ostream& stream, std::size_t inde
751750
}
752751
}
753752

754-
void Core::IO::Internal::GroupSpec::emit_metadata(ryml::NodeRef node) const
753+
void Core::IO::Internal::GroupSpec::emit_metadata(YamlNodeRef node) const
755754
{
756-
node |= ryml::MAP;
757-
node["name"] << name;
755+
node.node |= ryml::MAP;
756+
node.node["name"] << name;
758757

759-
node["type"] = "group";
758+
node.node["type"] = "group";
760759
if (!data.description.empty())
761760
{
762-
node["description"] << data.description;
761+
node.node["description"] << data.description;
763762
}
764-
emit_value_as_yaml(node["required"], data.required.value());
765-
emit_value_as_yaml(node["defaultable"], data.defaultable);
766-
node["specs"] |= ryml::SEQ;
763+
emit_value_as_yaml(node.wrap(node.node["required"]), data.required.value());
764+
emit_value_as_yaml(node.wrap(node.node["defaultable"]), data.defaultable);
765+
node.node["specs"] |= ryml::SEQ;
767766
{
768767
for (const auto& spec : specs)
769768
{
770-
auto child = node["specs"].append_child();
769+
auto child = node.node["specs"].append_child();
771770
child |= ryml::MAP;
772-
spec.impl().emit_metadata(child);
771+
spec.impl().emit_metadata(node.wrap(child));
773772
};
774773
}
775774
}
@@ -864,23 +863,23 @@ void Core::IO::Internal::AllOfSpec::print(std::ostream& stream, std::size_t inde
864863
}
865864
}
866865

867-
void Core::IO::Internal::AllOfSpec::emit_metadata(ryml::NodeRef node) const
866+
void Core::IO::Internal::AllOfSpec::emit_metadata(YamlNodeRef node) const
868867
{
869-
node |= ryml::MAP;
868+
node.node |= ryml::MAP;
870869

871-
node["type"] = "all_of";
870+
node.node["type"] = "all_of";
872871
if (!data.description.empty())
873872
{
874-
node["description"] << data.description;
873+
node.node["description"] << data.description;
875874
}
876-
emit_value_as_yaml(node["required"], data.required.value());
877-
node["specs"] |= ryml::SEQ;
875+
emit_value_as_yaml(node.wrap(node.node["required"]), data.required.value());
876+
node.node["specs"] |= ryml::SEQ;
878877
{
879878
for (const auto& spec : specs)
880879
{
881-
auto child = node["specs"].append_child();
880+
auto child = node.node["specs"].append_child();
882881
child |= ryml::MAP;
883-
spec.impl().emit_metadata(child);
882+
spec.impl().emit_metadata(node.wrap(child));
884883
}
885884
}
886885
}
@@ -1021,20 +1020,20 @@ void Core::IO::Internal::OneOfSpec::print(std::ostream& stream, std::size_t inde
10211020
}
10221021
}
10231022

1024-
void Core::IO::Internal::OneOfSpec::emit_metadata(ryml::NodeRef node) const
1023+
void Core::IO::Internal::OneOfSpec::emit_metadata(YamlNodeRef node) const
10251024
{
1026-
node |= ryml::MAP;
1025+
node.node |= ryml::MAP;
10271026

1028-
node["type"] << "one_of";
1027+
node.node["type"] << "one_of";
10291028
if (!data.description.empty())
10301029
{
1031-
node["description"] << data.description;
1030+
node.node["description"] << data.description;
10321031
}
1033-
node["specs"] |= ryml::SEQ;
1032+
node.node["specs"] |= ryml::SEQ;
10341033
for (const auto& spec : specs)
10351034
{
1036-
auto child = node["specs"].append_child();
1037-
spec.impl().emit_metadata(child);
1035+
auto child = node.node["specs"].append_child();
1036+
spec.impl().emit_metadata(node.wrap(child));
10381037
}
10391038
}
10401039

@@ -1153,21 +1152,21 @@ void Core::IO::Internal::ListSpec::print(std::ostream& stream, std::size_t inden
11531152
spec.impl().print(stream, indent + 2);
11541153
}
11551154

1156-
void Core::IO::Internal::ListSpec::emit_metadata(ryml::NodeRef node) const
1155+
void Core::IO::Internal::ListSpec::emit_metadata(YamlNodeRef node) const
11571156
{
1158-
node |= ryml::MAP;
1157+
node.node |= ryml::MAP;
11591158

1160-
node["name"] << name;
1159+
node.node["name"] << name;
11611160

1162-
node["type"] << "list";
1161+
node.node["type"] << "list";
11631162
if (!data.description.empty())
11641163
{
1165-
node["description"] << Core::Utils::trim(data.description);
1164+
node.node["description"] << Core::Utils::trim(data.description);
11661165
}
1167-
emit_value_as_yaml(node["required"], data.required);
1168-
if (data.size > 0) node["size"] << data.size;
1169-
node["spec"] |= ryml::MAP;
1170-
spec.impl().emit_metadata(node["spec"]);
1166+
emit_value_as_yaml(node.wrap(node.node["required"]), data.required);
1167+
if (data.size > 0) node.node["size"] << data.size;
1168+
node.node["spec"] |= ryml::MAP;
1169+
spec.impl().emit_metadata(node.wrap(node.node["spec"]));
11711170
}
11721171

11731172

src/core/io/src/4C_io_input_spec_builders.hpp

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ namespace Core::IO
179179
auto entry = node["choices"].append_child();
180180
// Write every choice entry as a map to easily extend the information at a later point.
181181
entry |= ryml::MAP;
182-
emit_value_as_yaml(entry["name"], choice_string);
182+
emit_value_as_yaml(YamlNodeRef(entry["name"], ""), choice_string);
183183
}
184184
}
185185
};
@@ -225,7 +225,7 @@ namespace Core::IO
225225
// Pull up the std::optional aspect. The fact that this type wraps another type is specific
226226
// to C++ and not relevant to other tools. Simply knowing that a type can be empty is
227227
// enough for them.
228-
emit_value_as_yaml(node["noneable"], true);
228+
emit_value_as_yaml(YamlNodeRef{node["noneable"], ""}, true);
229229
YamlTypeEmitter<T>{}(node, size);
230230
}
231231
};
@@ -400,7 +400,7 @@ namespace Core::IO
400400

401401
//! Emit metadata. This function always emits into a map, i.e., the implementation must
402402
//! insert keys and values into the yaml emitter.
403-
virtual void emit_metadata(ryml::NodeRef node) const = 0;
403+
virtual void emit_metadata(YamlNodeRef node) const = 0;
404404

405405
virtual bool emit(YamlNodeRef node, const InputParameterContainer&,
406406
const InputSpecEmitOptions& options) const = 0;
@@ -473,7 +473,7 @@ namespace Core::IO
473473
}
474474
}
475475

476-
void emit_metadata(ryml::NodeRef node) const override { wrapped.emit_metadata(node); }
476+
void emit_metadata(YamlNodeRef node) const override { wrapped.emit_metadata(node); }
477477

478478
bool emit(YamlNodeRef node, const InputParameterContainer& container,
479479
const InputSpecEmitOptions& options) const override
@@ -751,7 +751,7 @@ namespace Core::IO
751751
void parse(ValueParser& parser, InputParameterContainer& container) const;
752752
bool match(ConstYamlNodeRef node, InputParameterContainer& container,
753753
IO::Internal::MatchEntry& match_entry) const;
754-
void emit_metadata(ryml::NodeRef node) const;
754+
void emit_metadata(YamlNodeRef node) const;
755755
bool emit(YamlNodeRef node, const InputParameterContainer& container,
756756
const InputSpecEmitOptions& options) const;
757757
[[nodiscard]] bool has_correct_size(
@@ -779,7 +779,7 @@ namespace Core::IO
779779
bool match(ConstYamlNodeRef node, InputParameterContainer& container,
780780
IO::Internal::MatchEntry& match_entry) const;
781781
void print(std::ostream& stream, std::size_t indent) const;
782-
void emit_metadata(ryml::NodeRef node) const;
782+
void emit_metadata(YamlNodeRef node) const;
783783
bool emit(YamlNodeRef node, const InputParameterContainer& container,
784784
const InputSpecEmitOptions& options) const;
785785
};
@@ -806,7 +806,7 @@ namespace Core::IO
806806
bool match(ConstYamlNodeRef node, InputParameterContainer& container,
807807
IO::Internal::MatchEntry& match_entry) const;
808808
void print(std::ostream& stream, std::size_t indent) const;
809-
void emit_metadata(ryml::NodeRef node) const;
809+
void emit_metadata(YamlNodeRef node) const;
810810
bool emit(YamlNodeRef node, const InputParameterContainer& container,
811811
const InputSpecEmitOptions& options) const;
812812
void set_default_value(InputParameterContainer& container) const;
@@ -823,7 +823,7 @@ namespace Core::IO
823823
IO::Internal::MatchEntry& match_entry) const;
824824
void set_default_value(InputParameterContainer& container) const;
825825
void print(std::ostream& stream, std::size_t indent) const;
826-
void emit_metadata(ryml::NodeRef node) const;
826+
void emit_metadata(YamlNodeRef node) const;
827827
bool emit(YamlNodeRef node, const InputParameterContainer& container,
828828
const InputSpecEmitOptions& options) const;
829829
};
@@ -838,7 +838,7 @@ namespace Core::IO
838838
IO::Internal::MatchEntry& match_entry) const;
839839
void set_default_value(InputParameterContainer& container) const;
840840
void print(std::ostream& stream, std::size_t indent) const;
841-
void emit_metadata(ryml::NodeRef node) const;
841+
void emit_metadata(YamlNodeRef node) const;
842842
bool emit(YamlNodeRef node, const InputParameterContainer& container,
843843
const InputSpecEmitOptions& options) const;
844844
};
@@ -863,7 +863,7 @@ namespace Core::IO
863863

864864
void print(std::ostream& stream, std::size_t indent) const;
865865

866-
void emit_metadata(ryml::NodeRef node) const;
866+
void emit_metadata(YamlNodeRef node) const;
867867
bool emit(YamlNodeRef node, const InputParameterContainer& container,
868868
const InputSpecEmitOptions& options) const;
869869
};
@@ -882,7 +882,7 @@ namespace Core::IO
882882
IO::Internal::MatchEntry& match_entry) const;
883883
void set_default_value(InputParameterContainer& container) const;
884884
void print(std::ostream& stream, std::size_t indent) const;
885-
void emit_metadata(ryml::NodeRef node) const;
885+
void emit_metadata(YamlNodeRef node) const;
886886
bool emit(YamlNodeRef node, const InputParameterContainer& container,
887887
const InputSpecEmitOptions& options) const;
888888
};
@@ -1463,13 +1463,13 @@ bool Core::IO::Internal::ParameterSpec<T>::match(ConstYamlNodeRef node,
14631463

14641464

14651465
template <Core::IO::SupportedType T>
1466-
void Core::IO::Internal::ParameterSpec<T>::emit_metadata(ryml::NodeRef node) const
1466+
void Core::IO::Internal::ParameterSpec<T>::emit_metadata(YamlNodeRef node) const
14671467
{
1468-
node |= ryml::MAP;
1469-
node["name"] << name;
1468+
node.node |= ryml::MAP;
1469+
node.node["name"] << name;
14701470

14711471
if constexpr (rank<T>() == 0)
1472-
IO::Internal::emit_type_as_yaml<StoredType>(node);
1472+
IO::Internal::emit_type_as_yaml<StoredType>(node.node);
14731473
else
14741474
{
14751475
struct DynamicSizeVisitor
@@ -1486,17 +1486,17 @@ void Core::IO::Internal::ParameterSpec<T>::emit_metadata(ryml::NodeRef node) con
14861486
{
14871487
size_info[i] = std::visit(DynamicSizeVisitor{}, data.size[i]);
14881488
}
1489-
IO::Internal::emit_type_as_yaml<StoredType>(node, size_info);
1489+
IO::Internal::emit_type_as_yaml<StoredType>(node.node, size_info);
14901490
}
14911491

14921492
if (!data.description.empty())
14931493
{
1494-
emit_value_as_yaml(node["description"], data.description);
1494+
emit_value_as_yaml(node.wrap(node.node["description"]), data.description);
14951495
}
1496-
emit_value_as_yaml(node["required"], !(data.default_value.index() == 1));
1496+
emit_value_as_yaml(node.wrap(node.node["required"]), !(data.default_value.index() == 1));
14971497
if (data.default_value.index() == 1)
14981498
{
1499-
emit_value_as_yaml(node["default"], std::get<1>(data.default_value));
1499+
emit_value_as_yaml(node.wrap(node.node["default"]), std::get<1>(data.default_value));
15001500
}
15011501
}
15021502

@@ -1513,7 +1513,7 @@ bool Core::IO::Internal::ParameterSpec<T>::emit(YamlNodeRef node,
15131513
{
15141514
auto value_node = node.node.append_child();
15151515
value_node << ryml::key(name);
1516-
emit_value_as_yaml(value_node, *value);
1516+
emit_value_as_yaml(node.wrap(value_node), *value);
15171517
}
15181518
return true;
15191519
}
@@ -1524,7 +1524,7 @@ bool Core::IO::Internal::ParameterSpec<T>::emit(YamlNodeRef node,
15241524
{
15251525
auto value_node = node.node.append_child();
15261526
value_node << ryml::key(name);
1527-
emit_value_as_yaml(value_node, std::get<1>(data.default_value));
1527+
emit_value_as_yaml(node.wrap(value_node), std::get<1>(data.default_value));
15281528
}
15291529
return true;
15301530
}
@@ -1691,35 +1691,35 @@ void Core::IO::Internal::DeprecatedSelectionSpec<T>::print(
16911691
}
16921692

16931693
template <typename T>
1694-
void Core::IO::Internal::DeprecatedSelectionSpec<T>::emit_metadata(ryml::NodeRef node) const
1694+
void Core::IO::Internal::DeprecatedSelectionSpec<T>::emit_metadata(YamlNodeRef node) const
16951695
{
1696-
node |= ryml::MAP;
1697-
node["name"] << name;
1696+
node.node |= ryml::MAP;
1697+
node.node["name"] << name;
16981698

1699-
if constexpr (OptionalType<T>) emit_value_as_yaml(node["noneable"], true);
1700-
node["type"] = "enum";
1699+
if constexpr (OptionalType<T>) emit_value_as_yaml(node.wrap(node.node["noneable"]), true);
1700+
node.node["type"] = "enum";
17011701

17021702
if (!data.description.empty())
17031703
{
1704-
emit_value_as_yaml(node["description"], data.description);
1704+
emit_value_as_yaml(node.wrap(node.node["description"]), data.description);
17051705
}
1706-
emit_value_as_yaml(node["required"], !(data.default_value.index() == 1));
1706+
emit_value_as_yaml(node.wrap(node.node["required"]), !(data.default_value.index() == 1));
17071707
if (data.default_value.index() == 1)
17081708
{
17091709
// Find the choice that corresponds to the default value.
17101710
auto default_value_it = std::find_if(choices.begin(), choices.end(),
17111711
[&](const auto& choice) { return choice.second == std::get<1>(data.default_value); });
17121712
FOUR_C_ASSERT(
17131713
default_value_it != choices.end(), "Internal error: default value not found in choices.");
1714-
emit_value_as_yaml(node["default"], default_value_it->first);
1714+
emit_value_as_yaml(node.wrap(node.node["default"]), default_value_it->first);
17151715
}
1716-
node["choices"] |= ryml::SEQ;
1716+
node.node["choices"] |= ryml::SEQ;
17171717
for (const auto& [choice_string, _] : choices)
17181718
{
1719-
auto entry = node["choices"].append_child();
1719+
auto entry = node.node["choices"].append_child();
17201720
// Write every choice entry as a map to easily extend the information at a later point.
17211721
entry |= ryml::MAP;
1722-
emit_value_as_yaml(entry["name"], choice_string);
1722+
emit_value_as_yaml(node.wrap(entry["name"]), choice_string);
17231723
}
17241724
}
17251725

@@ -1737,7 +1737,7 @@ bool Core::IO::Internal::DeprecatedSelectionSpec<T>::emit(YamlNodeRef node,
17371737
{
17381738
auto value_node = node.node.append_child();
17391739
value_node << ryml::key(key);
1740-
emit_value_as_yaml(value_node, choice.first);
1740+
emit_value_as_yaml(node.wrap(value_node), choice.first);
17411741
return true;
17421742
}
17431743
}
@@ -1860,28 +1860,28 @@ void Core::IO::Internal::SelectionSpec<T>::print(std::ostream& stream, std::size
18601860

18611861
template <typename T>
18621862
requires(std::is_enum_v<T>)
1863-
void Core::IO::Internal::SelectionSpec<T>::emit_metadata(ryml::NodeRef node) const
1863+
void Core::IO::Internal::SelectionSpec<T>::emit_metadata(YamlNodeRef node) const
18641864
{
1865-
node |= ryml::MAP;
1866-
node["name"] << group_name;
1865+
node.node |= ryml::MAP;
1866+
node.node["name"] << group_name;
18671867

1868-
if constexpr (OptionalType<T>) emit_value_as_yaml(node["noneable"], true);
1869-
node["type"] = "selection";
1868+
if constexpr (OptionalType<T>) emit_value_as_yaml(node.wrap(node.node["noneable"]), true);
1869+
node.node["type"] = "selection";
18701870

18711871
if (!data.description.empty())
18721872
{
1873-
emit_value_as_yaml(node["description"], data.description);
1873+
emit_value_as_yaml(node.wrap(node.node["description"]), data.description);
18741874
}
1875-
emit_value_as_yaml(node["required"], data.required);
1876-
node["selector"] << based_on.selector;
1875+
emit_value_as_yaml(node.wrap(node.node["required"]), data.required);
1876+
node.node["selector"] << based_on.selector;
18771877

1878-
node["choices"] |= ryml::SEQ;
1878+
node.node["choices"] |= ryml::SEQ;
18791879
for (const auto& [choice, spec] : based_on.choices)
18801880
{
1881-
auto entry = node["choices"].append_child();
1881+
auto entry = node.node["choices"].append_child();
18821882
entry |= ryml::MAP;
1883-
emit_value_as_yaml(entry["name"], choice);
1884-
spec.impl().emit_metadata(entry["spec"]);
1883+
emit_value_as_yaml(node.wrap(entry["name"]), choice);
1884+
spec.impl().emit_metadata(node.wrap(entry["spec"]));
18851885
}
18861886
}
18871887

0 commit comments

Comments
 (0)