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