8 template<
typename TYPE>
11 enum class opts{AND = 1, OR = 0, NOT = 2, LEFT_BRACKET = 3, RIGHT_BRACKET = 4};
18 explicit filterStream();
24 void pushAll(
const filterStream& fs);
25 void toPostFix()
const;
27 ~filterStream() =
default;
29 filterStream& operator&&(
const filterStream& fs);
31 filterStream& operator||(
const filterStream& fs);
32 filterStream& operator!();
33 bool operator()(
const TYPE& t)
const;
38 friend filterStream<T> operator&&(
const filter<T>& f,
const filterStream<T>& ofs);
40 friend filterStream<T> operator&&(
const filterStream<T>& ofs,
const filter<T>& f);
44 friend filterStream<T> operator||(
const filter<T>& f,
const filterStream<T>& ofs);
46 friend filterStream<T> operator||(
const filterStream<T>& ofs,
const filter<T>& f);
48 friend filterStream<T> operator!(
const filter<T>& f);
50 friend filterStream<T> operator!(
const filterStream<T>& ofs);
52 friend filterStream<T> group(
const filterStream<T>& ofs);
54 friend filterStream<T> group(
const filter<T>& f);
79 template <
typename TYPE>
80 original::filterStream<TYPE>::filterStream() : stream(), ops(), flag(false) {}
82 template <
typename TYPE>
83 auto original::filterStream<TYPE>::addBrackets() ->
void
85 this->stream.pushBegin(
nullptr);
86 this->stream.pushEnd(
nullptr);
87 this->ops.pushBegin(opts::LEFT_BRACKET);
88 this->ops.pushEnd(opts::RIGHT_BRACKET);
91 template <
typename TYPE>
92 auto original::filterStream<TYPE>::addAndOpt() ->
void
94 this->stream.pushEnd(
nullptr);
95 this->ops.pushEnd(opts::AND);
98 template <
typename TYPE>
99 auto original::filterStream<TYPE>::addOrOpt() ->
void
101 this->stream.pushEnd(
nullptr);
102 this->ops.pushEnd(opts::OR);
105 template <
typename TYPE>
106 auto original::filterStream<TYPE>::addNotOpt() ->
void
108 this->stream.pushBegin(
nullptr);
109 this->ops.pushBegin(opts::NOT);
112 template <
typename TYPE>
113 auto original::filterStream<TYPE>::pushEnd(
const filter<TYPE>& f) ->
void
115 this->stream.pushEnd(std::shared_ptr<
filter<TYPE>>(f.clone()));
118 template <
typename TYPE>
119 auto original::filterStream<TYPE>::pushAll(
const filterStream& fs) ->
void
121 for (
const auto&
filter: fs.stream)
123 this->stream.pushEnd(
filter);
125 for (
const auto& op: fs.ops)
127 this->ops.pushEnd(op);
131 template <
typename TYPE>
132 auto original::filterStream<TYPE>::toPostFix() const ->
void{
139 auto it_stream = this->stream.begins();
140 auto it_ops = this->ops.begins();
142 while (it_stream->isValid()){
143 if (it_stream->get() !=
nullptr){
144 stream_post.pushEnd(it_stream->get());
145 }
else if (it_ops->isValid()){
146 switch (it_ops->get()) {
147 case opts::LEFT_BRACKET:
148 ops_tmp.pushEnd(opts::LEFT_BRACKET);
150 case opts::RIGHT_BRACKET:
151 while (!ops_tmp.empty() && ops_tmp[-1] != opts::LEFT_BRACKET){
152 stream_post.pushEnd(
nullptr);
153 ops_post.pushEnd(ops_tmp.popEnd());
158 ops_tmp.pushEnd(opts::NOT);
161 while (!ops_tmp.empty()
162 && ops_tmp[-1] >= it_ops->get()
163 && ops_tmp[-1] != opts::LEFT_BRACKET){
164 stream_post.pushEnd(
nullptr);
165 ops_post.pushEnd(ops_tmp.popEnd());
167 ops_tmp.pushEnd(it_ops->get());
175 while (!ops_tmp.empty()){
176 stream_post.pushEnd(
nullptr);
177 ops_post.pushEnd(ops_tmp.popEnd());
179 this->stream = stream_post;
180 this->ops = ops_post;
183 template <
typename TYPE>
191 template <
typename TYPE>
199 template <
typename TYPE>
207 template <
typename TYPE>
215 template <
typename TYPE>
216 auto original::filterStream<TYPE>::operator!() ->
filterStream&
223 template <
typename TYPE>
232 template <
typename TYPE>
241 template<
typename TYPE>
247 template <
typename TYPE>
256 template <
typename TYPE>
265 template<
typename TYPE>
271 template <
typename TYPE>
279 template<
typename TYPE>
285 template<
typename TYPE>
293 template<
typename TYPE>
300 template <
typename TYPE>
301 auto original::filterStream<TYPE>::operator()(
const TYPE &t)
const ->
bool {
302 if (!this->flag) this->toPostFix();
305 auto it_stream = this->stream.begins();
306 auto it_ops = this->ops.begins();
308 while (it_stream->isValid()){
309 if (it_stream->get() !=
nullptr){
310 value_stack.pushEnd(it_stream->get()->operator()(t));
311 }
else if (it_ops->isValid()){
312 switch (it_ops->get()) {
314 value_stack[-1] = !value_stack[-1];
317 const bool right = value_stack.popEnd();
318 const bool left = value_stack.popEnd();
319 value_stack.pushEnd(it_ops->get() == opts::AND ?
320 left && right : left || right);
327 return value_stack[-1];
Definition filterStream.h:10