// // Copyright (c) 2012 Samsung Electronics Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /** * @file FSclPhoneNumber.cpp * @brief This is the implementation for PhoneNumber class. * * This file contains definitions of @e PhoneNumber class. */ #include #include #include #include "FScl_PhoneNumberImpl.h" using namespace Tizen::Base; using namespace Tizen::App; namespace Tizen { namespace Social { PhoneNumber::PhoneNumber(void) { __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl(); SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } PhoneNumber::PhoneNumber(PhoneNumberType type, const String& number) { __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl(type, number); SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } PhoneNumber::PhoneNumber(const PhoneNumber& rhs) { __pPhoneNumberImpl = new (std::nothrow) _PhoneNumberImpl(*rhs.__pPhoneNumberImpl); SysTryReturnVoidResult(NID_SCL, __pPhoneNumberImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); } PhoneNumber::~PhoneNumber(void) { delete __pPhoneNumberImpl; } PhoneNumber& PhoneNumber::operator =(const PhoneNumber& rhs) { if (this == &rhs) { return *this; } *__pPhoneNumberImpl = *rhs.__pPhoneNumberImpl; return *this; } bool PhoneNumber::operator ==(const PhoneNumber& rhs) const { return *__pPhoneNumberImpl == *rhs.__pPhoneNumberImpl; } bool PhoneNumber::operator !=(const PhoneNumber& rhs) const { return !(*this == rhs); } bool PhoneNumber::Equals(const Object& rhs) const { const PhoneNumber* pPhoneNumber = dynamic_cast(&rhs); if (pPhoneNumber == null) { return false; } return *this == *pPhoneNumber; } int PhoneNumber::GetHashCode(void) const { return __pPhoneNumberImpl->GetHashCode(); } PhoneNumberType PhoneNumber::GetType(void) const { PhoneNumberType type = __pPhoneNumberImpl->GetType(); if (type == PHONENUMBER_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())) { type = PHONENUMBER_TYPE_OTHER; } return type; } String PhoneNumber::GetLabel(void) const { return __pPhoneNumberImpl->GetLabel(); } String PhoneNumber::GetPhoneNumber(void) const { String phoneNumber = __pPhoneNumberImpl->GetPhoneNumber(); if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()) { if (phoneNumber.GetLength() > MAX_PHONE_NUMBER_LENGTH) { phoneNumber.SetLength(MAX_PHONE_NUMBER_LENGTH); } } return phoneNumber; } void PhoneNumber::SetType(PhoneNumberType type) { __pPhoneNumberImpl->SetType(type); } void PhoneNumber::SetLabel(const String& label) { __pPhoneNumberImpl->SetLabel(label); } result PhoneNumber::SetPhoneNumber(const String& number) { if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()) { SysTryReturn(NID_SCL, number.GetLength() <= MAX_PHONE_NUMBER_LENGTH, 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)); } return __pPhoneNumberImpl->SetPhoneNumber(number); } }} // Tizen::Social