KOSMIndoorMap

osmconditionalexpression.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "osmconditionalexpression_p.h"
7#include "osmconditionalexpressioncontext_p.h"
8
9#include <scene/openinghourscache_p.h>
10
11using namespace KOSMIndoorMap;
12
13OSMConditionalExpression::OSMConditionalExpression() = default;
14OSMConditionalExpression::~OSMConditionalExpression() = default;
15
16void OSMConditionalExpression::parse(const QByteArray &expression)
17{
18 QByteArrayView input(expression);
19 while (!input.isEmpty()) {
20 const auto sep = input.lastIndexOf('@');
21 if (sep < 0) {
22 break;
23 }
24 const auto start = input.lastIndexOf(';', sep);
25 m_conditions.push_back(Condition{
26 .value = input.mid(start + 1, sep - 1 - start).trimmed().toByteArray(),
27 .condition = input.mid(sep + 1).trimmed().toByteArray()
28 });
29 input = input.left(std::max<qsizetype>(start, 0));
30 }
31
32 // we parse back to front, but evaluation order matters
33 std::reverse(m_conditions.begin(), m_conditions.end());
34}
35
36QByteArray OSMConditionalExpression::evaluate(const OSMConditionalExpressionContext &context) const
37{
38 for (const auto &cond : m_conditions) {
39 if (context.openingHoursCache->isAtCurrentTime(context.element, cond.condition)) {
40 return cond.value;
41 }
42 }
43 return {};
44}
Q_SCRIPTABLE Q_NOREPLY void start()
OSM-based multi-floor indoor maps for buildings.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.