tizen 2.3.1 release
[framework/web/wearable/wrt-security.git] / ace / include / ace / Condition.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 // File:   Condition.h
18 // Author: notroot
19 //
20 // Created on June 3, 2009, 9:00 AM
21 //
22 #ifndef _CONDITION_H
23 #define _CONDITION_H
24
25 #include <list>
26 #include <set>
27 #include <iostream>
28 #include <dpl/foreach.h>
29
30 #include "Attribute.h"
31 #include "Effect.h"
32 #include "TreeNode.h"
33
34 class Condition
35 {
36   public:
37     enum CombineType
38     {
39         AND, OR
40     };
41
42     void addCondition(const Condition & condition)
43     {
44         this->conditions.push_back(condition);
45     }
46
47     void addAttribute(const Attribute & attribute)
48     {
49         this->attributes.push_back(attribute);
50     }
51
52     void setCombineType(CombineType type)
53     {
54         this->combineType = type;
55     }
56
57     Condition() : combineType(AND),
58         parent(NULL)
59     {
60     }
61
62     Condition(CombineType type) : combineType(type),
63         parent(NULL)
64     {
65     }
66
67     virtual ~Condition()
68     {
69     }
70
71     Condition * getParent()
72     {
73         return this->parent;
74     }
75
76     void setParent(Condition * condition)
77     {
78         this->parent = condition;
79     }
80
81     Attribute::MatchResult evaluateCondition(
82             const AttributeSet * attrSet) const;
83
84     friend std::ostream & operator<<(std::ostream & out,
85             Condition & condition)
86     {
87         FOREACH (it, condition.attributes)
88         {
89             out << *it;
90         }
91         return out;
92     }
93     //[CR] change function name
94     void getAttributes(AttributeSet * attrSet);
95
96   private:
97     Attribute::MatchResult evaluateChildConditions(
98             const AttributeSet * attrSet,
99             bool &isFinalMatch,
100             bool & undefinedMatchFound) const;
101
102     Attribute::MatchResult evaluateAttributes(
103             const AttributeSet * attrSet,
104             bool& isFinalMatch,
105             bool & undefinedMatchFound) const;
106
107     // KW     Attribute::MatchResult performANDalgorithm(const std::set<Attribute> * attributes) const;
108
109     // KW     Attribute::MatchResult performORalgorithm(const std::set<Attribute> * attributes) const;
110
111     bool isEmpty() const
112     {
113         return attributes.empty() && conditions.empty();
114     }
115
116     bool isAndCondition() const
117     {
118         return combineType == AND;
119     }
120
121     bool isOrCondition() const
122     {
123         return combineType == OR;
124     }
125
126     std::list<Condition> conditions;
127     CombineType combineType;
128     std::list<Attribute> attributes;
129     Condition *parent;
130 };
131
132 #endif    /* _CONDITION_H */
133