2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FSclPhoneNumber.cpp
18 * @brief This is the implementation for PhoneNumber class.
20 * This file contains definitions of @e PhoneNumber class.
23 #include <FSclPhoneNumber.h>
24 #include <FBaseSysLog.h>
25 #include <FApp_AppInfo.h>
26 #include "FScl_PhoneNumberImpl.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::App;
31 namespace Tizen { namespace Social
34 PhoneNumber::PhoneNumber(void)
36 __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl();
37 SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
40 PhoneNumber::PhoneNumber(PhoneNumberType type, const String& number)
42 __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl(type, number);
43 SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
46 PhoneNumber::PhoneNumber(const PhoneNumber& rhs)
48 __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl(*rhs.__pPhoneNumberImpl);
49 SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
52 PhoneNumber::~PhoneNumber(void)
54 delete __pPhoneNumberImpl;
58 PhoneNumber::operator =(const PhoneNumber& rhs)
65 *__pPhoneNumberImpl = *rhs.__pPhoneNumberImpl;
71 PhoneNumber::operator ==(const PhoneNumber& rhs) const
73 return *__pPhoneNumberImpl == *rhs.__pPhoneNumberImpl;
77 PhoneNumber::operator !=(const PhoneNumber& rhs) const
79 return !(*this == rhs);
83 PhoneNumber::Equals(const Object& rhs) const
85 const PhoneNumber* pPhoneNumber = dynamic_cast<const PhoneNumber*>(&rhs);
86 if (pPhoneNumber == null)
91 return *this == *pPhoneNumber;
95 PhoneNumber::GetHashCode(void) const
97 return __pPhoneNumberImpl->GetHashCode();
101 PhoneNumber::GetType(void) const
103 PhoneNumberType type = __pPhoneNumberImpl->GetType();
104 if (type == PHONENUMBER_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
106 type = PHONENUMBER_TYPE_OTHER;
113 PhoneNumber::GetLabel(void) const
115 return __pPhoneNumberImpl->GetLabel();
119 PhoneNumber::GetPhoneNumber(void) const
121 String phoneNumber = __pPhoneNumberImpl->GetPhoneNumber();
123 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
125 if (phoneNumber.GetLength() > MAX_PHONE_NUMBER_LENGTH)
127 phoneNumber.SetLength(MAX_PHONE_NUMBER_LENGTH);
136 PhoneNumber::SetType(PhoneNumberType type)
138 __pPhoneNumberImpl->SetType(type);
142 PhoneNumber::SetLabel(const String& label)
144 __pPhoneNumberImpl->SetLabel(label);
148 PhoneNumber::SetPhoneNumber(const String& number)
150 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
152 SysTryReturn(NID_SCL, number.GetLength() <= MAX_PHONE_NUMBER_LENGTH,
153 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));
156 return __pPhoneNumberImpl->SetPhoneNumber(number);