2 // Open Service Platform
3 // Copyright (c) 2012 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 FSclPhoneNumber.cpp
19 * @brief This is the implementation for PhoneNumber class.
21 * This file contains definitions of @e PhoneNumber class.
24 #include <FSclPhoneNumber.h>
25 #include <FBaseSysLog.h>
26 #include <FApp_AppInfo.h>
27 #include "FScl_PhoneNumberImpl.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::App;
32 namespace Tizen { namespace Social
35 PhoneNumber::PhoneNumber(void)
37 __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl();
38 SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
41 PhoneNumber::PhoneNumber(PhoneNumberType type, const String& number)
43 __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl(type, number);
44 SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
47 PhoneNumber::PhoneNumber(const PhoneNumber& rhs)
49 __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl(*rhs.__pPhoneNumberImpl);
50 SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
53 PhoneNumber::~PhoneNumber(void)
55 delete __pPhoneNumberImpl;
59 PhoneNumber::operator =(const PhoneNumber& rhs)
66 *__pPhoneNumberImpl = *rhs.__pPhoneNumberImpl;
72 PhoneNumber::operator ==(const PhoneNumber& rhs) const
74 return *__pPhoneNumberImpl == *rhs.__pPhoneNumberImpl;
78 PhoneNumber::operator !=(const PhoneNumber& rhs) const
80 return !(*this == rhs);
84 PhoneNumber::Equals(const Object& rhs) const
86 const PhoneNumber* pPhoneNumber = dynamic_cast<const PhoneNumber*>(&rhs);
87 if (pPhoneNumber == null)
92 return *this == *pPhoneNumber;
96 PhoneNumber::GetHashCode(void) const
98 return __pPhoneNumberImpl->GetHashCode();
102 PhoneNumber::GetType(void) const
104 PhoneNumberType type = __pPhoneNumberImpl->GetType();
105 if (type == PHONENUMBER_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
107 type = PHONENUMBER_TYPE_OTHER;
114 PhoneNumber::GetLabel(void) const
116 return __pPhoneNumberImpl->GetLabel();
120 PhoneNumber::GetPhoneNumber(void) const
122 String phoneNumber = __pPhoneNumberImpl->GetPhoneNumber();
124 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
126 if (phoneNumber.GetLength() > MAX_PHONE_NUMBER_LENGTH)
128 phoneNumber.SetLength(MAX_PHONE_NUMBER_LENGTH);
137 PhoneNumber::SetType(PhoneNumberType type)
139 __pPhoneNumberImpl->SetType(type);
143 PhoneNumber::SetLabel(const String& label)
145 __pPhoneNumberImpl->SetLabel(label);
149 PhoneNumber::SetPhoneNumber(const String& number)
151 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
153 SysTryReturn(NID_SCL, number.GetLength() <= MAX_PHONE_NUMBER_LENGTH,
154 E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The length of the number exceeds MAX_PHONE_NUMBER_LENGTH.", GetErrorMessage(E_INVALID_ARG));
157 return __pPhoneNumberImpl->SetPhoneNumber(number);