KDECore
ktraderparsetree_p.h
Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef __ktrader_parse_tree_h__ 00021 #define __ktrader_parse_tree_h__ 00022 00023 #include <QtCore/QString> 00024 #include <QtCore/QStringList> 00025 #include <QtCore/QMap> 00026 00027 #include <kservice.h> 00028 00029 namespace KTraderParse { 00030 00031 class ParseTreeBase; 00032 00039 int matchConstraint( const ParseTreeBase *_tree, const KService::Ptr &, 00040 const KService::List& ); 00041 00045 struct KDECORE_EXPORT PreferencesMaxima 00046 { 00047 PreferencesMaxima() 00048 : iMax( 0 ), iMin( 0 ), fMax( 0 ), fMin( 0 ) 00049 { 00050 } 00051 00052 enum Type { PM_ERROR, PM_INVALID_INT, PM_INVALID_DOUBLE, PM_DOUBLE, PM_INT }; 00053 00054 Type type; 00055 int iMax; 00056 int iMin; 00057 double fMax; 00058 double fMin; 00059 }; 00060 00064 class ParseContext 00065 { 00066 public: 00070 explicit ParseContext( const ParseContext* _ctx ) : service( _ctx->service ), maxima( _ctx->maxima ), 00071 offers( _ctx->offers ) {} 00072 ParseContext( const KService::Ptr & _service, const KService::List& _offers, 00073 QMap<QString,PreferencesMaxima>& _m ) 00074 : service( _service ), maxima( _m ), offers( _offers ) {} 00075 00076 bool initMaxima( const QString& _prop); 00077 00078 enum Type { T_STRING = 1, T_DOUBLE = 2, T_NUM = 3, T_BOOL = 4, 00079 T_STR_SEQ = 5, T_SEQ = 6 }; 00080 00081 QString str; 00082 int i; 00083 double f; 00084 bool b; 00085 QList<QVariant> seq; 00086 QStringList strSeq; 00087 Type type; 00088 00089 KService::Ptr service; 00090 00091 QMap<QString,PreferencesMaxima>& maxima; 00092 const KService::List& offers; 00093 }; 00094 00098 class ParseTreeBase : public KShared 00099 { 00100 public: 00101 typedef KSharedPtr<ParseTreeBase> Ptr; 00102 ParseTreeBase() { } 00103 virtual ~ParseTreeBase() { } 00104 00105 virtual bool eval( ParseContext *_context ) const = 0; 00106 }; 00107 00108 ParseTreeBase::Ptr parseConstraints( const QString& _constr ); 00109 00113 class ParseTreeOR : public ParseTreeBase 00114 { 00115 public: 00116 ParseTreeOR( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; } 00117 00118 bool eval( ParseContext *_context ) const; 00119 00120 protected: 00121 ParseTreeBase::Ptr m_pLeft; 00122 ParseTreeBase::Ptr m_pRight; 00123 }; 00124 00128 class ParseTreeAND : public ParseTreeBase 00129 { 00130 public: 00131 ParseTreeAND( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; } 00132 00133 bool eval( ParseContext *_context ) const; 00134 00135 protected: 00136 ParseTreeBase::Ptr m_pLeft; 00137 ParseTreeBase::Ptr m_pRight; 00138 }; 00139 00143 class ParseTreeCMP : public ParseTreeBase 00144 { 00145 public: 00146 ParseTreeCMP( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2, int _i ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cmd = _i; } 00147 00148 bool eval( ParseContext *_context ) const; 00149 00150 protected: 00151 ParseTreeBase::Ptr m_pLeft; 00152 ParseTreeBase::Ptr m_pRight; 00153 int m_cmd; 00154 }; 00155 00159 class ParseTreeIN : public ParseTreeBase 00160 { 00161 public: 00162 ParseTreeIN(ParseTreeBase *ptr1, ParseTreeBase *ptr2, Qt::CaseSensitivity cs, bool substring = false) 00163 : m_pLeft(ptr1), 00164 m_pRight(ptr2), 00165 m_cs(cs), 00166 m_substring(substring) 00167 { 00168 } 00169 00170 bool eval( ParseContext *_context ) const; 00171 00172 protected: 00173 ParseTreeBase::Ptr m_pLeft; 00174 ParseTreeBase::Ptr m_pRight; 00175 Qt::CaseSensitivity m_cs; 00176 bool m_substring; 00177 }; 00178 00182 class ParseTreeMATCH : public ParseTreeBase 00183 { 00184 public: 00185 ParseTreeMATCH( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2, Qt::CaseSensitivity cs ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cs = cs; } 00186 00187 bool eval( ParseContext *_context ) const; 00188 00189 protected: 00190 ParseTreeBase::Ptr m_pLeft; 00191 ParseTreeBase::Ptr m_pRight; 00192 Qt::CaseSensitivity m_cs; 00193 }; 00194 00198 class ParseTreeCALC : public ParseTreeBase 00199 { 00200 public: 00201 ParseTreeCALC( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2, int _i ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cmd = _i; } 00202 00203 bool eval( ParseContext *_context ) const; 00204 00205 protected: 00206 ParseTreeBase::Ptr m_pLeft; 00207 ParseTreeBase::Ptr m_pRight; 00208 int m_cmd; 00209 }; 00210 00214 class ParseTreeBRACKETS : public ParseTreeBase 00215 { 00216 public: 00217 explicit ParseTreeBRACKETS( ParseTreeBase *_ptr ) { m_pLeft = _ptr; } 00218 00219 bool eval( ParseContext *_context ) const { return m_pLeft->eval( _context ); } 00220 00221 protected: 00222 ParseTreeBase::Ptr m_pLeft; 00223 }; 00224 00228 class ParseTreeNOT : public ParseTreeBase 00229 { 00230 public: 00231 explicit ParseTreeNOT( ParseTreeBase *_ptr ) { m_pLeft = _ptr; } 00232 00233 bool eval( ParseContext *_context ) const; 00234 00235 protected: 00236 ParseTreeBase::Ptr m_pLeft; 00237 }; 00238 00242 class ParseTreeEXIST : public ParseTreeBase 00243 { 00244 public: 00245 explicit ParseTreeEXIST( const char *_id ) { m_id = QString::fromUtf8(_id); } 00246 00247 bool eval( ParseContext *_context ) const; 00248 00249 protected: 00250 QString m_id; 00251 }; 00252 00256 class ParseTreeID : public ParseTreeBase 00257 { 00258 public: 00259 explicit ParseTreeID( const char *arg ) { m_str = QString::fromUtf8(arg); } 00260 00261 bool eval( ParseContext *_context ) const; 00262 00263 protected: 00264 QString m_str; 00265 }; 00266 00270 class ParseTreeSTRING : public ParseTreeBase 00271 { 00272 public: 00273 explicit ParseTreeSTRING( const char *arg ) { m_str = QString::fromUtf8(arg); } 00274 00275 bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_STRING; 00276 _context->str = m_str; 00277 return true; } 00278 00279 protected: 00280 QString m_str; 00281 }; 00282 00286 class ParseTreeNUM : public ParseTreeBase 00287 { 00288 public: 00289 explicit ParseTreeNUM( int arg ) { m_int = arg; } 00290 00291 bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_NUM; _context->i = m_int; return true; } 00292 00293 protected: 00294 int m_int; 00295 }; 00296 00300 class ParseTreeDOUBLE : public ParseTreeBase 00301 { 00302 public: 00303 explicit ParseTreeDOUBLE( double arg ) { m_double = arg; } 00304 00305 bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_DOUBLE; _context->f = m_double; return true; } 00306 00307 protected: 00308 double m_double; 00309 }; 00310 00314 class ParseTreeBOOL : public ParseTreeBase 00315 { 00316 public: 00317 explicit ParseTreeBOOL( bool arg ) { m_bool = arg; } 00318 00319 bool eval( ParseContext *_context ) const { _context->type = ParseContext::T_BOOL; _context->b = m_bool; return true; } 00320 00321 protected: 00322 bool m_bool; 00323 }; 00324 00328 class ParseTreeMAX2 : public ParseTreeBase 00329 { 00330 public: 00331 explicit ParseTreeMAX2( const char *_id ) { m_strId = QString::fromUtf8(_id); } 00332 00333 bool eval( ParseContext *_context ) const; 00334 00335 protected: 00336 QString m_strId; 00337 }; 00338 00342 class ParseTreeMIN2 : public ParseTreeBase 00343 { 00344 public: 00345 explicit ParseTreeMIN2( const char *_id ) { m_strId = QString::fromUtf8(_id); } 00346 00347 bool eval( ParseContext *_context ) const; 00348 00349 protected: 00350 QString m_strId; 00351 }; 00352 00353 } 00354 00355 #endif
KDE 4.6 API Reference