20 #ifndef __parse_tree_h__
21 #define __parse_tree_h__
24 #include <tqstringlist.h>
25 #include <tqvaluelist.h>
30 #include <kuserprofile.h>
39 struct TDEIO_EXPORT PreferencesReturn
41 enum Type { PRT_DOUBLE, PRT_ERROR };
43 PreferencesReturn() { type = PRT_ERROR; }
45 PreferencesReturn(
const PreferencesReturn& _r )
62 TDEIO_EXPORT
int matchConstraint(
const ParseTreeBase *_tree,
const KService::Ptr &,
63 const KServiceTypeProfile::OfferList& );
69 TDEIO_EXPORT PreferencesReturn matchPreferences(
const ParseTreeBase *_tree,
const KService::Ptr &,
70 const KServiceTypeProfile::OfferList& );
75 struct TDEIO_EXPORT PreferencesMaxima
77 enum Type { PM_ERROR, PM_INVALID_INT, PM_INVALID_DOUBLE, PM_DOUBLE, PM_INT };
89 class TDEIO_EXPORT ParseContext
95 ParseContext(
const ParseContext* _ctx ) : service( _ctx->service ), maxima( _ctx->maxima ),
96 offers( _ctx->offers ) {}
97 ParseContext(
const KService::Ptr & _service,
const KServiceTypeProfile::OfferList& _offers,
98 TQMap<TQString,PreferencesMaxima>& _m )
99 : service( _service ), maxima( _m ), offers( _offers ) {}
101 bool initMaxima(
const TQString& _prop);
103 enum Type { T_STRING = 1, T_DOUBLE = 2, T_NUM = 3, T_BOOL = 4,
104 T_STR_SEQ = 5, T_SEQ = 6 };
110 TQValueList<TQVariant> seq;
114 KService::Ptr service;
116 TQMap<TQString,PreferencesMaxima>& maxima;
117 const KServiceTypeProfile::OfferList& offers;
123 class TDEIO_EXPORT ParseTreeBase :
public TDEShared
126 typedef TDESharedPtr<ParseTreeBase> Ptr;
129 virtual bool eval( ParseContext *_context )
const = 0;
131 virtual ~ParseTreeBase() { };
134 TDEIO_EXPORT ParseTreeBase::Ptr parseConstraints(
const TQString& _constr );
135 TDEIO_EXPORT ParseTreeBase::Ptr parsePreferences(
const TQString& _prefs );
140 class TDEIO_EXPORT ParseTreeOR :
public ParseTreeBase
143 ParseTreeOR( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
145 bool eval( ParseContext *_context )
const;
148 ParseTreeBase::Ptr m_pLeft;
149 ParseTreeBase::Ptr m_pRight;
155 class TDEIO_EXPORT ParseTreeAND :
public ParseTreeBase
158 ParseTreeAND( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
160 bool eval( ParseContext *_context )
const;
163 ParseTreeBase::Ptr m_pLeft;
164 ParseTreeBase::Ptr m_pRight;
170 class TDEIO_EXPORT ParseTreeCMP :
public ParseTreeBase
173 ParseTreeCMP( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2,
int _i ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cmd = _i; }
175 bool eval( ParseContext *_context )
const;
178 ParseTreeBase::Ptr m_pLeft;
179 ParseTreeBase::Ptr m_pRight;
186 class TDEIO_EXPORT ParseTreeIN :
public ParseTreeBase
189 ParseTreeIN( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
191 bool eval( ParseContext *_context )
const;
194 ParseTreeBase::Ptr m_pLeft;
195 ParseTreeBase::Ptr m_pRight;
201 class TDEIO_EXPORT ParseTreeMATCH :
public ParseTreeBase
204 ParseTreeMATCH( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2 ) { m_pLeft = _ptr1; m_pRight = _ptr2; }
206 bool eval( ParseContext *_context )
const;
209 ParseTreeBase::Ptr m_pLeft;
210 ParseTreeBase::Ptr m_pRight;
216 class TDEIO_EXPORT ParseTreeCALC :
public ParseTreeBase
219 ParseTreeCALC( ParseTreeBase *_ptr1, ParseTreeBase *_ptr2,
int _i ) { m_pLeft = _ptr1; m_pRight = _ptr2; m_cmd = _i; }
221 bool eval( ParseContext *_context )
const;
224 ParseTreeBase::Ptr m_pLeft;
225 ParseTreeBase::Ptr m_pRight;
232 class TDEIO_EXPORT ParseTreeBRACKETS :
public ParseTreeBase
235 ParseTreeBRACKETS( ParseTreeBase *_ptr ) { m_pLeft = _ptr; }
237 bool eval( ParseContext *_context )
const {
return m_pLeft->eval( _context ); }
240 ParseTreeBase::Ptr m_pLeft;
246 class TDEIO_EXPORT ParseTreeNOT :
public ParseTreeBase
249 ParseTreeNOT( ParseTreeBase *_ptr ) { m_pLeft = _ptr; }
251 bool eval( ParseContext *_context )
const;
254 ParseTreeBase::Ptr m_pLeft;
260 class TDEIO_EXPORT ParseTreeEXIST :
public ParseTreeBase
263 ParseTreeEXIST(
const char *_id ) { m_id = _id; }
265 bool eval( ParseContext *_context )
const;
274 class TDEIO_EXPORT ParseTreeID :
public ParseTreeBase
277 ParseTreeID(
const char *arg ) { m_str = arg; }
279 bool eval( ParseContext *_context )
const;
288 class TDEIO_EXPORT ParseTreeSTRING :
public ParseTreeBase
291 ParseTreeSTRING(
const char *arg ) { m_str = arg; }
293 bool eval( ParseContext *_context )
const { _context->type = ParseContext::T_STRING; _context->str = m_str;
return true; }
302 class TDEIO_EXPORT ParseTreeNUM :
public ParseTreeBase
305 ParseTreeNUM(
int arg ) { m_int = arg; }
307 bool eval( ParseContext *_context )
const { _context->type = ParseContext::T_NUM; _context->i = m_int;
return true; }
316 class TDEIO_EXPORT ParseTreeDOUBLE :
public ParseTreeBase
319 ParseTreeDOUBLE(
double arg ) { m_double = arg; }
321 bool eval( ParseContext *_context )
const { _context->type = ParseContext::T_DOUBLE; _context->f = m_double;
return true; }
330 class TDEIO_EXPORT ParseTreeBOOL :
public ParseTreeBase
333 ParseTreeBOOL(
bool arg ) { m_bool = arg; }
335 bool eval( ParseContext *_context )
const { _context->type = ParseContext::T_BOOL; _context->b = m_bool;
return true; }
344 class TDEIO_EXPORT ParseTreeMAX2 :
public ParseTreeBase
347 ParseTreeMAX2(
const char *_id ) { m_strId = _id; }
349 bool eval( ParseContext *_context )
const;
358 class TDEIO_EXPORT ParseTreeMIN2 :
public ParseTreeBase
361 ParseTreeMIN2(
const char *_id ) { m_strId = _id; }
363 bool eval( ParseContext *_context )
const;
A namespace for TDEIO globals.