196 std::map<std::string, ruleRuleKeys> &rrkMap,
198 mx::app::appConfigurator &config
201 std::vector<std::string> sections;
203 config.unusedSections( sections );
205 if( sections.size() == 0 )
207 throw mx::exception( mx::error_t::invalidconfig,
"no rules found in config" );
210 for(
size_t i = 0; i < sections.size(); ++i )
212 bool ruleTypeSet = config.isSetUnused( mx::app::iniFile::makeKey( sections[i],
"ruleType" ) );
221 if( maps.
rules.count( sections[i] ) != 0 )
223 throw mx::exception( mx::error_t::invalidconfig,
"duplicate rule: " + sections[i] );
226 std::string ruleType;
227 config.configUnused( ruleType, mx::app::iniFile::makeKey( sections[i],
"ruleType" ) );
229 std::string priostr =
"none";
230 config.configUnused( priostr, mx::app::iniFile::makeKey( sections[i],
"priority" ) );
234 config.configUnused( message, mx::app::iniFile::makeKey( sections[i],
"message" ) );
235 stripQuotesWS( message );
239 std::string compstr =
comp2string( rule->defaultComparison() );
240 config.configUnused( compstr, mx::app::iniFile::makeKey( sections[i],
"comp" ) );
242 rule->priority( priority );
243 rule->message( message );
250 maps.
rules.insert( std::pair<std::string, indiCompRule *>( { sections[i], nvr } ) );
252 configureRuleBase( nvr );
254 pcf::IndiProperty *prop =
nullptr;
258 &prop, element, maps, sections[i],
"property",
"element", pcf::IndiProperty::Number, config );
262 double target = nvr->
target();
263 config.configUnused( target, mx::app::iniFile::makeKey( sections[i],
"target" ) );
266 double tol = nvr->
tol();
267 config.configUnused( tol, mx::app::iniFile::makeKey( sections[i],
"tol" ) );
273 maps.
rules.insert( std::pair<std::string, indiCompRule *>( { sections[i], tvr } ) );
275 configureRuleBase( tvr );
277 pcf::IndiProperty *prop =
nullptr;
281 &prop, element, maps, sections[i],
"property",
"element", pcf::IndiProperty::Text, config );
285 std::string target = tvr->
target();
286 config.configUnused( target, mx::app::iniFile::makeKey( sections[i],
"target" ) );
292 maps.
rules.insert( std::pair<std::string, indiCompRule *>( { sections[i], svr } ) );
294 configureRuleBase( svr );
296 pcf::IndiProperty *prop =
nullptr;
300 &prop, element, maps, sections[i],
"property",
"element", pcf::IndiProperty::Switch, config );
304 std::string target =
"On";
305 config.configUnused( target, mx::app::iniFile::makeKey( sections[i],
"target" ) );
311 maps.
rules.insert( std::pair<std::string, indiCompRule *>( { sections[i], nvr } ) );
313 configureRuleBase( nvr );
315 pcf::IndiProperty *prop =
nullptr;
319 &prop, element, maps, sections[i],
"property",
"element", pcf::IndiProperty::Number, config );
323 double target = nvr->
target();
324 config.configUnused( target, mx::app::iniFile::makeKey( sections[i],
"target" ) );
327 double tol = nvr->
tol();
328 config.configUnused( tol, mx::app::iniFile::makeKey( sections[i],
"tol" ) );
334 maps.
rules.insert( std::pair<std::string, indiCompRule *>( { sections[i], nvr } ) );
336 configureRuleBase( nvr );
338 pcf::IndiProperty *prop1;
339 std::string element1;
342 &prop1, element1, maps, sections[i],
"property1",
"element1", pcf::IndiProperty::Number, config );
346 pcf::IndiProperty *prop2;
347 std::string element2;
350 &prop2, element2, maps, sections[i],
"property2",
"element2", pcf::IndiProperty::Number, config );
357 maps.
rules.insert( std::pair<std::string, indiCompRule *>( { sections[i], tvr } ) );
359 configureRuleBase( tvr );
361 pcf::IndiProperty *prop1;
362 std::string element1;
365 &prop1, element1, maps, sections[i],
"property1",
"element1", pcf::IndiProperty::Text, config );
369 pcf::IndiProperty *prop2;
370 std::string element2;
373 &prop2, element2, maps, sections[i],
"property2",
"element2", pcf::IndiProperty::Text, config );
380 maps.
rules.insert( std::pair<std::string, indiCompRule *>( { sections[i], svr } ) );
382 configureRuleBase( svr );
384 pcf::IndiProperty *prop1;
385 std::string element1;
388 &prop1, element1, maps, sections[i],
"property1",
"element1", pcf::IndiProperty::Switch, config );
392 pcf::IndiProperty *prop2;
393 std::string element2;
396 &prop2, element2, maps, sections[i],
"property2",
"element2", pcf::IndiProperty::Switch, config );
404 if( rrkMap.count( sections[i] ) > 0 )
407 throw mx::exception( mx::error_t::invalidconfig,
"duplicate ruleRule: " + sections[i] );
411 maps.
rules.insert( std::pair<std::string, indiCompRule *>( { sections[i], rcr } ) );
413 configureRuleBase( rcr );
417 config.configUnused( rrk.
rule1, mx::app::iniFile::makeKey( sections[i],
"rule1" ) );
418 if( rrk.
rule1 ==
"" )
420 throw mx::exception( mx::error_t::invalidconfig,
421 "rule1 for ruleVal rule " + sections[i] +
" not found" );
423 if( rrk.
rule1 == sections[i] )
425 throw mx::exception( mx::error_t::invalidconfig,
426 "rule1 for ruleVal rule " + sections[i] +
" can't equal rule name" );
429 config.configUnused( rrk.
rule2, mx::app::iniFile::makeKey( sections[i],
"rule2" ) );
430 if( rrk.
rule2 ==
"" )
432 throw mx::exception( mx::error_t::invalidconfig,
433 "rule2 for ruleVal rule " + sections[i] +
" not found" );
435 if( rrk.
rule2 == sections[i] )
437 throw mx::exception( mx::error_t::invalidconfig,
438 "rule2 for ruleVal rule " + sections[i] +
" can't equal rule name" );
441 rrkMap.insert( std::pair<std::string, ruleRuleKeys>( sections[i], rrk ) );
446 maps.
rules.insert( std::pair<std::string, indiCompRule *>( { sections[i], mscr } ) );
448 configureRuleBase( mscr );
452 config.configUnused( numSwitches, mx::app::iniFile::makeKey( sections[i],
"numSwitches" ) );
453 if( numSwitches < 1 )
456 mx::error_t::invalidconfig,
457 std::format(
"numSwitches for multiSwitchCombo rule {} must be greater than zero", sections[i] ) );
460 for(
int n = 0; n < numSwitches; ++n )
462 pcf::IndiProperty *prop =
nullptr;
463 std::string property;
465 std::string propKey = std::format(
"property{}", n + 1 );
466 extractRuleProperty( &prop, property, maps, sections[i], propKey, pcf::IndiProperty::Switch, config );
472 config.configUnused( format, mx::app::iniFile::makeKey( sections[i],
"format" ) );
473 stripQuotesWS( format );
476 pcf::IndiProperty *targetProp =
nullptr;
477 std::string targetProperty;
479 &targetProp, targetProperty, maps, sections[i],
"targetProperty", pcf::IndiProperty::Switch, config );
486 throw mx::exception( mx::error_t::invalidconfig,
487 std::format(
"multiSwitchCombo rule {} is invalid: {}",
489 std::get<std::string>( rv ) ) );
494 throw mx::exception( mx::error_t::notimpl,
495 std::format(
"unknown rule type {} in {}", ruleType, sections[i] ) );