Fix for CompatTC Fail
[framework/osp/social.git] / src / FScl_ContactAppLaunchDataImpl.cpp
1 //
2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
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  * @file                FScl_ContactAppLaunchDataImpl.cpp
19  * @brief               This is the header file for the %_ContactAppLaunchData class.
20  *
21  * This header file contains the declarations of the %_ContactAppLaunchData class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include "FScl_ContactAppLaunchDataImpl.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Collection;
29
30 namespace Tizen { namespace Social
31 {
32
33 _ContactAppLaunchDataImpl::_ContactAppLaunchDataImpl(void)
34 {
35         std::unique_ptr<HashMap, AllElementsDeleter> pExtraData(new (std::nothrow) HashMap());
36         SysTryReturnVoidResult(NID_SCL, pExtraData != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
37
38         result r = pExtraData->Construct();
39         SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pExtraData.", GetErrorMessage(r));
40
41         __pExtraData = std::move(pExtraData);
42 }
43
44 _ContactAppLaunchDataImpl::_ContactAppLaunchDataImpl(const _ContactAppLaunchDataImpl& rhs)
45 {
46         std::unique_ptr<HashMap, AllElementsDeleter> pExtraData(new (std::nothrow) HashMap());
47         SysTryReturnVoidResult(NID_SCL, pExtraData != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
48
49         result r = pExtraData->Construct();
50         SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pExtraData.", GetErrorMessage(r));
51
52         std::unique_ptr<IMapEnumerator> pMapEnum((rhs.__pExtraData)->GetMapEnumeratorN());
53         SysTryReturnVoidResult(NID_SCL, pMapEnum != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
54
55         std::unique_ptr<String> pKey(null);
56         std::unique_ptr<String> pVal(null);
57         String* pStr = null;
58
59         while (pMapEnum->MoveNext() == E_SUCCESS)
60         {
61                 pStr = static_cast<String*> (pMapEnum->GetKey());
62                 pKey.reset(new (std::nothrow) String(*pStr));
63                 SysTryReturnVoidResult(NID_SCL, pKey != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
64
65                 pStr = static_cast<String*> (pMapEnum->GetValue());
66                 pVal.reset(new (std::nothrow) String(*pStr));
67                 SysTryReturnVoidResult(NID_SCL, pVal != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
68
69                 r = pExtraData->Add(pKey.get(), pVal.get());
70                 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
71
72                 pKey.release();
73                 pVal.release();
74         }
75
76         __pExtraData = std::move(pExtraData);
77
78         __displayText = rhs.__displayText;
79         __uid = rhs.__uid;
80         __appId = rhs.__appId;
81         __operationId = rhs.__operationId;
82         __uri = rhs.__uri;
83         __category = rhs.__category;
84         __mime = rhs.__mime;
85 }
86
87 _ContactAppLaunchDataImpl::~_ContactAppLaunchDataImpl(void)
88 {
89 }
90
91 _ContactAppLaunchDataImpl&
92 _ContactAppLaunchDataImpl::operator =(const _ContactAppLaunchDataImpl& rhs)
93 {
94         if (this == &rhs)
95         {
96                 return *this;
97         }
98
99         std::unique_ptr<HashMap, AllElementsDeleter> pExtraData(new (std::nothrow) HashMap());
100         SysTryReturn(NID_SCL, pExtraData != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
101
102         result r = pExtraData->Construct();
103         SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Failed to construct pExtraData.", GetErrorMessage(r));
104
105         std::unique_ptr<IMapEnumerator> pMapEnum((rhs.__pExtraData)->GetMapEnumeratorN());
106         SysTryReturn(NID_SCL, pMapEnum != null, *this, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
107
108         std::unique_ptr<String> pKey(null);
109         std::unique_ptr<String> pVal(null);
110         String* pStr = null;
111
112         while (pMapEnum->MoveNext() == E_SUCCESS)
113         {
114                 pStr = static_cast<String*> (pMapEnum->GetKey());
115                 pKey.reset(new (std::nothrow) String(*pStr));
116                 SysTryReturn(NID_SCL, pKey != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
117
118                 pStr = static_cast<String*> (pMapEnum->GetValue());
119                 pVal.reset(new (std::nothrow) String(*pStr));
120                 SysTryReturn(NID_SCL, pVal != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
121
122                 r = pExtraData->Add(pKey.get(), pVal.get());
123                 SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Propagating.", GetErrorMessage(r));
124
125                 pKey.release();
126                 pVal.release();
127         }
128
129         __pExtraData = std::move(pExtraData);
130
131         __displayText = rhs.__displayText;
132         __uid = rhs.__uid;
133         __appId = rhs.__appId;
134         __operationId = rhs.__operationId;
135         __uri = rhs.__uri;
136         __category = rhs.__category;
137         __mime = rhs.__mime;
138
139         return *this;
140 }
141
142 bool operator ==(const _ContactAppLaunchDataImpl& lhs, const _ContactAppLaunchDataImpl& rhs)
143 {
144         if (lhs.__displayText != rhs.__displayText)
145         {
146                 return false;
147         }
148
149         if (lhs.__uid != rhs.__uid)
150         {
151                 return false;
152         }
153
154         if (lhs.__appId != rhs.__appId)
155         {
156                 return false;
157         }
158
159         if (lhs.__operationId != rhs.__operationId)
160         {
161                 return false;
162         }
163
164         if (lhs.__uri != rhs.__uri)
165         {
166                 return false;
167         }
168
169         if (lhs.__category != rhs.__category)
170         {
171                 return false;
172         }
173
174         if (lhs.__mime != rhs.__mime)
175         {
176                 return false;
177         }
178
179         if (!lhs.__pExtraData->Equals(*rhs.__pExtraData))
180         {
181                 return false;
182         }
183
184         return true;
185 }
186
187 bool operator !=(const _ContactAppLaunchDataImpl& lhs, const _ContactAppLaunchDataImpl& rhs)
188 {
189         return !(lhs == rhs);
190 }
191
192 bool
193 _ContactAppLaunchDataImpl::Equals(const Object& rhs) const
194 {
195         const _ContactAppLaunchDataImpl* pContactAppLaunchData = dynamic_cast<const _ContactAppLaunchDataImpl*>(&rhs);
196         if (pContactAppLaunchData == null)
197         {
198                 return false;
199         }
200
201         return *this == *pContactAppLaunchData;
202 }
203
204 int
205 _ContactAppLaunchDataImpl::GetHashCode(void) const
206 {
207         int hash = __displayText.GetHashCode();
208         hash += __uid.GetHashCode();
209         hash += __appId.GetHashCode();
210         hash += __operationId.GetHashCode();
211         hash += __uri.GetHashCode();
212         hash += __category.GetHashCode();
213         hash += __mime.GetHashCode();
214
215         return hash;
216 }
217
218 String
219 _ContactAppLaunchDataImpl::GetDisplayText(void) const
220 {
221         return __displayText;
222 }
223
224 String
225 _ContactAppLaunchDataImpl::GetUid(void) const
226 {
227         return __uid;
228 }
229
230 String
231 _ContactAppLaunchDataImpl::GetAppId(void) const
232 {
233         return __appId;
234 }
235
236 String
237 _ContactAppLaunchDataImpl::GetOperationId(void) const
238 {
239         return __operationId;
240 }
241
242 String
243 _ContactAppLaunchDataImpl::GetUri(void) const
244 {
245         return __uri;
246 }
247
248 String
249 _ContactAppLaunchDataImpl::GetCategory(void) const
250 {
251         return __category;
252 }
253
254 String
255 _ContactAppLaunchDataImpl::GetMime(void) const
256 {
257         return __mime;
258 }
259
260 IMap*
261 _ContactAppLaunchDataImpl::GetExtraDataN(void) const
262 {
263         ClearLastResult();
264
265         std::unique_ptr<HashMap, AllElementsDeleter> pExtraData(new (std::nothrow) HashMap());
266         SysTryReturn(NID_SCL, pExtraData != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
267
268         result r = pExtraData->Construct();
269         SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Failed to construct pExtraData.", GetErrorMessage(r));
270
271         std::unique_ptr<IMapEnumerator> pMapEnum(__pExtraData->GetMapEnumeratorN());
272         SysTryReturn(NID_SCL, pMapEnum != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
273
274         std::unique_ptr<String> pKey(null);
275         std::unique_ptr<String> pVal(null);
276         String* pStr = null;
277
278         while (pMapEnum->MoveNext() == E_SUCCESS)
279         {
280                 pStr = static_cast<String*> (pMapEnum->GetKey());
281                 pKey.reset(new (std::nothrow) String(*pStr));
282                 SysTryReturn(NID_SCL, pKey != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
283
284                 pStr = static_cast<String*> (pMapEnum->GetValue());
285                 pVal.reset(new (std::nothrow) String(*pStr));
286                 SysTryReturn(NID_SCL, pVal != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
287
288                 r = pExtraData->Add(pKey.get(), pVal.get());
289                 SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
290
291                 pKey.release();
292                 pVal.release();
293         }
294
295         return pExtraData.release();
296 }
297
298 void
299 _ContactAppLaunchDataImpl::SetDisplayText(const String& displayText)
300 {
301         __displayText = displayText;
302 }
303
304 void
305 _ContactAppLaunchDataImpl::SetUid(const String& uid)
306 {
307         __uid = uid;
308 }
309
310 void
311 _ContactAppLaunchDataImpl::SetAppId(const String& appId)
312 {
313         __appId = appId;
314 }
315
316 void
317 _ContactAppLaunchDataImpl::SetOperationId(const String& operationId)
318 {
319         __operationId = operationId;
320 }
321
322 void
323 _ContactAppLaunchDataImpl::SetUri(const String& uri)
324 {
325         __uri = uri;
326 }
327
328 void
329 _ContactAppLaunchDataImpl::SetCategory(const String& category)
330 {
331         __category = category;
332 }
333
334 void
335 _ContactAppLaunchDataImpl::SetMime(const String& mime)
336 {
337         __mime = mime;
338 }
339
340 result
341 _ContactAppLaunchDataImpl::SetExtraData(const IMap* pExtraData)
342 {
343         std::unique_ptr<HashMap, AllElementsDeleter> pNewExtraData(new (std::nothrow) HashMap());
344         SysTryReturn(NID_SCL, pNewExtraData != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
345
346         result r = pNewExtraData->Construct();
347         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Failed to construct pExtraData.", GetErrorMessage(r));
348
349         if (pExtraData != null)
350         {
351                 std::unique_ptr<IMapEnumerator> pMapEnum(pExtraData->GetMapEnumeratorN());
352                 SysTryReturn(NID_SCL, pMapEnum != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
353
354                 std::unique_ptr<String> pKey(null);
355                 std::unique_ptr<String> pVal(null);
356                 String* pStr = null;
357
358                 while (pMapEnum->MoveNext() == E_SUCCESS)
359                 {
360                         pStr = static_cast<String*> (pMapEnum->GetKey());
361                         pKey.reset(new (std::nothrow) String(*pStr));
362                         SysTryReturn(NID_SCL, pKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
363
364                         pStr = static_cast<String*> (pMapEnum->GetValue());
365                         pVal.reset(new (std::nothrow) String(*pStr));
366                         SysTryReturn(NID_SCL, pVal != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
367
368                         r = pNewExtraData->Add(pKey.get(), pVal.get());
369                         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
370
371                         pKey.release();
372                         pVal.release();
373                 }
374         }
375
376         __pExtraData = std::move(pNewExtraData);
377
378         return E_SUCCESS;
379 }
380
381 bool
382 _ContactAppLaunchDataImpl::IsEmpty(void) const
383 {
384         if (!__displayText.IsEmpty())
385         {
386                 return false;
387         }
388
389         if (!__uid.IsEmpty())
390         {
391                 return false;
392         }
393
394         if (!__appId.IsEmpty())
395         {
396                 return false;
397         }
398
399         if (!__operationId.IsEmpty())
400         {
401                 return false;
402         }
403
404         if (!__uri.IsEmpty())
405         {
406                 return false;
407         }
408
409         if (!__category.IsEmpty())
410         {
411                 return false;
412         }
413
414         if (!__mime.IsEmpty())
415         {
416                 return false;
417         }
418
419         if (__pExtraData->GetCount() != 0)
420         {
421                 return false;
422         }
423
424         return true;
425 }
426
427 const _ContactAppLaunchDataImpl*
428 _ContactAppLaunchDataImpl::GetInstance(const ContactAppLaunchData& appLaunchData)
429 {
430         return appLaunchData.__pContactAppLaunchDataImpl;
431 }
432
433 _ContactAppLaunchDataImpl*
434 _ContactAppLaunchDataImpl::GetInstance(ContactAppLaunchData& appLaunchData)
435 {
436         return appLaunchData.__pContactAppLaunchDataImpl;
437 }
438
439 }} // Tizen::Social