2a22c0e4673e5498326f79e13bc6a3485013385d
[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                 MatchFlagStrArray matchFlags)
35 {
36         int i;
37         for(i=0; properties[i].attributeName != 0 ; i++)
38                 m_properties[properties[i].attributeName] =
39                                 PropertyPtr(new Property(properties[i].type));
40
41         for(i=0; matchFlags[i] != 0; i++)
42                 m_matchFlags[matchFlags[i]] = true;
43 }
44
45 FilterValidator::~FilterValidator()
46 {
47 }
48
49 bool FilterValidator::validateAttribute(std::string& attrName, AnyArrayPtr& values,
50                 std::string& matchFlag, bool caseSensitive, int depth)
51 {
52         if(m_properties[attrName] == NULL)
53                 return false;
54
55         PropertyPtr prop = m_properties[attrName];
56
57         if(values != NULL)
58         {
59                 AnyArray::iterator arrayIter;
60                 for(arrayIter = values->begin(); arrayIter != values->end(); arrayIter++)
61                         if(!(prop->type & (*arrayIter)->getType()))
62                                 return false;
63         }
64
65         if(m_matchFlags[matchFlag] == false)
66                 return false;
67
68         return true;
69 }
70
71 bool FilterValidator::validateAttributeRange(std::string& attrName,
72                 AnyPtr& initialValue, AnyPtr& endValue, int depth)
73 {
74         if(m_properties[attrName] == NULL)
75                 return false;
76
77         PropertyPtr prop = m_properties[attrName];
78
79         if(prop->type != initialValue->getType())
80                 return false;
81
82         if(prop->type != endValue->getType())
83                 return false;
84
85         return true;
86 }
87
88 bool FilterValidator::validateComposite(int depth)
89 {
90         return true;
91 }
92
93 } // Tizen
94 } // Api
95 } // TizenApis