@@ -121,6 +121,8 @@ class Rule : public metkit::mars::MarsExpandContext {
121
121
122
122
Rule::Rule (const Rule& other, const eckit::Value& matchers, const eckit::Value& values, const eckit::Value& ids) {
123
123
124
+ std::map<std::string, size_t > precedence;
125
+
124
126
const eckit::Value& keys = matchers.keys ();
125
127
for (size_t i = 0 ; i < keys.size (); ++i) {
126
128
std::string name = keys[i];
@@ -132,7 +134,6 @@ Rule::Rule(const Rule& other, const eckit::Value& matchers, const eckit::Value&
132
134
for (const std::string& v : other.values_ ) {
133
135
values_.push_back (v);
134
136
}
135
-
136
137
auto it = mapping_.begin ();
137
138
for (auto m : other.mapping_ ) {
138
139
mapping_.emplace_hint (it, m.first , m.second );
@@ -159,16 +160,37 @@ Rule::Rule(const Rule& other, const eckit::Value& matchers, const eckit::Value&
159
160
std::string v = aliases[j];
160
161
161
162
if (mapping_.find (v) != mapping_.end ()) {
163
+ auto it = precedence.find (v);
164
+
165
+ if (it != precedence.end () and (*it).second <= j) {
162
166
163
- LOG_DEBUG_LIB (LibMetkit) << " Redefinition of param "
164
- << v
165
- << " ='"
166
- << first
167
- << " ', overriding previous value of '"
168
- << mapping_[v]
169
- << " ' "
170
- << *this
171
- << std::endl;
167
+ LOG_DEBUG_LIB (LibMetkit) << " Redefinition ignored: param "
168
+ << v
169
+ << " ='"
170
+ << first
171
+ << " ', keeping previous value of '"
172
+ << mapping_[v]
173
+ << " ' "
174
+ << *this
175
+ << std::endl;
176
+ continue ;
177
+ }
178
+ else {
179
+
180
+ LOG_DEBUG_LIB (LibMetkit) << " Redefinition of param "
181
+ << v
182
+ << " ='"
183
+ << first
184
+ << " ', overriding previous value of '"
185
+ << mapping_[v]
186
+ << " ' "
187
+ << *this
188
+ << std::endl;
189
+
190
+ precedence[v] = j;
191
+ }
192
+ } else {
193
+ precedence[v] = j;
172
194
}
173
195
174
196
mapping_[v] = first;
@@ -453,7 +475,6 @@ static void init() {
453
475
}
454
476
455
477
(*rules).push_back (Rule{eckit::Value::makeMap (), ids.keys (), ids});
456
- // (*rules).push_back(Rule{eckit::Value::makeMap(), unambiguousIDs, ids});
457
478
}
458
479
459
480
namespace metkit {
0 commit comments