Skip to content

Commit 4956d72

Browse files
authored
Merge pull request #1479 from sebproell/remove-string-converter
Remove outdated StringConverter tools
2 parents 475b704 + b6c859e commit 4956d72

File tree

4 files changed

+0
-792
lines changed

4 files changed

+0
-792
lines changed

src/core/io/src/4C_io_file_reader.hpp

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
/*-----------------------------------------------------------------------------------------------*/
1212
#include "4C_config.hpp"
1313

14-
#include "4C_io_string_converter.hpp"
1514
#include "4C_utils_demangle.hpp"
1615

1716
#include <fstream>
@@ -42,102 +41,6 @@ namespace Core::IO
4241
std::vector<std::vector<double>> read_csv_as_columns(
4342
int number_of_columns, std::istream& csv_stream);
4443

45-
/*!
46-
* @brief Read a @p input_stream line by line and parse each line into an object of type @p T
47-
* using `Core::IO::StringConverter<T>::Parse(line_string)`. Return a vector containing all those
48-
* objects.
49-
*
50-
* @param[in] input_stream input stream
51-
* @tparam T type of object one line is read into
52-
*/
53-
template <typename T>
54-
std::vector<T> convert_lines(std::istream& input_stream);
55-
56-
/*!
57-
* @brief Read an @p input_stream line by line and parse each line into an object of type @p T
58-
* using `Core::IO::StringConverter<T>::Parse(line_string)`. The parsed objects are then reduced
59-
* into another object of @p ReturnType. This process is also known as a `fold` over the data. You
60-
* can specify which @p operation should be performed by supplying a callable that takes the
61-
* already accumulated data of type @p ReturnType and the result of parsing a single line into a
62-
* type @p T.
63-
*
64-
* Assume you have an input stream, where each line follows the pattern `"key:val_1,val_2,val_3"`.
65-
* Those lines can be parsed into objects of type `T = std::map<int, std::array<int, 3>>`.
66-
* You want to create an `std::map<int,int>` containing the sum of values for each key.
67-
* Hence, you need an operation (e.g., a lambda function) that creates a `std::map<int, int>`
68-
* (ReturnType) from objects of type `std::map<int, std::array<int, 3>>` (T) by summing up the
69-
* array entries:
70-
*
71-
* @code {.cpp}
72-
* auto operation = [](ReducedType acc, T &&next)
73-
* {
74-
* for (const auto &[key, value] : next)
75-
* {
76-
* acc[key] = value[0] + value[1] + value[2];
77-
* }
78-
* return acc;
79-
* };
80-
* @endcode
81-
*
82-
* The desired map could then be read from the input_stream:
83-
*
84-
* @code {.cpp}
85-
* using ReducedType = std::map<int, int>;
86-
* using T = std::map<int, std::array<int, 3>>;
87-
* ReducedType converted_data = Core::IO::convert_lines<T, ReducedType>(input_stream, operator);
88-
* @endcode
89-
*
90-
* @param[in] input_stream input stream
91-
* @param[in] operation Binary operation function object that is apply to create the operated data
92-
* from the parsed data. Its signature must be:
93-
* @code {.cpp}
94-
* ReturnType operation(ReturnType a, T&& b)
95-
* @endcode
96-
* @tparam T type of object one line is read into
97-
* @tparam ReturnType type of the result created through the binary operation
98-
*/
99-
template <typename T, typename ReturnType, typename BinaryOperation>
100-
ReturnType convert_lines(std::istream& input_stream, BinaryOperation operation);
101-
102-
template <typename T>
103-
std::vector<T> convert_lines(std::istream& input_stream)
104-
{
105-
return convert_lines<T, std::vector<T>>(input_stream,
106-
[](std::vector<T> accumulator, T&& next)
107-
{
108-
accumulator.emplace_back(std::move(next));
109-
return accumulator;
110-
});
111-
}
112-
113-
template <typename T, typename ReturnType, typename BinaryOperation>
114-
ReturnType convert_lines(std::istream& input_stream, BinaryOperation operation)
115-
{
116-
std::string line_str;
117-
ReturnType operated_data;
118-
119-
// read the input stream line by line
120-
while (std::getline(input_stream, line_str))
121-
{
122-
// do not read in line if it is a header
123-
if (line_str[0] == '#') continue;
124-
125-
try
126-
{
127-
// parse line string and apply the specified operation on the parsed data
128-
T parsed_data = Core::IO::StringConverter<T>::parse(line_str);
129-
operated_data = operation(std::forward<ReturnType>(operated_data), std::move(parsed_data));
130-
}
131-
catch (...)
132-
{
133-
FOUR_C_THROW(
134-
"Could not read line '{}' from input stream. Likely the string's pattern is not "
135-
"convertible to an object of type {}",
136-
line_str.c_str(), Core::Utils::get_type_name<T>().c_str());
137-
}
138-
}
139-
return operated_data;
140-
}
14144
} // namespace Core::IO
14245

14346
FOUR_C_NAMESPACE_CLOSE

0 commit comments

Comments
 (0)