Add DRAFT stubs for Vehicle plugin
[profile/ivi/wrt-plugins-tizen.git] / src / platform / API / Filter / FilterValidator.cpp
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       IFilterTracer.cpp
19  * @author     Kisub Song (kisubs.song@samsung.com)
20  * @version    0.1
21  * @brief
22  */
23
24 #include <algorithm>
25 #include "FilterValidator.h"
26
27 namespace TizenApis {
28 namespace Api {
29 namespace Tizen {
30
31 using namespace std;
32
33 FilterValidator::FilterValidator(PropertyStructArray properties)
34 {
35         int i;
36         for(i=0; properties[i].attributeName != 0 ; i++)
37                 m_properties[properties[i].attributeName] =
38                                 PropertyPtr(new Property(properties[i].type));
39 }
40
41 FilterValidator::~FilterValidator()
42 {
43 }
44
45 bool FilterValidator::validateAttribute(std::string& attrName,
46                 MatchFlag& matchFlag, AnyPtr& matchValue, int depth)
47 {
48         if(m_properties.find(attrName) == m_properties.end())
49                 return false;
50
51         if(matchValue == NULL)
52                 return false;
53
54         PropertyPtr prop = m_properties[attrName];
55
56         if(matchFlag == MATCH_EXISTS)
57                 return true;
58
59         if(!matchValue->isType(prop->type))
60                 return false;
61
62         return true;
63 }
64
65 bool FilterValidator::validateAttributeRange(std::string& attrName,
66                 AnyPtr& initialValue, AnyPtr& endValue, int depth)
67 {
68         if(initialValue == NULL || endValue == NULL)
69                 return false;
70
71         if(m_properties.find(attrName) == m_properties.end())
72                 return false;
73
74         PropertyPtr prop = m_properties[attrName];
75
76         bool initialValueIsNull = initialValue->isNullOrUndefined();
77         bool endValueIsNull = endValue->isNullOrUndefined();
78
79         // Invalid if both values are null
80         if(initialValueIsNull && endValueIsNull)
81                 return false;
82
83         if(!initialValueIsNull && !initialValue->isType(prop->type))
84                 return false;
85
86         if(!endValueIsNull && !endValue->isType(prop->type))
87                 return false;
88
89         return true;
90 }
91
92 bool FilterValidator::validateComposite(int depth)
93 {
94         return true;
95 }
96
97 } // Tizen
98 } // Api
99 } // TizenApis