Fix the boiler plate codes
[framework/osp/social.git] / src / FSclPhoneNumber.cpp
1 //
2 // Copyright (c) 2012 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 * @file         FSclPhoneNumber.cpp
18 * @brief                This is the implementation for PhoneNumber class.
19 *
20 * This file contains definitions of @e PhoneNumber class.
21 */
22
23 #include <FSclPhoneNumber.h>
24 #include <FBaseSysLog.h>
25 #include <FApp_AppInfo.h>
26 #include "FScl_PhoneNumberImpl.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::App;
30
31 namespace Tizen { namespace Social
32 {
33
34 PhoneNumber::PhoneNumber(void)
35 {
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));
38 }
39
40 PhoneNumber::PhoneNumber(PhoneNumberType type, const String& number)
41 {
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));
44 }
45
46 PhoneNumber::PhoneNumber(const PhoneNumber& rhs)
47 {
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));
50 }
51
52 PhoneNumber::~PhoneNumber(void)
53 {
54         delete __pPhoneNumberImpl;
55 }
56
57 PhoneNumber&
58 PhoneNumber::operator =(const PhoneNumber& rhs)
59 {
60         if (this == &rhs)
61         {
62                 return *this;
63         }
64
65         *__pPhoneNumberImpl = *rhs.__pPhoneNumberImpl;
66
67         return *this;
68 }
69
70 bool
71 PhoneNumber::operator ==(const PhoneNumber& rhs) const
72 {
73         return *__pPhoneNumberImpl == *rhs.__pPhoneNumberImpl;
74 }
75
76 bool
77 PhoneNumber::operator !=(const PhoneNumber& rhs) const
78 {
79         return !(*this == rhs);
80 }
81
82 bool
83 PhoneNumber::Equals(const Object& rhs) const
84 {
85         const PhoneNumber* pPhoneNumber = dynamic_cast<const PhoneNumber*>(&rhs);
86         if (pPhoneNumber == null)
87         {
88                 return false;
89         }
90
91         return *this == *pPhoneNumber;
92 }
93
94 int
95 PhoneNumber::GetHashCode(void) const
96 {
97         return __pPhoneNumberImpl->GetHashCode();
98 }
99
100 PhoneNumberType
101 PhoneNumber::GetType(void) const
102 {
103         PhoneNumberType type =  __pPhoneNumberImpl->GetType();
104         if (type == PHONENUMBER_TYPE_CUSTOM && (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat()))
105         {
106                 type =  PHONENUMBER_TYPE_OTHER;
107         }
108
109         return type;
110 }
111
112 String
113 PhoneNumber::GetLabel(void) const
114 {
115         return __pPhoneNumberImpl->GetLabel();
116 }
117
118 String
119 PhoneNumber::GetPhoneNumber(void) const
120 {
121         String phoneNumber =  __pPhoneNumberImpl->GetPhoneNumber();
122
123         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
124         {
125                 if (phoneNumber.GetLength() > MAX_PHONE_NUMBER_LENGTH)
126                 {
127                         phoneNumber.SetLength(MAX_PHONE_NUMBER_LENGTH);
128                 }
129         }
130
131         return phoneNumber;
132 }
133
134
135 void
136 PhoneNumber::SetType(PhoneNumberType type)
137 {
138         __pPhoneNumberImpl->SetType(type);
139 }
140
141 void
142 PhoneNumber::SetLabel(const String& label)
143 {
144         __pPhoneNumberImpl->SetLabel(label);
145 }
146
147 result
148 PhoneNumber::SetPhoneNumber(const String& number)
149 {
150         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
151         {
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));
154         }
155
156         return __pPhoneNumberImpl->SetPhoneNumber(number);
157 }
158
159 }} // Tizen::Social