• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.4 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • services
ktraderparsetree_p.h
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef __ktrader_parse_tree_h__
21 #define __ktrader_parse_tree_h__
22 
23 #include <QtCore/QString>
24 #include <QtCore/QStringList>
25 #include <QtCore/QMap>
26 
27 #include <kservice.h>
28 
29 namespace KTraderParse {
30 
31 class ParseTreeBase;
32 
39 int matchConstraint( const ParseTreeBase *_tree, const KService::Ptr &,
40  const KService::List& );
41 
45 struct KDECORE_EXPORT PreferencesMaxima
46 {
47  PreferencesMaxima()
48  : iMax( 0 ), iMin( 0 ), fMax( 0 ), fMin( 0 )
49  {
50  }
51 
52  enum Type { PM_ERROR, PM_INVALID_INT, PM_INVALID_DOUBLE, PM_DOUBLE, PM_INT };
53 
54  Type type;
55  int iMax;
56  int iMin;
57  double fMax;
58  double fMin;
59 };
60 
64 class ParseContext
65 {
66 public:
70  explicit ParseContext( const ParseContext* _ctx ) : service( _ctx->service ), maxima( _ctx->maxima ),
71  offers( _ctx->offers ) {}
72  ParseContext( const KService::Ptr & _service, const KService::List& _offers,
73  QMap<QString,PreferencesMaxima>& _m )
74  : service( _service ), maxima( _m ), offers( _offers ) {}
75 
76  bool initMaxima( const QString& _prop);
77 
78  enum Type { T_STRING = 1, T_DOUBLE = 2, T_NUM = 3, T_BOOL = 4,
79  T_STR_SEQ = 5, T_SEQ = 6 };
80 
81  QString str;
82  int i;
83  double f;
84  bool b;
85  QList<QVariant> seq;
86  QStringList strSeq;
87  Type type;
88 
89  KService::Ptr service;
90 
91  QMap<QString,PreferencesMaxima>& maxima;
92  const KService::List& offers;
93 };
94 
98 class ParseTreeBase : public KShared
99 {
100 public:
101  typedef KSharedPtr<ParseTreeBase> Ptr;
102  ParseTreeBase() { }
103  virtual ~ParseTreeBase() { }
104 
105  virtual bool eval( ParseContext *_context ) const = 0;
106 };
107 
108 ParseTreeBase::Ptr parseConstraints( const QString& _constr );
109 
113 class ParseTreeOR : public ParseTreeBase
114 {
115 public:
116  ParseTreeOR( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
117 
118  bool eval( ParseContext *_context ) const;
119 
120 protected:
121  ParseTreeBase::Ptr m_pLeft;
122  ParseTreeBase::Ptr m_pRight;
123 };
124 
128 class ParseTreeAND : public ParseTreeBase
129 {
130 public:
131  ParseTreeAND( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
132 
133  bool eval( ParseContext *_context ) const;
134 
135 protected:
136  ParseTreeBase::Ptr m_pLeft;
137  ParseTreeBase::Ptr m_pRight;
138 };
139 
143 class ParseTreeCMP : public ParseTreeBase
144 {
145 public:
146  ParseTreeCMP( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2, int _i ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cmd = _i; }
147 
148  bool eval( ParseContext *_context ) const;
149 
150 protected:
151  ParseTreeBase::Ptr m_pLeft;
152  ParseTreeBase::Ptr m_pRight;
153  int m_cmd;
154 };
155 
159 class ParseTreeIN : public ParseTreeBase
160 {
161 public:
162  ParseTreeIN(ParseTreeBase *ptr1, ParseTreeBase *ptr2, Qt::CaseSensitivity cs, bool substring = false)
163  : m_pLeft(ptr1),
164  m_pRight(ptr2),
165  m_cs(cs),
166  m_substring(substring)
167  {
168  }
169 
170  bool eval( ParseContext *_context ) const;
171 
172 protected:
173  ParseTreeBase::Ptr m_pLeft;
174  ParseTreeBase::Ptr m_pRight;
175  Qt::CaseSensitivity m_cs;
176  bool m_substring;
177 };
178 
182 class ParseTreeMATCH : public ParseTreeBase
183 {
184 public:
185  ParseTreeMATCH( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2, Qt::CaseSensitivity cs ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cs = cs; }
186 
187  bool eval( ParseContext *_context ) const;
188 
189 protected:
190  ParseTreeBase::Ptr m_pLeft;
191  ParseTreeBase::Ptr m_pRight;
192  Qt::CaseSensitivity m_cs;
193 };
194 
198 class ParseTreeCALC : public ParseTreeBase
199 {
200 public:
201  ParseTreeCALC( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2, int _i ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cmd = _i; }
202 
203  bool eval( ParseContext *_context ) const;
204 
205 protected:
206  ParseTreeBase::Ptr m_pLeft;
207  ParseTreeBase::Ptr m_pRight;
208  int m_cmd;
209 };
210 
214 class ParseTreeBRACKETS : public ParseTreeBase
215 {
216 public:
217  explicit ParseTreeBRACKETS( ParseTreeBase *_ptr ) { m_pLeft = _ptr; }
218 
219  bool eval( ParseContext *_context ) const { return m_pLeft->eval( _context ); }
220 
221 protected:
222  ParseTreeBase::Ptr m_pLeft;
223 };
224 
228 class ParseTreeNOT : public ParseTreeBase
229 {
230 public:
231  explicit ParseTreeNOT( ParseTreeBase *_ptr ) { m_pLeft = _ptr; }
232 
233  bool eval( ParseContext *_context ) const;
234 
235 protected:
236  ParseTreeBase::Ptr m_pLeft;
237 };
238 
242 class ParseTreeEXIST : public ParseTreeBase
243 {
244 public:
245  explicit ParseTreeEXIST( const char *_id ) { m_id = QString::fromUtf8(_id); }
246 
247  bool eval( ParseContext *_context ) const;
248 
249 protected:
250  QString m_id;
251 };
252 
256 class ParseTreeID : public ParseTreeBase
257 {
258 public:
259  explicit ParseTreeID( const char *arg ) { m_str = QString::fromUtf8(arg); }
260 
261  bool eval( ParseContext *_context ) const;
262 
263 protected:
264  QString m_str;
265 };
266 
270 class ParseTreeSTRING : public ParseTreeBase
271 {
272 public:
273  explicit ParseTreeSTRING( const char *arg ) { m_str = QString::fromUtf8(arg); }
274 
275  bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_STRING;
276  _context->str = m_str;
277  return true; }
278 
279 protected:
280  QString m_str;
281 };
282 
286 class ParseTreeNUM : public ParseTreeBase
287 {
288 public:
289  explicit ParseTreeNUM( int arg ) { m_int = arg; }
290 
291  bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_NUM; _context->i = m_int; return true; }
292 
293 protected:
294  int m_int;
295 };
296 
300 class ParseTreeDOUBLE : public ParseTreeBase
301 {
302 public:
303  explicit ParseTreeDOUBLE( double arg ) { m_double = arg; }
304 
305  bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_DOUBLE; _context->f = m_double; return true; }
306 
307 protected:
308  double m_double;
309 };
310 
314 class ParseTreeBOOL : public ParseTreeBase
315 {
316 public:
317  explicit ParseTreeBOOL( bool arg ) { m_bool = arg; }
318 
319  bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_BOOL; _context->b = m_bool; return true; }
320 
321 protected:
322  bool m_bool;
323 };
324 
328 class ParseTreeMAX2 : public ParseTreeBase
329 {
330 public:
331  explicit ParseTreeMAX2( const char *_id ) { m_strId = QString::fromUtf8(_id); }
332 
333  bool eval( ParseContext *_context ) const;
334 
335 protected:
336  QString m_strId;
337 };
338 
342 class ParseTreeMIN2 : public ParseTreeBase
343 {
344 public:
345  explicit ParseTreeMIN2( const char *_id ) { m_strId = QString::fromUtf8(_id); }
346 
347  bool eval( ParseContext *_context ) const;
348 
349 protected:
350  QString m_strId;
351 };
352 
353 }
354 
355 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Wed Jun 5 2013 18:35:24 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.10.4 API Reference

Skip menu "kdelibs-4.10.4 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal