MCPcopy Create free account
hub / github.com/comaps/comaps / GetState

Function GetState

3party/opening_hours/rules_evaluation.cpp:475–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

473}
474
475RuleState GetState(TRuleSequences const & rules, time_t const timestamp)
476{
477 RuleSequence const * emptyRule = nullptr;
478 RuleSequence const * dayMatchedRule = nullptr;
479
480 for (auto it = rules.rbegin(); it != rules.rend(); ++it)
481 {
482 auto const & rule = *it;
483 auto const res = IsActiveImpl(rule, timestamp);
484 if (!res.first)
485 continue;
486
487 bool const empty = rule.IsEmpty();
488 if (res.second)
489 {
490 if (empty && !emptyRule)
491 emptyRule = &rule;
492 else
493 {
494 // Should understand if previous 'rule vs dayMatchedRule' should work
495 // like 'general x BUT specific y' or like 'x OR y'.
496
497 if (dayMatchedRule && IsR1IncludesR2(rule, *dayMatchedRule))
498 return RuleState::Closed;
499
500 return ModifierToRuleState(rule.GetModifier());
501 }
502 }
503 else if (!empty && !dayMatchedRule && ModifierToRuleState(rule.GetModifier()) == RuleState::Open)
504 {
505 // Save recent day-matched rule with Open state, but not time-matched.
506 dayMatchedRule = &rule;
507 }
508 }
509
510 if (emptyRule)
511 {
512 if (emptyRule->HasComment())
513 return RuleState::Unknown;
514 else
515 return ModifierToRuleState(emptyRule->GetModifier());
516 }
517
518 return (rules.empty()
519 ? RuleState::Unknown
520 : RuleState::Closed);
521}
522} // namespace osmoh

Callers 12

GetCapStateMethod · 0.85
ShowMethod · 0.85
HideMethod · 0.85
RefreshInterpolatorMethod · 0.85
GetNextTimeStateFunction · 0.85
IsOpenFunction · 0.85
GetNextTimeOpenFunction · 0.85
IsClosedFunction · 0.85
GetNextTimeClosedFunction · 0.85
IsUnknownFunction · 0.85
GetInfoMethod · 0.85
GetRulesStateFunction · 0.85

Calls 9

IsActiveImplFunction · 0.85
IsR1IncludesR2Function · 0.85
ModifierToRuleStateFunction · 0.85
rbeginMethod · 0.80
rendMethod · 0.80
GetModifierMethod · 0.80
HasCommentMethod · 0.80
IsEmptyMethod · 0.45
emptyMethod · 0.45

Tested by 1

GetRulesStateFunction · 0.68