KDb

KDbToken.h
1/****************************************************************************
2 * Created by generate_parser_code.sh
3 * WARNING! All changes made in this file will be lost!
4 ****************************************************************************/
5/* This file is part of the KDE project
6 Copyright (C) 2015-2018 Jarosław Staniek <staniek@kde.org>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef KDB_TOKEN_H
25#define KDB_TOKEN_H
26
27#include "kdb_export.h"
28
29#include <QDebug>
30
31class KDbDriver;
32
33/*! @brief A type-safe KDbSQL token
34 It can be used in KDb expressions
35 @see KDbExpression */
36class KDB_EXPORT KDbToken
37{
38public:
39 //! @todo add KDbToken(const QByteArray &name)
40
41 //! Creates an invalid token
42 inline KDbToken() : v(0) {}
43
44 KDbToken(const KDbToken &other) : v(other.v) {}
45
46 //! Creates a single-character token
47 //! Only characters that belong to the grammar are accepted:
48 //! ';' ',' '.' '>' '<' '=' '+' '-' '&' '|' '/' '*' '%' '~' '#' ':' '(' ')'
49 //! Invalid KDbToken is created for character that is not accepted.
50 KDbToken(char charToken);
51
52 //! @return true if this token is valid
53 inline bool isValid() const { return v != 0; }
54
55 //! @return name of this token
56 //! Useful for debugging.
57 //! For example "NOT_EQUAL" string is returned for the NOT_EQUAL token.
58 //! A single character is returned for printable single-character tokens.
59 //! A number is returned for non-printable single-character.
60 //! "<INVALID_TOKEN>" is returned for an invalid string.
61 QString name() const;
62
63 //! @return string interpretation of this token (as visibe to the user)
64 //! For example "<>" is returned for the NOT_EQUAL token.
65 //! Empty string is returned for an invalid string
66 //! The result may depend on the optional @a driver parameter.
67 //! If @a driver is @c nullptr, representation for portable KDbSQL dialect is returned.
68 QString toString(const KDbDriver *driver = nullptr) const;
69
70 //! Like toString(const KDbDriver *driver)
71 static QString toString(KDbToken token, const KDbDriver *driver = nullptr);
72
73 //! Maximum character token value (253)
74 static const int maxCharTokenValue;
75
76 //! Maximum character token value
77 static const int maxTokenValue;
78
79 //! @return character equivalent of this token
80 //! Only character-based tokens are supported this way (toInt() <= maxCharTokenValue).
81 //! For unsupported tokens @c nullptr is returned.
82 inline char toChar() const { return v <= maxCharTokenValue ? v : 0; }
83
84 //! @return numeric value of this token
85 inline int value() const { return v; }
86
87 //! @return true if this token is equal to @a other token
88 inline bool operator==(KDbToken other) const { return v == other.v; }
89
90 //! @return true if this token is not equal to @a other token
91 inline bool operator!=(KDbToken other) const { return v != other.v; }
92
93 //! @return true if this token is equal to @a other token
94 inline bool operator==(char charToken) const { return v == charToken; }
95
96 //! @return true if this token is not equal to @a other token
97 inline bool operator!=(char charToken) const { return v != charToken; }
98
99 //! Assigns a token
100 inline void operator=(char charToken) { v = charToken; }
101
102 static QList<KDbToken> allTokens();
103
104 // -- constants go here --
105 static const KDbToken SQL_TYPE;
106 static const KDbToken AS;
107 static const KDbToken AS_EMPTY;
108 static const KDbToken ASC;
109 static const KDbToken AUTO_INCREMENT;
110 static const KDbToken BIT;
111 static const KDbToken BITWISE_SHIFT_LEFT;
112 static const KDbToken BITWISE_SHIFT_RIGHT;
113 static const KDbToken BY;
114 static const KDbToken CHARACTER_STRING_LITERAL;
115 static const KDbToken CONCATENATION;
116 static const KDbToken CREATE;
117 static const KDbToken DESC;
118 static const KDbToken DISTINCT;
119 static const KDbToken DOUBLE_QUOTED_STRING;
120 static const KDbToken FROM;
121 static const KDbToken JOIN;
122 static const KDbToken KEY;
123 static const KDbToken LEFT;
124 static const KDbToken LESS_OR_EQUAL;
125 static const KDbToken GREATER_OR_EQUAL;
126 static const KDbToken SQL_NULL;
127 static const KDbToken SQL_IS;
128 static const KDbToken SQL_IS_NULL;
129 static const KDbToken SQL_IS_NOT_NULL;
130 static const KDbToken ORDER;
131 static const KDbToken PRIMARY;
132 static const KDbToken SELECT;
133 static const KDbToken INTEGER_CONST;
134 static const KDbToken REAL_CONST;
135 static const KDbToken RIGHT;
136 static const KDbToken SQL_ON;
137 static const KDbToken DATE_CONST;
138 static const KDbToken DATETIME_CONST;
139 static const KDbToken TIME_CONST;
140 static const KDbToken TABLE;
141 static const KDbToken IDENTIFIER;
142 static const KDbToken IDENTIFIER_DOT_ASTERISK;
143 static const KDbToken QUERY_PARAMETER;
144 static const KDbToken VARCHAR;
145 static const KDbToken WHERE;
146 static const KDbToken SQL;
147 static const KDbToken SQL_TRUE;
148 static const KDbToken SQL_FALSE;
149 static const KDbToken UNION;
150 static const KDbToken SCAN_ERROR;
151 static const KDbToken AND;
152 static const KDbToken BETWEEN;
153 static const KDbToken NOT_BETWEEN;
154 static const KDbToken EXCEPT;
155 static const KDbToken SQL_IN;
156 static const KDbToken INTERSECT;
157 static const KDbToken LIKE;
158 static const KDbToken ILIKE;
159 static const KDbToken NOT_LIKE;
160 static const KDbToken NOT;
161 static const KDbToken NOT_EQUAL;
162 static const KDbToken NOT_EQUAL2;
163 static const KDbToken OR;
164 static const KDbToken SIMILAR_TO;
165 static const KDbToken NOT_SIMILAR_TO;
166 static const KDbToken XOR;
167 static const KDbToken UMINUS;
168 static const KDbToken TABS_OR_SPACES;
169 static const KDbToken DATE_TIME_INTEGER;
170 static const KDbToken TIME_AM;
171 static const KDbToken TIME_PM;
172 //! Custom tokens are not used in parser but used as an extension in expression classes.
173 static const KDbToken BETWEEN_AND;
174 static const KDbToken NOT_BETWEEN_AND;
175 // -- end of constants --
176
177 class List;
178private:
179 inline KDbToken(int value) : v(value) {}
180 int v;
181};
182
183//! Sends information about token @a token to debug output @a dbg.
184KDB_EXPORT QDebug operator<<(QDebug dbg, KDbToken token);
185
186#endif
Database driver's abstraction.
Definition KDbDriver.h:50
A type-safe KDbSQL token It can be used in KDb expressions.
Definition KDbToken.h:37
bool operator==(char charToken) const
Definition KDbToken.h:94
bool operator!=(char charToken) const
Definition KDbToken.h:97
static const KDbToken BETWEEN_AND
Custom tokens are not used in parser but used as an extension in expression classes.
Definition KDbToken.h:173
bool operator==(KDbToken other) const
Definition KDbToken.h:88
void operator=(char charToken)
Assigns a token.
Definition KDbToken.h:100
bool isValid() const
Definition KDbToken.h:53
char toChar() const
Definition KDbToken.h:82
int value() const
Definition KDbToken.h:85
KDbToken()
Creates an invalid token.
Definition KDbToken.h:42
static const int maxCharTokenValue
Maximum character token value (253)
Definition KDbToken.h:74
bool operator!=(KDbToken other) const
Definition KDbToken.h:91
static const int maxTokenValue
Maximum character token value.
Definition KDbToken.h:77
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.