modify license, permission and remove ^M char
[platform/framework/native/uifw.git] / src / ui / FUi_PropertyUtils.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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_PropertyUtils.cpp
19  * @brief               This is the implementation file for _PropertyUtils class.
20  */
21
22 #include <new>
23 #include <FBaseErrors.h>
24 #include <FBaseSysLog.h>
25 #include "FUi_PropertyUtils.h"
26
27 using namespace Tizen::Base;
28
29 namespace Tizen { namespace Ui
30 {
31
32 /**
33  * @class       _StringComparer
34  * @brief       We implemented new custom string-comparer for performance.
35  * @since 2.1
36  *
37  */
38
39 // _StringComparer class
40 _StringComparer::_StringComparer(void)
41 {
42
43 }
44
45 _StringComparer::~_StringComparer(void)
46 {
47
48 }
49
50 result
51 _StringComparer::Compare(const Object& obj1, const Object& obj2, int& cmp) const
52 {
53         const String* pString1 = static_cast<const String*>(&obj1);
54         const String* pString2 = static_cast<const String*>(&obj2);
55
56         // dirty optimization. HaspMap do not care of the sign. It is interested only in zero or not.
57         if (*pString1 == *pString2)
58         {
59                 cmp = 0;
60         }
61         else
62         {
63                 cmp = -1;
64         }
65
66         return E_SUCCESS;
67 }
68
69 // _StringHashProvider class
70 _StringHashProvider::_StringHashProvider(void)
71 {
72
73 }
74
75 _StringHashProvider::~_StringHashProvider(void)
76 {
77
78 }
79
80 int
81 _StringHashProvider::GetHashCode(const Object& obj) const
82 {
83         return obj.GetHashCode();
84 }
85
86 // _PropertyUtils class
87 _PropertyUtils::_PropertyUtils(void)
88         : __pStringComparer(null)
89         , __pStringHashProvider(null)
90 {
91
92 }
93
94 _PropertyUtils::~_PropertyUtils(void)
95 {
96         if (__pStringComparer)
97         {
98                 delete __pStringComparer;
99         }
100
101         if (__pStringHashProvider)
102         {
103                 delete __pStringHashProvider;
104         }
105 }
106
107 _PropertyUtils*
108 _PropertyUtils::GetInstance(void)
109 {
110 #if 0
111         static _PropertyUtils* pPropertyUtils = null;
112         result r = E_SUCCESS;
113         if (pPropertyUtils == null)
114         {
115                 pPropertyUtils = new (std::nothrow) _PropertyUtils;
116                 SysTryReturn(NID_UI, pPropertyUtils != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create pPropertyUtils.");
117
118                 r = pPropertyUtils->Construct();
119                 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to construct pPropertyUtils.");
120         }
121
122         return pPropertyUtils;
123 #else
124         static _PropertyUtils propertyUtils;
125         static bool initialized = false;
126
127         if (!initialized)
128         {
129                 result r = propertyUtils.Construct();
130                 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to construct pPropertyUtils.");
131
132                 initialized = true;
133         }
134
135         return &propertyUtils;
136 #endif
137 }
138
139 const _StringComparer*
140 _PropertyUtils::GetStringComparer() const
141 {
142         return __pStringComparer;
143 }
144
145 const  _StringHashProvider*
146 _PropertyUtils::GetStringHashProvider() const
147 {
148         return __pStringHashProvider;
149 }
150
151 result
152 _PropertyUtils::Construct(void)
153 {
154         result r = E_SUCCESS;
155
156         if (!__pStringComparer)
157         {
158                 __pStringComparer = new (std::nothrow) _StringComparer;
159         }
160         SysTryReturn(NID_UI, __pStringComparer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _StringComparer.");
161
162         if (!__pStringHashProvider)
163         {
164                 __pStringHashProvider = new (std::nothrow) _StringHashProvider;
165         }
166         SysTryReturn(NID_UI, __pStringHashProvider != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _StringHashProvider.");
167
168         return r;
169 }
170
171 } } //Tizen::Ui
172