Beta merge 2
[profile/ivi/wrt-plugins-tizen.git] / src / platform / API / Filter / FilterValidator.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file       FilterValidator.h
19  * @author     Kisub Song (kisubs.song@samsung.com)
20  * @version    0.1
21  * @brief
22  */
23
24 #ifndef _API_FILTER_VALIDATOR_H_
25 #define _API_FILTER_VALIDATOR_H_
26
27 #include <map>
28 #include <vector>
29 #include <string>
30 #include <dpl/shared_ptr.h>
31 #include <API/Filter/FilterTypes.h>
32 #include "AnyType.h"
33
34 namespace TizenApis {
35 namespace Api {
36 namespace Tizen {
37
38 class IFilter;
39 typedef DPL::SharedPtr<IFilter> FilterPtr;
40 typedef std::vector<std::string> MatchFlagArray;
41 typedef DPL::SharedPtr<MatchFlagArray> MatchFlagArrayPtr;
42
43 struct PropertyStruct
44 {
45         const char * attributeName;
46     const PrimitiveType type;
47 };
48 typedef PropertyStruct PropertyStructArray[];
49
50 // GoF Visitor Pattern
51 class FilterValidator
52 {
53 private:
54         class Property
55         {
56         public:
57                 Property(PrimitiveType pType) :
58                         type(pType) {}
59                 PrimitiveType type;
60         };
61         typedef DPL::SharedPtr<Property> PropertyPtr;
62         typedef std::map<std::string, PropertyPtr> PropertyMap;
63
64         PropertyMap                             m_properties;
65
66 public:
67         FilterValidator(PropertyStructArray properties);
68
69         virtual ~FilterValidator();
70
71         // validate AttributeFilter
72         virtual bool validateAttribute(std::string& attrName,
73                         MatchFlag& matchFlag, AnyArrayPtr& values, int depth=0);
74
75         // validate AttributeRangeFilter
76         virtual bool validateAttributeRange(std::string& attrName,
77                         AnyPtr& initialValue, AnyPtr& endValue, int depth=0);
78
79         // validate CompositeFilter
80         virtual bool validateComposite(int depth=0);
81 };
82
83 typedef DPL::SharedPtr<FilterValidator> FilterValidatorPtr;
84
85 } // Tizen
86 } // Api
87 } // TizenApis
88
89 #endif // _API_FILTER_VALIDATOR_H_