Nebula
Loading...
Searching...
No Matches
filterset.h
Go to the documentation of this file.
1#pragma once
2#ifndef DB_FILTERSET_H
3#define DB_FILTERSET_H
4//------------------------------------------------------------------------------
15#include "core/refcounted.h"
16#include "attr/attribute.h"
17#include "util/simpletree.h"
18
19//------------------------------------------------------------------------------
20namespace Db
21{
22class Command;
23
25{
27public:
29 FilterSet();
31 virtual ~FilterSet();
33 void Clear();
35 void ClearDirtyFlag();
37 bool IsDirty() const;
39 bool IsEmpty() const;
41 void BeginBlock();
43 void EndBlock();
45 void AddEqualCheck(const Attr::Attribute& attr);
47 void AddGreaterThenCheck(const Attr::Attribute& attr);
49 void AddLessThenCheck(const Attr::Attribute& attr);
53 void AddLessOrEqualCheck(const Attr::Attribute& attr);
55 void AddAnd();
57 void AddOr();
59 void AddNot();
61 virtual Util::String AsSqlWhere() const;
63 virtual void BindValuesToCommand(const Ptr<Command>& cmd, IndexT wildcardStartIndex);
64
65protected:
66 class Token
67 {
68 public:
85 Token();
87 Token(Type t);
89 Token(Type t, const Attr::Attribute& attr);
91 Type GetType() const;
93 const Attr::Attribute& GetAttr() const;
94
95 private:
98 };
99
104};
105
106//------------------------------------------------------------------------------
109inline void
111{
112 this->isDirty = false;
113}
114
115//------------------------------------------------------------------------------
118inline bool
120{
121 return this->isDirty;
122}
123
124//------------------------------------------------------------------------------
128 type(Root)
129{
130 // empty
131}
132
133//------------------------------------------------------------------------------
137 type(t)
138{
139 // empty
140}
141
142//------------------------------------------------------------------------------
146 type(t),
147 attr(a)
148{
149 // empty
150}
151
152//------------------------------------------------------------------------------
155inline bool
157{
158 return (this->tokens.Root().Size() == 0);
159}
160
161//------------------------------------------------------------------------------
166{
167 return this->type;
168}
169
170//------------------------------------------------------------------------------
173inline const Attr::Attribute&
175{
176 return this->attr;
177}
178
179} // namespace Db
180//------------------------------------------------------------------------------
181#endif
A compiletime-typesafe key/value pair.
Definition attribute.h:32
The common base class of Nebula.
Definition refcounted.h:38
Definition filterset.h:67
Type GetType() const
get type
Definition filterset.h:165
Attr::Attribute attr
Definition filterset.h:97
Type
token types
Definition filterset.h:71
@ And
Definition filterset.h:78
@ NotEqual
Definition filterset.h:73
@ Greater
Definition filterset.h:74
@ Equal
Definition filterset.h:72
@ Less
Definition filterset.h:75
@ GreaterEqual
Definition filterset.h:76
@ LessEqual
Definition filterset.h:77
@ Or
Definition filterset.h:79
@ Block
Definition filterset.h:81
@ Not
Definition filterset.h:80
@ Root
Definition filterset.h:82
const Attr::Attribute & GetAttr() const
get attribute
Definition filterset.h:174
Token()
default constructor
Definition filterset.h:127
Type type
Definition filterset.h:96
Implements a filter for datatbase data using a condition tree.
Definition filterset.h:25
void AddGreaterOrEqualCheck(const Attr::Attribute &attr)
add a greater-equals check
Definition filterset.cc:133
void EndBlock()
end the current level in the condition tree (close current bracket)
Definition filterset.cc:67
void Clear()
clear the filter
Definition filterset.cc:37
__DeclareClass(FilterSet)
FilterSet()
constructor
Definition filterset.cc:18
void AddAnd()
add a boolean AND
Definition filterset.cc:162
void AddLessThenCheck(const Attr::Attribute &attr)
add a lesser check
Definition filterset.cc:118
Util::Array< Attr::Attribute > bindAttrs
Definition filterset.h:102
void AddGreaterThenCheck(const Attr::Attribute &attr)
add a greater check
Definition filterset.cc:103
void AddOr()
add a boolean OR
Definition filterset.cc:175
void AddLessOrEqualCheck(const Attr::Attribute &attr)
add a lesser-equals check
Definition filterset.cc:148
void ClearDirtyFlag()
clear the dirty state of the filter (every op on the filter will make it dirty)
Definition filterset.h:110
Util::SimpleTree< Token > tokens
Definition filterset.h:100
bool IsEmpty() const
return true if the filter is empty
Definition filterset.h:156
void AddNot()
add a boolean NOT
Definition filterset.cc:188
Util::SimpleTree< Token >::Node * curToken
Definition filterset.h:101
bool isDirty
Definition filterset.h:103
void AddEqualCheck(const Attr::Attribute &attr)
add an equality check
Definition filterset.cc:88
virtual void BindValuesToCommand(const Ptr< Command > &cmd, IndexT wildcardStartIndex)
bind filter attribute values to command
Definition filterset.cc:213
virtual ~FilterSet()
destructor
Definition filterset.cc:28
virtual Util::String AsSqlWhere() const
compile into an SQL WHERE statement
Definition filterset.cc:202
void BeginBlock()
begin a new level in the condition tree (opens a bracket)
Definition filterset.cc:52
bool IsDirty() const
return true if the filter is dirty
Definition filterset.h:119
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:60
public node class
Definition simpletree.h:23
A simple tree class which stores its nodes in Util::Arrays.
Definition simpletree.h:19
Definition column.cc:10
Nebula's universal string class.
Definition string.h:50
int IndexT
Definition types.h:48