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 <[email protected]>
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 
31 class KDbDriver;
32 
33 /*! @brief A type-safe KDbSQL token
34  It can be used in KDb expressions
35  @see KDbExpression */
36 class KDB_EXPORT KDbToken
37 {
38 public:
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  static QList<KDbToken> allTokens();
100 
101  // -- constants go here --
102  static const KDbToken SQL_TYPE;
103  static const KDbToken AS;
104  static const KDbToken AS_EMPTY;
105  static const KDbToken ASC;
106  static const KDbToken AUTO_INCREMENT;
107  static const KDbToken BIT;
108  static const KDbToken BITWISE_SHIFT_LEFT;
109  static const KDbToken BITWISE_SHIFT_RIGHT;
110  static const KDbToken BY;
111  static const KDbToken CHARACTER_STRING_LITERAL;
112  static const KDbToken CONCATENATION;
113  static const KDbToken CREATE;
114  static const KDbToken DESC;
115  static const KDbToken DISTINCT;
116  static const KDbToken DOUBLE_QUOTED_STRING;
117  static const KDbToken FROM;
118  static const KDbToken JOIN;
119  static const KDbToken KEY;
120  static const KDbToken LEFT;
121  static const KDbToken LESS_OR_EQUAL;
122  static const KDbToken GREATER_OR_EQUAL;
123  static const KDbToken SQL_NULL;
124  static const KDbToken SQL_IS;
125  static const KDbToken SQL_IS_NULL;
126  static const KDbToken SQL_IS_NOT_NULL;
127  static const KDbToken ORDER;
128  static const KDbToken PRIMARY;
129  static const KDbToken SELECT;
130  static const KDbToken INTEGER_CONST;
131  static const KDbToken REAL_CONST;
132  static const KDbToken RIGHT;
133  static const KDbToken SQL_ON;
134  static const KDbToken DATE_CONST;
135  static const KDbToken DATETIME_CONST;
136  static const KDbToken TIME_CONST;
137  static const KDbToken TABLE;
138  static const KDbToken IDENTIFIER;
139  static const KDbToken IDENTIFIER_DOT_ASTERISK;
140  static const KDbToken QUERY_PARAMETER;
141  static const KDbToken VARCHAR;
142  static const KDbToken WHERE;
143  static const KDbToken SQL;
144  static const KDbToken SQL_TRUE;
145  static const KDbToken SQL_FALSE;
146  static const KDbToken UNION;
147  static const KDbToken SCAN_ERROR;
148  static const KDbToken AND;
149  static const KDbToken BETWEEN;
150  static const KDbToken NOT_BETWEEN;
151  static const KDbToken EXCEPT;
152  static const KDbToken SQL_IN;
153  static const KDbToken INTERSECT;
154  static const KDbToken LIKE;
155  static const KDbToken ILIKE;
156  static const KDbToken NOT_LIKE;
157  static const KDbToken NOT;
158  static const KDbToken NOT_EQUAL;
159  static const KDbToken NOT_EQUAL2;
160  static const KDbToken OR;
161  static const KDbToken SIMILAR_TO;
162  static const KDbToken NOT_SIMILAR_TO;
163  static const KDbToken XOR;
164  static const KDbToken UMINUS;
165  static const KDbToken TABS_OR_SPACES;
166  static const KDbToken DATE_TIME_INTEGER;
167  static const KDbToken TIME_AM;
168  static const KDbToken TIME_PM;
169  //! Custom tokens are not used in parser but used as an extension in expression classes.
170  static const KDbToken BETWEEN_AND;
171  static const KDbToken NOT_BETWEEN_AND;
172  // -- end of constants --
173 
174  class List;
175 private:
176  inline KDbToken(int value) : v(value) {}
177  int v;
178 };
179 
180 //! Sends information about token @a token to debug output @a dbg.
181 KDB_EXPORT QDebug operator<<(QDebug dbg, KDbToken token);
182 
183 #endif
bool operator==(char charToken) const
Definition: KDbToken.h:94
bool isValid() const
Definition: KDbToken.h:53
A type-safe KDbSQL token It can be used in KDb expressions.
Definition: KDbToken.h:36
KDbToken()
Creates an invalid token.
Definition: KDbToken.h:42
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
Database driver's abstraction.
Definition: KDbDriver.h:49
static const KDbToken BETWEEN_AND
Custom tokens are not used in parser but used as an extension in expression classes.
Definition: KDbToken.h:170
bool operator!=(char charToken) const
Definition: KDbToken.h:97
bool operator!=(KDbToken other) const
Definition: KDbToken.h:91
bool operator==(KDbToken other) const
Definition: KDbToken.h:88
char toChar() const
Definition: KDbToken.h:82
static const int maxTokenValue
Maximum character token value.
Definition: KDbToken.h:77
static const int maxCharTokenValue
Maximum character token value (253)
Definition: KDbToken.h:74
int value() const
Definition: KDbToken.h:85
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 04:07:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.