1 /* Query - query parsing and evaluation 2 * 3 * Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de. 4 * This file may be used under the terms of the MIT License. 5 */ 6 #ifndef QUERY_H 7 #define QUERY_H 8 9 10 #include "Chain.h" 11 #include "Index.h" 12 13 #include <util/Stack.h> 14 #include <SupportDefs.h> 15 16 class Volume; 17 class Term; 18 class Equation; 19 class TreeIterator; 20 class Query; 21 22 23 class Expression { 24 public: 25 Expression(char *expr); 26 ~Expression(); 27 28 status_t InitCheck(); 29 const char *Position() const { return fPosition; } 30 Term *Root() const { return fTerm; } 31 32 protected: 33 Term *ParseOr(char **expr); 34 Term *ParseAnd(char **expr); 35 Term *ParseEquation(char **expr); 36 37 bool IsOperator(char **expr,char op); 38 39 private: 40 Expression(const Expression &); 41 Expression &operator=(const Expression &); 42 // no implementation 43 44 char *fPosition; 45 Term *fTerm; 46 }; 47 48 class Query { 49 public: 50 Query(Volume *volume, Expression *expression, uint32 flags); 51 ~Query(); 52 53 status_t Rewind(); 54 status_t GetNextEntry(struct dirent *, size_t size); 55 56 void SetLiveMode(port_id port, int32 token); 57 void LiveUpdate(Inode *inode, const char *attribute, int32 type, 58 const uint8 *oldKey, size_t oldLength, const uint8 *newKey, size_t newLength); 59 60 Expression *GetExpression() const { return fExpression; } 61 62 private: 63 Volume *fVolume; 64 Expression *fExpression; 65 Equation *fCurrent; 66 TreeIterator *fIterator; 67 Index fIndex; 68 Stack<Equation *> fStack; 69 70 uint32 fFlags; 71 port_id fPort; 72 int32 fToken; 73 74 private: 75 friend class Chain<Query>; 76 77 Query *fNext; 78 }; 79 80 #endif /* QUERY_H */ 81