Skip to content

Commit 0ec3b8b

Browse files
committed
MUL-294: Move and template parseConfig method for reuse in other actions
1 parent 44c33b4 commit 0ec3b8b

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

src/multio/action/Action.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "ActionStatistics.h"
2626
#include "eckit/memory/NonCopyable.h"
2727
#include "multio/config/ComponentConfiguration.h"
28+
#include "multio/datamod/core/EntryParser.h"
2829
#include "multio/message/Message.h"
2930
#include "multio/util/FailureHandling.h"
3031

@@ -130,4 +131,16 @@ class ActionBuilder final : public ActionBuilderBase {
130131

131132
//--------------------------------------------------------------------------------------------------
132133

134+
template <typename ParsedConfig>
135+
ParsedConfig parseConfig(const ComponentConfiguration& compConf) {
136+
multio::datamod::ParseOptions opts;
137+
opts.allowAdditionalKeys = false;
138+
139+
auto conf = compConf.parsedConfig();
140+
conf.remove("type");
141+
conf.remove("next");
142+
143+
return multio::datamod::readRecordByValue<ParsedConfig>(conf, opts);
144+
}
145+
133146
} // namespace multio::action

src/multio/action/encode-mtg2/EncodeMtg2.cc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,9 @@ mars2grib::RawOptions mapOpts(EncodeMtg2Options opts) {
4343
return ret;
4444
};
4545

46-
EncodeMtg2Options parseOpts(const ComponentConfiguration& compConf) {
47-
/// TODO(pgeier) With C++20 designators are more useful for inline creation of structs:
48-
/// ParsedOptions{.allowAdditionalKeys=false}
49-
dm::ParseOptions opts;
50-
opts.allowAdditionalKeys = false;
51-
52-
// TODO(pgeier) Fix after refactoring action - need to remove keys "type" and "next"
53-
auto conf = compConf.parsedConfig();
54-
conf.remove("type");
55-
conf.remove("next");
56-
57-
return dm::readRecordByValue<EncodeMtg2Options>(conf, opts);
58-
}
59-
6046

6147
EncodeMtg2::EncodeMtg2(const ComponentConfiguration& compConf) :
62-
ChainedAction{compConf}, opts_{parseOpts(compConf)}, mars2grib_{mapOpts(opts_)} {}
48+
ChainedAction{compConf}, opts_{parseConfig<EncodeMtg2Options>(compConf)}, mars2grib_{mapOpts(opts_)} {}
6349

6450

6551
void EncodeMtg2::executeImpl(Message msg) {

src/multio/action/scale/Scale.cc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@
2020

2121
namespace multio::action::scale {
2222

23-
ScaleConfig parseConfig(const ComponentConfiguration& compConf) {
24-
dm::ParseOptions opts;
25-
opts.allowAdditionalKeys = false;
26-
27-
// TODO(pgeier) Fix after refactoring action - need to remove keys "type" and "next"
28-
auto conf = compConf.parsedConfig();
29-
conf.remove("type");
30-
conf.remove("next");
31-
32-
return dm::readRecordByValue<ScaleConfig>(conf, opts);
33-
}
34-
3523
const std::vector<ScaleMappingConfig> getPresetMappings(const Preset& preset) {
3624
// Load the mapping file
3725
eckit::LocalConfiguration mappingConf{eckit::YAMLConfiguration{eckit::PathName{
@@ -71,7 +59,7 @@ Mappings getMappings(const ScaleConfig& config) {
7159
}
7260

7361
Scale::Scale(const ComponentConfiguration& compConf) :
74-
ChainedAction(compConf), mappings_{getMappings(parseConfig(compConf))} {}
62+
ChainedAction(compConf), mappings_{getMappings(parseConfig<ScaleConfig>(compConf))} {}
7563

7664
void Scale::executeImpl(message::Message msg) {
7765
// Skip non-field messages

0 commit comments

Comments
 (0)