Skip to content

Commit 6ae7a2c

Browse files
committed
Remove unnecessary code paths in InputFile
1 parent 6f845b7 commit 6ae7a2c

File tree

3 files changed

+22
-76
lines changed

3 files changed

+22
-76
lines changed

src/core/io/src/4C_io_input_file.cpp

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ namespace Core::IO
9595
{
9696
//! Node in the tree of the associated InputFileImpl.
9797
ryml::NodeRef node;
98-
99-
//! String representation of the section in the .dat format. This is intended as a buffer
100-
//! to store the content if it should be requested via `get_as_dat_style_string()`. Do not
101-
//! assume this to contain a particular content.
102-
std::string dat_style_string{};
10398
};
10499

105100
//! Content of the section is either in the .dat format or in the yaml format.
@@ -573,55 +568,8 @@ namespace Core::IO
573568
}
574569
else
575570
{
576-
// flatten the yaml node into a string
577-
std::ostringstream ss;
578-
ss << node;
579-
// replace all the yaml markup characters with spaces to receive a dat-style string
580-
auto& str = pimpl_->section->as_yaml().dat_style_string;
581-
str = ss.str();
582-
std::replace(str.begin(), str.end(), '\n', ' ');
583-
std::replace(str.begin(), str.end(), ':', ' ');
584-
std::replace(str.begin(), str.end(), ',', ' ');
585-
std::replace(str.begin(), str.end(), '[', ' ');
586-
std::replace(str.begin(), str.end(), ']', ' ');
587-
str = Core::Utils::trim(str);
588-
589-
return std::string_view(str);
590-
}
591-
}
592-
}
593-
594-
595-
std::optional<InputParameterContainer> InputFile::Fragment::match(const InputSpec& spec) const
596-
{
597-
FOUR_C_ASSERT(pimpl_, "Implementation error: fragment is not initialized.");
598-
599-
if (std::holds_alternative<std::string_view>(pimpl_->fragment))
600-
{
601-
Core::IO::ValueParser parser{get_as_dat_style_string(),
602-
{.base_path = std::filesystem::path(pimpl_->section->file).parent_path()}};
603-
InputParameterContainer container;
604-
spec.fully_parse(parser, container);
605-
return container;
606-
}
607-
else
608-
{
609-
const auto node = std::get<ryml::ConstNodeRef>(pimpl_->fragment);
610-
// We need to check whether the node contains structured yaml or just a dat-style string.
611-
if (node.is_val())
612-
{
613-
std::string_view dat_style_string{node.val().data(), node.val().size()};
614-
Core::IO::ValueParser parser{dat_style_string,
615-
{.base_path = std::filesystem::path(pimpl_->section->file).parent_path()}};
616-
InputParameterContainer container;
617-
spec.fully_parse(parser, container);
618-
return container;
619-
}
620-
else
621-
{
622-
InputParameterContainer container;
623-
spec.match(ConstYamlNodeRef(node, pimpl_->section->file), container);
624-
return container;
571+
FOUR_C_THROW(
572+
"Yaml node does not contain a string. This legacy function is only meant for strings.");
625573
}
626574
}
627575
}

src/core/io/src/4C_io_input_file.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,6 @@ namespace Core::IO
115115
*/
116116
[[nodiscard]] std::string_view get_as_dat_style_string() const;
117117

118-
/**
119-
* Match the fragment against a given InputSpec @p spec. If the fragment does not match the
120-
* spec, an empty optional is returned. If the fragment matches the spec, an
121-
* InputParameterContainer with the parsed content is returned.
122-
*/
123-
[[nodiscard]] std::optional<InputParameterContainer> match(const InputSpec& spec) const;
124-
125118
/**
126119
* A raw pointer to implementation details. This pointer will be valid as long as the
127120
* associated InputFile object is alive.

src/core/io/tests/4C_io_input_file_test.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,37 +135,42 @@ namespace
135135
TESTING::get_support_file_path("test_files/yaml_includes/main.yaml");
136136

137137
MPI_Comm comm(MPI_COMM_WORLD);
138-
Core::IO::InputFile input{{{"INCLUDED SECTION 2", all_of({
139-
parameter<int>("a"),
140-
parameter<double>("b"),
141-
parameter<bool>("c"),
142-
})}},
138+
Core::IO::InputFile input(
139+
{{"INCLUDED SECTION 2", all_of({
140+
parameter<int>("a"),
141+
parameter<double>("b"),
142+
parameter<bool>("c"),
143+
})},
144+
{"SECTION WITH SUBSTRUCTURE", list("SECTION WITH SUBSTRUCTURE",
145+
all_of({
146+
parameter<int>("MAT"),
147+
group("THERMO",
148+
{
149+
parameter<std::vector<double>>("COND"),
150+
parameter<double>("CAPA"),
151+
}),
152+
}))}},
143153
{
144154
"MAIN SECTION",
145155
"INCLUDED SECTION 1",
146156
"INCLUDED SECTION 3",
147-
"SECTION WITH SUBSTRUCTURE",
148157
},
149-
comm};
158+
comm);
150159
input.read(input_file_name);
151160

152161
check_section_rank_0_only(input, "INCLUDED SECTION 1", std::vector<std::string>(2, "line"));
153-
check_section_rank_0_only(
154-
input, "SECTION WITH SUBSTRUCTURE", {"MAT 1 THERMO COND 1 2 3 CAPA 2"});
155162

156163
EXPECT_EQ(input.file_for_section("INCLUDED SECTION 2").filename(), "included.yaml");
157164

158-
auto spec = Core::IO::InputSpecBuilders::all_of({
159-
Core::IO::InputSpecBuilders::parameter<int>("a"),
160-
Core::IO::InputSpecBuilders::parameter<double>("b"),
161-
Core::IO::InputSpecBuilders::parameter<bool>("c"),
162-
});
163-
164165
Core::IO::InputParameterContainer container;
165166
input.match_section("INCLUDED SECTION 2", container);
166167
EXPECT_EQ(container.get<int>("a"), 1);
167168
EXPECT_EQ(container.get<double>("b"), 2.0);
168169
EXPECT_EQ(container.get<bool>("c"), true);
170+
171+
container.clear();
172+
input.match_section("SECTION WITH SUBSTRUCTURE", container);
173+
EXPECT_EQ(container.get_list("SECTION WITH SUBSTRUCTURE")[0].get<int>("MAT"), 1);
169174
}
170175

171176
} // namespace

0 commit comments

Comments
 (0)