btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / storage / QueryPredicate.h
blob252d26eb797d4d1164b30b46b434d72205c1cd6b
1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the MIT License.
4 //---------------------------------------------------------------------
5 /*!
6 \file QueryPredicate.h
7 BQuery predicate helper classes interface declaration.
8 */
9 #ifndef _QUERY_PREDICATE_H
10 #define _QUERY_PREDICATE_H
12 #include <stdio.h>
14 #include <List.h>
15 #include <Query.h>
16 #include <String.h>
18 namespace BPrivate {
19 namespace Storage {
21 // QueryNode
22 class QueryNode {
23 public:
24 QueryNode();
25 virtual ~QueryNode();
27 virtual uint32 Arity() const = 0;
28 virtual status_t SetChildAt(QueryNode *child, int32 index) = 0;
29 virtual QueryNode *ChildAt(int32 index) = 0;
31 virtual status_t GetString(BString &predicate) = 0;
34 // LeafNode
35 class LeafNode : public QueryNode {
36 public:
37 LeafNode();
38 virtual ~LeafNode();
40 virtual uint32 Arity() const;
41 virtual status_t SetChildAt(QueryNode *child, int32 index);
42 virtual QueryNode *ChildAt(int32 index);
45 // UnaryNode
46 class UnaryNode : public QueryNode {
47 public:
48 UnaryNode();
49 virtual ~UnaryNode();
51 virtual uint32 Arity() const;
52 virtual status_t SetChildAt(QueryNode *child, int32 index);
53 virtual QueryNode *ChildAt(int32 index);
55 protected:
56 QueryNode *fChild;
59 // BinaryNode
60 class BinaryNode : public QueryNode {
61 public:
62 BinaryNode();
63 virtual ~BinaryNode();
65 virtual uint32 Arity() const;
66 virtual status_t SetChildAt(QueryNode *child, int32 index);
67 virtual QueryNode *ChildAt(int32 index);
69 protected:
70 QueryNode *fChild1;
71 QueryNode *fChild2;
74 // AttributeNode
75 class AttributeNode : public LeafNode {
76 public:
77 AttributeNode(const char *attribute);
79 virtual status_t GetString(BString &predicate);
81 private:
82 BString fAttribute;
85 // StringNode
86 class StringNode : public LeafNode {
87 public:
88 StringNode(const char *value, bool caseInsensitive = false);
90 virtual status_t GetString(BString &predicate);
92 inline const char *Value() const { return fValue.String(); }
94 private:
95 BString fValue;
98 // DateNode
99 class DateNode : public LeafNode {
100 public:
101 DateNode(const char *value);
103 virtual status_t GetString(BString &predicate);
105 private:
106 BString fValue;
109 // ValueNode
110 template<typename ValueType>
111 class ValueNode : public LeafNode {
112 public:
113 ValueNode(const ValueType &value);
115 virtual status_t GetString(BString &predicate);
117 private:
118 ValueType fValue;
121 // constructor
122 template<typename ValueType>
123 ValueNode<ValueType>::ValueNode(const ValueType &value)
124 : LeafNode(),
125 fValue(value)
129 // GetString
130 template<typename ValueType>
131 status_t
132 ValueNode<ValueType>::GetString(BString &predicate)
134 predicate.SetTo("");
135 predicate << fValue;
136 return B_OK;
139 // specializations for float and double
140 template<> status_t ValueNode<float>::GetString(BString &predicate);
141 template<> status_t ValueNode<double>::GetString(BString &predicate);
144 // short hands
145 typedef ValueNode<int32> Int32ValueNode;
146 typedef ValueNode<uint32> UInt32ValueNode;
147 typedef ValueNode<int64> Int64ValueNode;
148 typedef ValueNode<uint64> UInt64ValueNode;
149 typedef ValueNode<float> FloatValueNode;
150 typedef ValueNode<double> DoubleValueNode;
153 // SpecialOpNode
154 class SpecialOpNode : public LeafNode {
155 public:
156 SpecialOpNode(query_op op);
158 virtual status_t GetString(BString &predicate);
160 private:
161 query_op fOp;
164 // UnaryOpNode
165 class UnaryOpNode : public UnaryNode {
166 public:
167 UnaryOpNode(query_op op);
169 virtual status_t GetString(BString &predicate);
171 private:
172 query_op fOp;
175 // BinaryOpNode
176 class BinaryOpNode : public BinaryNode {
177 public:
178 BinaryOpNode(query_op op);
180 virtual status_t GetString(BString &predicate);
182 private:
183 query_op fOp;
187 // QueryStack
188 class QueryStack {
189 public:
190 QueryStack();
191 virtual ~QueryStack();
193 status_t PushNode(QueryNode *node);
194 QueryNode *PopNode();
196 status_t ConvertToTree(QueryNode *&rootNode);
198 private:
199 status_t _GetSubTree(QueryNode *&rootNode);
201 private:
202 BList fNodes;
205 }; // namespace Storage
206 }; // namespace BPrivate
208 #endif // _QUERY_PREDICATE_H