BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / ramfs / Query.h
blob0fadfc4961a3a6db75f276c317f8c4e2682a740d
1 /* Query - query parsing and evaluation
3 * Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de.
4 * This file may be used under the terms of the MIT License.
6 * Adjusted by Ingo Weinhold <bonefish@cs.tu-berlin.de> for usage in RAM FS.
7 */
8 #ifndef QUERY_H
9 #define QUERY_H
12 #include <OS.h>
13 #include <SupportDefs.h>
15 #include <util/DoublyLinkedList.h>
17 #include "Index.h"
18 #include "Stack.h"
19 #include "ramfs.h"
21 class Entry;
22 class Equation;
23 class IndexIterator;
24 class Node;
25 class Query;
26 class Term;
27 class Volume;
30 #define B_QUERY_NON_INDEXED 0x00000002
33 // Wraps the RAM FS Index to provide the interface required by the Query
34 // implementation. At least most of it.
36 // IndexWrapper
37 class IndexWrapper {
38 public:
39 IndexWrapper(Volume *volume);
41 status_t SetTo(const char *name);
42 void Unset();
44 uint32 Type() const;
45 off_t GetSize() const;
46 int32 KeySize() const;
48 private:
49 friend class IndexIterator;
51 Volume *fVolume;
52 Index *fIndex;
55 // IndexIterator
56 class IndexIterator {
57 public:
58 IndexIterator(IndexWrapper *indexWrapper);
60 status_t Find(const uint8 *const key, size_t keyLength);
61 status_t Rewind();
62 status_t GetNextEntry(uint8 *buffer, uint16 *keyLength, size_t bufferSize,
63 Entry **entry);
65 private:
66 IndexWrapper *fIndexWrapper;
67 IndexEntryIterator fIterator;
68 bool fInitialized;
72 class Expression {
73 public:
74 Expression(char *expr);
75 ~Expression();
77 status_t InitCheck();
78 const char *Position() const { return fPosition; }
79 Term *Root() const { return fTerm; }
81 protected:
82 Term *ParseOr(char **expr);
83 Term *ParseAnd(char **expr);
84 Term *ParseEquation(char **expr);
86 bool IsOperator(char **expr,char op);
88 private:
89 Expression(const Expression &);
90 Expression &operator=(const Expression &);
91 // no implementation
93 char *fPosition;
94 Term *fTerm;
97 class Query : public DoublyLinkedListLinkImpl<Query> {
98 public:
99 Query(Volume *volume, Expression *expression, uint32 flags);
100 ~Query();
102 status_t Rewind();
103 status_t GetNextEntry(struct dirent *, size_t size);
105 void SetLiveMode(port_id port, int32 token);
106 void LiveUpdate(Entry *entry, Node* node, const char *attribute,
107 int32 type, const uint8 *oldKey, size_t oldLength,
108 const uint8 *newKey, size_t newLength);
110 Expression *GetExpression() const { return fExpression; }
112 private:
113 // void SendNotification(Entry* entry)
115 private:
116 Volume *fVolume;
117 Expression *fExpression;
118 Equation *fCurrent;
119 IndexIterator *fIterator;
120 IndexWrapper fIndex;
121 Stack<Equation *> fStack;
123 uint32 fFlags;
124 port_id fPort;
125 int32 fToken;
126 bool fNeedsEntry;
129 #endif /* QUERY_H */