tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Tizen / FilterIterator.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 #ifndef __TIZEN_TIZEN_FILTER_ITERATOR_H__
18 #define __TIZEN_TIZEN_FILTER_ITERATOR_H__
19
20 #include "AbstractFilter.h"
21 #include "AttributeFilter.h"
22 #include "AttributeRangeFilter.h"
23 #include "CompositeFilter.h"
24
25 #include <stack>
26
27 namespace DeviceAPI {
28 namespace Tizen {
29
30 enum FilterIteratorState {
31     FIS_NOT_VALID = 0,
32     FIS_ATTRIBUTE_FILTER,
33     FIS_ATTRIBUTE_RANGE_FILTER,
34     FIS_COMPOSITE_START,
35     FIS_COMPOSITE_END,
36     FIS_END
37 };
38
39 class FilterIterator
40 {
41 public:
42     FilterIterator(AbstractFilterPtr filter);
43
44     FilterIteratorState getState() const;
45     AbstractFilterPtr operator*() const;
46     AbstractFilterPtr getCurrentFilter() const;
47     bool isEnd() const;
48
49     bool isInsideCompositeFilter() const;
50
51     /**
52      * Returns null shared pointer if we are not inside composite filter
53      */
54     CompositeFilterPtr getCurrentCompositeFilter() const;
55
56     /**
57      * Get index of current sub filter (inside composite filter)
58      * Returns 0 if we are not inside composite filter.
59      */
60     int getCurrentCompositeSubFilterIndex() const;
61
62     /**
63      * Return true if current sub filter is the last one in current composite filter
64      * Returns false if we are not inside composite filter.
65      */
66     bool isLastCompositeSubFilter() const;
67
68     void operator++();
69     void operator++(int);
70
71 private:
72     void setReachedEnd();
73     void goToNext(AbstractFilterPtr next);
74     void goToNextInCurCompositeFilter();
75
76     AbstractFilterPtr m_root_filter;
77     FilterIteratorState m_current_state;
78     AbstractFilterPtr m_current_filter;
79
80     struct CompositeIterState {
81         CompositeIterState() :
82                 cur_sub_filter_index(0)
83         {
84         }
85
86         CompositeIterState(const CompositeIterState& other) :
87                 filter(other.filter),
88                 cur_sub_filter_index(other.cur_sub_filter_index)
89         {
90         }
91
92         CompositeFilterPtr filter;
93         int cur_sub_filter_index;
94     };
95
96     std::stack<CompositeIterState> m_composite_stack;
97 };
98
99 } // Tizen
100 } // DeviceAPI
101
102 #endif // __TIZEN_TIZEN_FILTER_ITERATOR_H__