KOSMIndoorMap

mapcssexpression.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "mapcssexpression_p.h"
7#include "mapcssparser_impl.h"
8#include "mapcssparsercontext_p.h"
9#include "mapcssscanner.h"
10#include "mapcssterm_p.h"
11#include "logging.h"
12
13namespace KOSMIndoorMap {
14class MapCSSExpressionParserContext : public MapCSSParserContext {
15public:
16 MapCSSExpressionParserContext() : MapCSSParserContext(ParseEvalExpression) {};
17};
18}
19
20using namespace KOSMIndoorMap;
21
22MapCSSExpression::MapCSSExpression() = default;
23MapCSSExpression::MapCSSExpression(MapCSSExpression&&) noexcept = default;
24
25MapCSSExpression::MapCSSExpression(MapCSSTerm *term)
26 : m_term(term)
27{
28}
29
30MapCSSExpression::~MapCSSExpression() = default;
31
32MapCSSExpression& MapCSSExpression::operator=(MapCSSExpression&&) noexcept = default;
33
34bool MapCSSExpression::isValid() const
35{
36 return (bool)m_term;
37}
38
39void MapCSSExpression::compile(const OSM::DataSet &dataSet)
40{
41 m_term->compile(dataSet);
42}
43
44MapCSSValue MapCSSExpression::evaluate(const MapCSSExpressionContext &context) const
45{
46 return m_term->evaluate(context);
47}
48
49void MapCSSExpression::write(QIODevice *out) const
50{
51 m_term->write(out);
52}
53
54MapCSSExpression MapCSSExpression::fromString(const char *str)
55{
56 MapCSSExpressionParserContext context;
57 yyscan_t scanner;
58
59 if (yylex_init_extra(&context, &scanner)) {
60 return {};
61 }
62 const auto lexerCleanup = qScopeGuard([&scanner]{ yylex_destroy(scanner); });
63
64 YY_BUFFER_STATE state;
65 state = yy_scan_string(str, scanner);
66 if (yyparse(&context, scanner)) {
67 // TODO store error information from context in result
68 return {};
69 }
70
71 yy_delete_buffer(state, scanner);
72
73 return MapCSSExpression(context.m_term);
74}
A set of nodes, ways and relations.
Definition datatypes.h:343
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 Fri Jul 26 2024 11:57:46 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.