xref: /haiku/src/add-ons/kernel/file_systems/bfs/Query.h (revision 5115ca085884f7b604a3d607688f0ca20fb7cf57)
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 #include "system_dependencies.h"
10 
11 #include "Chain.h"
12 #include "Index.h"
13 
14 class Volume;
15 class Term;
16 class Equation;
17 class TreeIterator;
18 class Query;
19 
20 
21 class Expression {
22 	public:
23 		Expression(char *expr);
24 		~Expression();
25 
26 		status_t InitCheck();
27 		const char *Position() const { return fPosition; }
28 		Term *Root() const { return fTerm; }
29 
30 	protected:
31 		Term *ParseOr(char **expr);
32 		Term *ParseAnd(char **expr);
33 		Term *ParseEquation(char **expr);
34 
35 		bool IsOperator(char **expr,char op);
36 
37 	private:
38 		Expression(const Expression &);
39 		Expression &operator=(const Expression &);
40 			// no implementation
41 
42 		char *fPosition;
43 		Term *fTerm;
44 };
45 
46 class Query {
47 	public:
48 		Query(Volume *volume, Expression *expression, uint32 flags);
49 		~Query();
50 
51 		status_t Rewind();
52 		status_t GetNextEntry(struct dirent *, size_t size);
53 
54 		void SetLiveMode(port_id port, int32 token);
55 		void LiveUpdate(Inode *inode, const char *attribute, int32 type,
56 			const uint8 *oldKey, size_t oldLength, const uint8 *newKey, size_t newLength);
57 
58 		Expression *GetExpression() const { return fExpression; }
59 
60 	private:
61 		Volume			*fVolume;
62 		Expression		*fExpression;
63 		Equation		*fCurrent;
64 		TreeIterator	*fIterator;
65 		Index			fIndex;
66 		Stack<Equation *> fStack;
67 
68 		uint32			fFlags;
69 		port_id			fPort;
70 		int32			fToken;
71 
72 	private:
73 		friend class Chain<Query>;
74 
75 		Query			*fNext;
76 };
77 
78 #endif	/* QUERY_H */
79