4 #ifndef DP3_COMMON_VALUE_PER_STATION_PARSING_H_
5 #define DP3_COMMON_VALUE_PER_STATION_PARSING_H_
13 #include <aocommon/logger.h>
14 #include <aocommon/uvector.h>
27 template <
typename ValueType>
29 const std::string pattern_string,
30 std::span<const std::string> station_names) {
34 aocommon::UVector<bool> is_selected(station_names.size(),
false);
35 const std::vector<std::string> patterns(
37 for (
const std::string& pattern : patterns) {
39 const auto SetSelected = [&](
bool new_value,
const std::string& pattern) {
40 const std::regex pattern_regex(pattern);
41 for (
size_t i = 0; i < station_names.size(); ++i) {
42 if (std::regex_match(station_names[i], pattern_regex)) {
43 is_selected[i] = new_value;
48 if (pattern.size() > 1 && (pattern[0] ==
'!' || pattern[0] ==
'^')) {
54 aocommon::Logger::Warn <<
"No matching stations found for pattern "
58 for (
size_t i = 0; i < is_selected.size(); ++i) {
59 if (is_selected[i]) result[i] = value;
78 template <
typename ValueType>
80 std::span<const std::string> string_list,
81 std::span<const std::string> station_names) {
82 assert(result.size() == station_names.size());
84 for (
const std::string& stations_value : string_list) {
85 const size_t colon = stations_value.find(
':');
86 if (colon == std::string::npos)
87 throw std::runtime_error(
88 "Items of station-value lists must be of the form "
89 "'station-pattern:value'. Item is missing a colon: '" +
90 stations_value +
"'");
91 const std::string value_string(
92 stations_value.substr(colon + 1, stations_value.size() - colon));
93 std::istringstream value_stream(value_string);
95 value_stream >> value;
96 std::string station_pattern(stations_value.substr(0, colon));
The value of a parameter.
Definition: ParameterValue.h:24
Definition: BaselineSelection.h:20
void AssignStationValues(std::span< ValueType > result, ValueType value, const std::string pattern_string, std::span< const std::string > station_names)
Definition: ValuePerStationParsing.h:28
void ParseValuePerStation(std::span< ValueType > result, std::span< const std::string > string_list, std::span< const std::string > station_names)
Definition: ValuePerStationParsing.h:79
std::string PatternToRegex(const std::string &pattern)