tizen 2.3.1 release
[framework/web/wearable/wrt-security.git] / ace / include / ace-dao-ro / BaseAttribute.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  *
19  * @file       IAttribute.h
20  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
21  * @version    0.1
22  * @brief
23  */
24
25 #ifndef ACCESS_CONTROL_DAO_BASEATTRIBUTE_H_
26 #define ACCESS_CONTROL_DAO_BASEATTRIBUTE_H_
27
28 #include <list>
29 #include <set>
30 #include <string>
31 #include <memory>
32 #include <dpl/assert.h>
33
34 namespace AceDB {
35
36 class BaseAttribute;
37 typedef std::shared_ptr<BaseAttribute> BaseAttributePtr;
38
39 class BaseAttribute
40 {
41
42   public:
43     /**
44      * Types of attributes
45      */
46     enum class Type { Subject, Environment, Resource, FunctionParam,
47                       WidgetParam, Undefined };
48
49     struct UnaryPredicate
50     {
51       public:
52         UnaryPredicate(const AceDB::BaseAttribute *comp = NULL) :
53             m_priv(comp)
54         {
55         }
56
57         bool operator()(const AceDB::BaseAttributePtr &comp)
58         {
59             Assert(m_priv != NULL);
60             if (m_priv->getName()->compare(*comp->getName()) != 0) {
61                 return false;
62             }
63             return m_priv->getType() == comp->getType();
64         }
65
66         bool operator()(const AceDB::BaseAttributePtr &comp1,
67                         const AceDB::BaseAttributePtr &comp2)
68         {
69             if (comp1->getType() != comp2->getType()) {
70                 return comp1->getType() < comp2->getType();
71             }
72             return comp1->getName()->compare(*comp2->getName()) < 0;
73         }
74
75       private:
76           const AceDB::BaseAttribute *m_priv;
77     };
78
79   public:
80     BaseAttribute() :
81         m_typeId(Type::Undefined),
82         m_undetermindState(false)
83     {}
84
85     virtual void setName(const std::string& name)
86     {
87         m_name = name;
88     }
89     virtual void setName(const std::string* name)
90     {
91         m_name = *name;
92     }
93
94     virtual void setType(const Type& type)
95     {
96         m_typeId = type;
97     }
98     virtual Type getType() const
99     {
100         return m_typeId;
101     }
102
103     virtual const std::string* getName() const
104     {
105         return &m_name;
106     }
107
108     //TODO think
109     virtual void setUndetermind(bool tmp)
110     {
111         m_undetermindState = tmp;
112     }
113     virtual bool isUndetermind() const
114     {
115         return m_undetermindState;
116     }
117     virtual std::list<std::string> * getValue() const
118     {
119         return const_cast<std::list<std::string>* >(&value);
120     }
121     virtual bool isValueEmpty() const
122     {
123         return value.empty();
124     }
125
126     virtual void setValue(const std::list<std::string>& arg)
127     {
128         value = arg;
129     }
130
131     virtual ~BaseAttribute()
132     {
133     }
134
135     static const char * typeToString(Type type);
136
137     virtual std::string toString() const;
138
139   protected:
140     std::string m_name;
141     Type m_typeId;
142     bool m_undetermindState;
143     std::list<std::string> value; //string bag list
144 };
145
146 typedef std::set<BaseAttributePtr, BaseAttribute::UnaryPredicate> BaseAttributeSet;
147
148 }
149
150 #endif