Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / resource / FUi_ResourceMap.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FUi_ResourceMap.h
19  * @brief               This is the header file for Map class.
20  * @version             3.0
21  *
22  * This header file contains declaration of Map class.
23  * The ActionEvent class can call listener's method. So, when event occurred,
24  * application can handle it appropriately.
25  *
26  */
27 #ifndef _FUI_INTERNAL_RESOURCE_MAP_H_
28 #define _FUI_INTERNAL_RESOURCE_MAP_H_
29
30 #include <FBaseString.h>
31 #include <FBaseColHashMapT.h>
32 #include <FBaseSysLog.h>
33
34 namespace Tizen { namespace Base {
35         class String;
36 }}// Tizen::Base
37
38 namespace Tizen { namespace Ui { namespace _Resource
39 {
40 enum _ResourceType
41 {
42         RESOURCE_TYPE_NONE,
43         RESOURCE_TYPE_COLOR,
44         RESOURCE_TYPE_DIMENSION,
45         RESOURCE_TYPE_FIXED_VALUE,
46         RESOURCE_TYPE_FONT,
47         RESOURCE_TYPE_IMAGE,
48         RESOURCE_TYPE_SHAPE,
49         RESOURCE_TYPE_MAX,
50 };
51
52 class _ResourceHashCodeProvider
53         : public Tizen::Base::Collection::IHashCodeProviderT <Tizen::Base::String>
54 {
55 public:
56         _ResourceHashCodeProvider(void) {}
57         virtual ~_ResourceHashCodeProvider(void) {}
58
59         virtual int GetHashCode(const Tizen::Base::String& obj) const
60         {
61                 return obj.GetHashCode();
62         }
63 };
64
65 class _ResourceComparer
66         : public Tizen::Base::Collection::IComparerT <Tizen::Base::String>
67 {
68 public:
69         _ResourceComparer(void) {}
70         virtual ~_ResourceComparer(void) {}
71         virtual result Compare(const Tizen::Base::String& obj1, const Tizen::Base::String& obj2, int& cmp) const
72         {
73                 if (obj1 == obj2)
74                 {
75                         cmp = 0;
76                         return E_SUCCESS;
77                 }
78                 else
79                 {
80                         cmp = -1;
81                         return E_SUCCESS;
82                 }
83         }
84 };
85
86 template<class ValueType>
87 class Map
88         : public Tizen::Base::Collection::HashMapT<Tizen::Base::String, ValueType>
89 {
90 public:
91         Map(_ResourceType type)
92                 : Tizen::Base::Collection::HashMapT<Tizen::Base::String, ValueType>()
93                 , __type(type)
94         {
95         __pProvider = new _ResourceHashCodeProvider;
96         SysTryReturnVoidResult(NID_UI, __pProvider, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
97         __pComparer = new _ResourceComparer;
98         SysTryReturnVoidResult(NID_UI, __pComparer, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation is failed.");
99         __modifiedItemTable.Construct(0,0,*__pProvider, *__pComparer);
100         }
101         virtual ~Map(void)
102         {
103                 result r = E_SUCCESS;
104                 Tizen::Base::Collection::IMapEnumeratorT<Tizen::Base::String, ValueType >* pMapEnum = null;
105                 if (Tizen::Base::Collection::HashMapT<Tizen::Base::String, ValueType>::GetCount() > 0)
106                 {
107                         pMapEnum = Tizen::Base::Collection::HashMapT<Tizen::Base::String, ValueType>::GetMapEnumeratorN();
108                         SysTryReturn(NID_UI_ANIM, (pMapEnum != null), , E_SYSTEM, "[E_SYSTEM] System Error.");
109
110                         Tizen::Base::Collection::MapEntryT<Tizen::Base::String, ValueType> value;
111                         while ((pMapEnum->MoveNext() == E_SUCCESS))
112                         {
113                                 r = pMapEnum->GetCurrent(value);
114                                 SysTryCatch(NID_UI_ANIM, (r == E_SUCCESS), r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System Error.");
115
116                                 ValueType pObj = value.GetValue();
117                                 delete pObj;
118                         }
119                         Tizen::Base::Collection::HashMapT<Tizen::Base::String, ValueType>::RemoveAll();
120                         delete pMapEnum;
121                 }
122                 delete __pProvider;
123                 __pProvider = null;
124                 delete __pComparer;
125                 __pComparer = null;
126                 return;
127
128                 CATCH:
129                 delete pMapEnum;
130         }
131         void Initialize(void)
132         {
133                 result r = E_SUCCESS;
134                 Tizen::Base::Collection::MapEntryT <Tizen::Base::String, ValueType> currentEntry;
135                 Tizen::Base::Collection::IEnumeratorT <Tizen::Base::Collection::MapEntryT <Tizen::Base::String, ValueType> >* pMapEnumerator = Tizen::Base::Collection::HashMapT<Tizen::Base::String, ValueType>::GetMapEnumeratorN();
136
137                 SysTryReturn(NID_UI, pMapEnumerator, , E_SYSTEM, "[E_SYSTEM] Getting enumerator is failed.");
138
139                 while ((pMapEnumerator->MoveNext() == E_SUCCESS))
140                 {
141                         ValueType pObject = null;
142                         r = pMapEnumerator->GetCurrent(currentEntry);
143                         SysTryCatch(NID_UI, r == E_SUCCESS, r = E_SYSTEM, r, "[E_SYSTEM] removing data binding is failed.");
144
145                         pObject = currentEntry.GetValue();
146                         SysTryCatch(NID_UI, pObject, r = E_SYSTEM, r, "[E_SYSTEM] UpdateAllBindings is failed.");
147                         delete pObject;
148                 }
149                 delete pMapEnumerator;
150                 pMapEnumerator = null;
151                 Tizen::Base::Collection::HashMapT<Tizen::Base::String, ValueType>::RemoveAll();
152
153                 CATCH:
154                 delete pMapEnumerator;
155         }
156         result SetValue(const Tizen::Base::String& key, const ValueType& value)
157         {
158                 ValueType _value = null;
159                 if(GetValue(key, _value) == E_SUCCESS)
160                 {
161                         __modifiedItemTable.Add(key, true);
162                         *_value = *value;
163                         return E_SUCCESS;
164                 }
165                 else
166                 {
167                         return E_OBJ_NOT_FOUND;
168                 }
169         }
170         _ResourceType GetMode(void) const
171         {
172                 return __type;
173         }
174         void SetInformation (const Tizen::Base::String& information)
175         {
176                 __information = information;
177         }
178         Tizen::Base::String GetInformation(void)
179         {
180                 return __information;
181         }
182         bool IsUserThemeItem(const Tizen::Base::String& key)
183         {
184                 bool exist = false;
185                 __modifiedItemTable.ContainsKey(key, exist);
186                 return exist;
187         }
188
189 private:
190         Map(void);
191         Map(const Map&);
192         Map& operator =(const Map&);
193 private:
194         const _ResourceType __type;
195         Tizen::Base::String __information;
196         Tizen::Base::Collection::HashMapT<Tizen::Base::String, bool> __modifiedItemTable;
197         Tizen::Base::Collection::IHashCodeProviderT<Tizen::Base::String>* __pProvider;
198         Tizen::Base::Collection::IComparerT<Tizen::Base::String>* __pComparer;
199
200 };
201 }}}
202
203 #endif // _FUI_INTERNAL_RESOURCE_MAP_H_