# kio Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# ktraderparsetree.h

    00001 /* This file is part of the KDE project
    00002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License as published by the Free Software Foundation; either
    00007    version 2 of the License, or (at your option) any later version.
    00008
    00009    This library is distributed in the hope that it will be useful,
    00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012    Library General Public License for more details.
    00013
    00014    You should have received a copy of the GNU Library General Public License
    00015    along with this library; see the file COPYING.LIB.  If not, write to
    00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017    Boston, MA 02111-1307, USA.
    00018 */
    00019
    00020 #ifndef __parse_tree_h__
    00021 #define __parse_tree_h__
    00022
    00023 #include <qstring.h>
    00024 #include <qstringlist.h>
    00025 #include <qvaluelist.h>
    00026 #include <qmap.h>
    00027 #include <qshared.h>
    00028
    00029 #include <kservice.h>
    00030 #include <kuserprofile.h>
    00031
    00032 #include "ktrader.h"
    00033
    00034 namespace KIO {
    00035
    00036 class ParseTreeBase;
    00037
    00038 struct PreferencesReturn
    00039 {
    00040   enum Type { PRT_DOUBLE, PRT_ERROR };
    00041
    00042   PreferencesReturn() { type = PRT_ERROR; }
    00043
    00044   PreferencesReturn( const PreferencesReturn& _r )
    00045   {
    00046     type = _r.type;
    00047     f = _r.f;
    00048   }
    00049
    00050   Type type;
    00051   double f;
    00052 };
    00053
    00054
    00060 int matchConstraint( const ParseTreeBase *_tree, const KService::Ptr &,
    00061                      const KServiceTypeProfile::OfferList& );
    00062
    00066 PreferencesReturn matchPreferences( const ParseTreeBase *_tree, const KService::Ptr &,
    00067                                     const KServiceTypeProfile::OfferList& );
    00068
    00072 struct PreferencesMaxima
    00073 {
    00074   enum Type { PM_ERROR, PM_INVALID_INT, PM_INVALID_DOUBLE, PM_DOUBLE, PM_INT };
    00075
    00076   Type type;
    00077   int iMax;
    00078   int iMin;
    00079   double fMax;
    00080   double fMin;
    00081 };
    00082
    00086 class ParseContext
    00087 {
    00088 public:
    00092   ParseContext( const ParseContext* _ctx ) : service( _ctx->service ), maxima( _ctx->maxima ),
    00093     offers( _ctx->offers ) {}
    00094   ParseContext( const KService::Ptr & _service, const KServiceTypeProfile::OfferList& _offers,
    00095                 QMap<QString,PreferencesMaxima>& _m )
    00096     : service( _service ), maxima( _m ), offers( _offers ) {}
    00097
    00098   bool initMaxima( const QString& _prop);
    00099
    00100   enum Type { T_STRING = 1, T_DOUBLE = 2, T_NUM = 3, T_BOOL = 4,
    00101               T_STR_SEQ = 5, T_SEQ = 6 };
    00102
    00103   QString str;
    00104   int i;
    00105   double f;
    00106   bool b;
    00107   QValueList<QVariant> seq;
    00108   QStringList strSeq;
    00109   Type type;
    00110
    00111   KService::Ptr service;
    00112
    00113   QMap<QString,PreferencesMaxima>& maxima;
    00114   const KServiceTypeProfile::OfferList& offers;
    00115 };
    00116
    00120 class ParseTreeBase : public KShared
    00121 {
    00122 public:
    00123   typedef KSharedPtr<ParseTreeBase> Ptr;
    00124   ParseTreeBase() { }
    00125
    00126   virtual bool eval( ParseContext *_context ) const = 0;
    00127 protected:
    00128   virtual ~ParseTreeBase() { };
    00129 };
    00130
    00131 ParseTreeBase::Ptr parseConstraints( const QString& _constr );
    00132 ParseTreeBase::Ptr parsePreferences( const QString& _prefs );
    00133
    00137 class ParseTreeOR : public ParseTreeBase
    00138 {
    00139 public:
    00140   ParseTreeOR( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
    00141
    00142   bool eval( ParseContext *_context ) const;
    00143
    00144 protected:
    00145   ParseTreeBase::Ptr m_pLeft;
    00146   ParseTreeBase::Ptr m_pRight;
    00147 };
    00148
    00152 class ParseTreeAND : public ParseTreeBase
    00153 {
    00154 public:
    00155   ParseTreeAND( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
    00156
    00157   bool eval( ParseContext *_context ) const;
    00158
    00159 protected:
    00160   ParseTreeBase::Ptr m_pLeft;
    00161   ParseTreeBase::Ptr m_pRight;
    00162 };
    00163
    00167 class ParseTreeCMP : public ParseTreeBase
    00168 {
    00169 public:
    00170   ParseTreeCMP( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2, int _i ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cmd = _i; }
    00171
    00172   bool eval( ParseContext *_context ) const;
    00173
    00174 protected:
    00175   ParseTreeBase::Ptr m_pLeft;
    00176   ParseTreeBase::Ptr m_pRight;
    00177   int m_cmd;
    00178 };
    00179
    00183 class ParseTreeIN : public ParseTreeBase
    00184 {
    00185 public:
    00186   ParseTreeIN( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
    00187
    00188   bool eval( ParseContext *_context ) const;
    00189
    00190 protected:
    00191   ParseTreeBase::Ptr m_pLeft;
    00192   ParseTreeBase::Ptr m_pRight;
    00193 };
    00194
    00198 class ParseTreeMATCH : public ParseTreeBase
    00199 {
    00200 public:
    00201   ParseTreeMATCH( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
    00202
    00203   bool eval( ParseContext *_context ) const;
    00204
    00205 protected:
    00206   ParseTreeBase::Ptr m_pLeft;
    00207   ParseTreeBase::Ptr m_pRight;
    00208 };
    00209
    00213 class ParseTreeCALC : public ParseTreeBase
    00214 {
    00215 public:
    00216   ParseTreeCALC( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2, int _i ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cmd = _i; }
    00217
    00218   bool eval( ParseContext *_context ) const;
    00219
    00220 protected:
    00221   ParseTreeBase::Ptr m_pLeft;
    00222   ParseTreeBase::Ptr m_pRight;
    00223   int m_cmd;
    00224 };
    00225
    00229 class ParseTreeBRACKETS : public ParseTreeBase
    00230 {
    00231 public:
    00232   ParseTreeBRACKETS( ParseTreeBase *_ptr ) { m_pLeft = _ptr; }
    00233
    00234   bool eval( ParseContext *_context ) const { return m_pLeft->eval( _context ); }
    00235
    00236 protected:
    00237   ParseTreeBase::Ptr m_pLeft;
    00238 };
    00239
    00243 class ParseTreeNOT : public ParseTreeBase
    00244 {
    00245 public:
    00246   ParseTreeNOT( ParseTreeBase *_ptr ) { m_pLeft = _ptr; }
    00247
    00248   bool eval( ParseContext *_context ) const;
    00249
    00250 protected:
    00251   ParseTreeBase::Ptr m_pLeft;
    00252 };
    00253
    00257 class ParseTreeEXIST : public ParseTreeBase
    00258 {
    00259 public:
    00260   ParseTreeEXIST( const char *_id ) { m_id = _id; }
    00261
    00262   bool eval( ParseContext *_context ) const;
    00263
    00264 protected:
    00265   QString m_id;
    00266 };
    00267
    00271 class ParseTreeID : public ParseTreeBase
    00272 {
    00273 public:
    00274   ParseTreeID( const char *arg ) { m_str = arg; }
    00275
    00276   bool eval( ParseContext *_context ) const;
    00277
    00278 protected:
    00279   QString m_str;
    00280 };
    00281
    00285 class ParseTreeSTRING : public ParseTreeBase
    00286 {
    00287 public:
    00288   ParseTreeSTRING( const char *arg ) { m_str = arg; }
    00289
    00290   bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_STRING; _context->str = m_str; return true; }
    00291
    00292 protected:
    00293   QString m_str;
    00294 };
    00295
    00299 class ParseTreeNUM : public ParseTreeBase
    00300 {
    00301 public:
    00302   ParseTreeNUM( int arg ) { m_int = arg; }
    00303
    00304   bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_NUM; _context->i = m_int; return true; }
    00305
    00306 protected:
    00307   int m_int;
    00308 };
    00309
    00313 class ParseTreeDOUBLE : public ParseTreeBase
    00314 {
    00315 public:
    00316   ParseTreeDOUBLE( double arg ) { m_double = arg; }
    00317
    00318   bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_DOUBLE; _context->f = m_double; return true; }
    00319
    00320 protected:
    00321   double m_double;
    00322 };
    00323
    00327 class ParseTreeBOOL : public ParseTreeBase
    00328 {
    00329 public:
    00330   ParseTreeBOOL( bool arg ) { m_bool = arg; }
    00331
    00332   bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_BOOL; _context->b = m_bool; return true; }
    00333
    00334 protected:
    00335   bool m_bool;
    00336 };
    00337
    00341 class ParseTreeMAX2 : public ParseTreeBase
    00342 {
    00343 public:
    00344   ParseTreeMAX2( const char *_id ) { m_strId = _id; }
    00345
    00346   bool eval( ParseContext *_context ) const;
    00347
    00348 protected:
    00349   QString m_strId;
    00350 };
    00351
    00355 class ParseTreeMIN2 : public ParseTreeBase
    00356 {
    00357 public:
    00358   ParseTreeMIN2( const char *_id ) { m_strId = _id; }
    00359
    00360   bool eval( ParseContext *_context ) const;
    00361
    00362 protected:
    00363   QString m_strId;
    00364 };
    00365
    00366 }
    00367
    00368 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:14:30 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001