2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
18 * @file FUI_PropertyUtils.cpp
19 * @brief This is the implementation file for _PropertyUtils class.
23 #include <FBaseErrors.h>
24 #include <FBaseSysLog.h>
25 #include "FUi_PropertyUtils.h"
27 using namespace Tizen::Base;
29 namespace Tizen { namespace Ui
33 * @class _StringComparer
34 * @brief We implemented new custom string-comparer for performance.
39 // _StringComparer class
40 _StringComparer::_StringComparer(void)
45 _StringComparer::~_StringComparer(void)
51 _StringComparer::Compare(const Object& obj1, const Object& obj2, int& cmp) const
53 const String* pString1 = static_cast<const String*>(&obj1);
54 const String* pString2 = static_cast<const String*>(&obj2);
56 // dirty optimization. HaspMap do not care of the sign. It is interested only in zero or not.
57 if (*pString1 == *pString2)
69 // _StringHashProvider class
70 _StringHashProvider::_StringHashProvider(void)
75 _StringHashProvider::~_StringHashProvider(void)
81 _StringHashProvider::GetHashCode(const Object& obj) const
83 return obj.GetHashCode();
86 // _PropertyUtils class
87 _PropertyUtils::_PropertyUtils(void)
88 : __pStringComparer(null)
89 , __pStringHashProvider(null)
94 _PropertyUtils::~_PropertyUtils(void)
96 if (__pStringComparer)
98 delete __pStringComparer;
101 if (__pStringHashProvider)
103 delete __pStringHashProvider;
108 _PropertyUtils::GetInstance(void)
111 static _PropertyUtils* pPropertyUtils = null;
112 result r = E_SUCCESS;
113 if (pPropertyUtils == null)
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.");
118 r = pPropertyUtils->Construct();
119 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to construct pPropertyUtils.");
122 return pPropertyUtils;
124 static _PropertyUtils propertyUtils;
125 static bool initialized = false;
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.");
135 return &propertyUtils;
139 const _StringComparer*
140 _PropertyUtils::GetStringComparer() const
142 return __pStringComparer;
145 const _StringHashProvider*
146 _PropertyUtils::GetStringHashProvider() const
148 return __pStringHashProvider;
152 _PropertyUtils::Construct(void)
154 result r = E_SUCCESS;
156 if (!__pStringComparer)
158 __pStringComparer = new (std::nothrow) _StringComparer;
160 SysTryReturn(NID_UI, __pStringComparer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _StringComparer.");
162 if (!__pStringHashProvider)
164 __pStringHashProvider = new (std::nothrow) _StringHashProvider;
166 SysTryReturn(NID_UI, __pStringHashProvider != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _StringHashProvider.");