Changeset View
Changeset View
Standalone View
Standalone View
src/kconfig_compiler/KConfigXmlParser.h
- This file was added.
1 | /* This file is part of the KDE libraries | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | ||||
3 | Copyright (c) 2003 Waldo Bastian <bastian@kde.org> | ||||
4 | Copyright (c) 2003 Zack Rusin <zack@kde.org> | ||||
5 | Copyright (c) 2006 Michaël Larouche <michael.larouche@kdemail.net> | ||||
6 | Copyright (c) 2008 Allen Winter <winter@kde.org> | ||||
7 | Copyright (C) 2020 Tomaz Cananbrava (tcanabrava@kde.org) | ||||
8 | | ||||
9 | This library is free software; you can redistribute it and/or | ||||
10 | modify it under the terms of the GNU Library General Public | ||||
11 | License as published by the Free Software Foundation; either | ||||
12 | version 2 of the License, or (at your option) any later version. | ||||
13 | | ||||
14 | This library is distributed in the hope that it will be useful, | ||||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
17 | Library General Public License for more details. | ||||
18 | | ||||
19 | You should have received a copy of the GNU Library General Public License | ||||
20 | along with this library; see the file COPYING.LIB. If not, write to | ||||
21 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
22 | Boston, MA 02110-1301, USA. | ||||
23 | */ | ||||
24 | | ||||
25 | #ifndef KCONFIGXMLPARSER_H | ||||
26 | #define KCONFIGXMLPARSER_H | ||||
27 | | ||||
28 | #include <QDomDocument> | ||||
29 | #include <QString> | ||||
30 | #include <QRegularExpression> | ||||
31 | | ||||
32 | #include "KConfigCommonStructs.h" | ||||
33 | #include "KConfigParameters.h" | ||||
34 | | ||||
35 | /* This parses the contents of a Xml file into a ParseResult Structure, | ||||
36 | * It also fails hard: | ||||
37 | * If start() succeeds, you can use the result, | ||||
38 | * if start() fails, the program aborts with an error message so there's | ||||
39 | * no possibility of generating incorrect code information. | ||||
40 | */ | ||||
41 | class KConfigXmlParser | ||||
42 | { | ||||
43 | public: | ||||
44 | KConfigXmlParser(const KConfigParameters &cfg, const QString &inputFileName); | ||||
45 | | ||||
46 | // Start the parser and reads the contents of the inputFileName into the ParseResult Structure | ||||
47 | void start(); | ||||
48 | | ||||
49 | // Get the result of the parse | ||||
50 | ParseResult getParseResult() const; | ||||
51 | | ||||
52 | private: | ||||
53 | // creates a `somethingChanged` signal for every property | ||||
54 | void createChangedSignal(CfgEntry &readEntry); | ||||
55 | | ||||
56 | void validateNameAndKey(CfgEntry &readEntry, const QDomElement &element); | ||||
57 | | ||||
58 | // TODO: Use std::optional and CfgEntry (without heap allocation) for this function | ||||
59 | // *or* fail hard if the parse fails. | ||||
60 | CfgEntry *parseEntry(const QString &group, const QDomElement &element); | ||||
61 | | ||||
62 | // Steps | ||||
63 | void readIncludeTag(const QDomElement &element); | ||||
64 | void readGroupTag(const QDomElement &element); | ||||
65 | void readKcfgfileTag(const QDomElement &element); | ||||
66 | void readSignalTag(const QDomElement &element); | ||||
67 | | ||||
68 | // Those are the Entries in the Xml, that represent a parameter within the <group> </group> tag. | ||||
69 | void readParameterFromEntry(CfgEntry &entry, const QDomElement &element); | ||||
70 | bool hasDefaultCode(CfgEntry &entry, const QDomElement &element); | ||||
71 | void readChoicesFromEntry(CfgEntry &entry, const QDomElement &element); | ||||
72 | void readGroupElements(CfgEntry &entry, const QDomElement &element); | ||||
73 | void readParamDefaultValues(CfgEntry &entry, const QDomElement &element); | ||||
74 | | ||||
75 | private: | ||||
76 | ParseResult mParseResult; | ||||
77 | KConfigParameters cfg; | ||||
78 | QString mInputFileName; | ||||
79 | QStringList mAllNames; | ||||
80 | QRegularExpression mValidNameRegexp; | ||||
81 | }; | ||||
82 | | ||||
83 | #endif |