2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __TIZEN_TIZEN_ABSTRACT_FILTER_H__
18 #define __TIZEN_TIZEN_ABSTRACT_FILTER_H__
24 //#include <JSArray.h>
27 #include "common/filter-utils.h"
33 typedef std::shared_ptr<AbstractFilter> AbstractFilterPtr;
34 typedef std::vector<AbstractFilterPtr> AbstractFilterPtrVector;
36 struct AbstractFilterHolder {
37 AbstractFilterPtr ptr;
40 enum FilterType { ABSTRACT_FILTER = 0, ATTRIBUTE_FILTER, ATTRIBUTE_RANGE_FILTER, COMPOSITE_FILTER };
42 class FilterableObject {
44 virtual ~FilterableObject() {
47 virtual bool isMatchingAttribute(const std::string& attribute_name,
48 const common::AttributeMatchFlag match_flag,
49 AnyPtr match_value) const = 0;
51 virtual bool isMatchingAttributeRange(const std::string& attribute_name, AnyPtr initial_value,
52 AnyPtr end_value) const = 0;
55 class AbstractFilter {
57 AbstractFilter(FilterType type = ABSTRACT_FILTER);
58 virtual ~AbstractFilter();
60 FilterType getFilterType() const;
62 // static JSValueRef makeJSValue(JSContextRef context, AbstractFilterPtr priv);
63 // static AbstractFilterPtr getPrivateObject(JSContextRef context,
66 virtual bool isMatching(const FilterableObject* const filtered_object) const;
69 FilterType m_filter_type;
72 // class JSFilterArray : public Common::JSArray<AbstractFilterPtr> {
74 // JSFilterArray(JSContextRef ctx, JSObjectRef array):
75 // JSArray<AbstractFilterPtr>(ctx, array, AbstractFilter::getPrivateObject,
76 // AbstractFilter::makeJSValue)
79 // JSFilterArray(JSContextRef ctx):
80 // JSArray<AbstractFilterPtr>(ctx, AbstractFilter::getPrivateObject,
81 // AbstractFilter::makeJSValue)
84 // void operator=(const std::vector<AbstractFilterPtr>& list)
90 namespace FilterUtils {
92 bool isAnyStringMatching(const std::string& key, const std::vector<std::string>& values,
93 common::AttributeMatchFlag flag);
94 bool isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& initial_value,
95 tizen::AnyPtr& end_value);
96 bool isInRange(const unsigned long messageCount, const unsigned long initial_value,
97 const unsigned long end_value);
98 inline bool isBetweenTimeRange(const time_t timestamp, const time_t from, const time_t to) {
99 return (difftime(timestamp, from) >= 0.0) && (difftime(to, timestamp) >= 0.0);
103 * isMatching() behavior for different common::AttributeMatchFlags:
104 * - EXACTLY - value and filter_value's value must be identical
105 * - EXISTS - false is returned always. isMatching do not check if EXISTS filter matches.
106 * Testing against EXISTS match flag has to be done in another function, i.e. before calling
108 * - FULLSTRING, CONTAINS, STARTSWITH, ENDSWITH - applicable for strings only,
109 * used to filter values of other types result in no-match
111 bool isMatching(const Any& filter_value, const std::string& value, common::AttributeMatchFlag flag);
112 bool isMatching(const Any& filter_value, const bool value, common::AttributeMatchFlag flag);
113 bool isMatching(const Any& filter_value, const unsigned long value,
114 common::AttributeMatchFlag flag);
116 } // namespace FilterUtils
121 #endif // __TIZEN_TIZEN_ABSTRACT_FILTER_H__