Fix for CompatTC Fail
[framework/osp/social.git] / src / FScl_PhoneNumberImpl.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         FScl_PhoneNumberImpl.cpp
18 * @brief                This is the implementation for _PhoneNumberImpl class.
19 *
20 * This file contains definitions of @e _PhoneNumberImpl class.
21 */
22
23 #include <unique_ptr.h>
24 #include <FSclPhoneNumber.h>
25 #include <FBaseSysLog.h>
26 #include <FBase_StringConverter.h>
27 #include "FScl_PhoneNumberImpl.h"
28
29 using namespace Tizen::Base;
30
31 namespace Tizen { namespace Social
32 {
33
34 _PhoneNumberImpl::_PhoneNumberImpl(void)
35 : __recordId(-1)
36 , __type(PHONENUMBER_TYPE_HOME)
37 , __isPhoneTypeChanged(false)
38 {
39
40 }
41
42 _PhoneNumberImpl::_PhoneNumberImpl(PhoneNumberType type, const String& number)
43 : __recordId(-1)
44 , __type(type)
45 , __number(number)
46 , __isPhoneTypeChanged(false)
47 {
48
49 }
50
51 _PhoneNumberImpl::_PhoneNumberImpl(const _PhoneNumberImpl& rhs)
52 {
53         __recordId = rhs.__recordId;
54         __type = rhs.__type;
55         __label = rhs.__label;
56         __number = rhs.__number;
57         __isPhoneTypeChanged = rhs.__isPhoneTypeChanged;
58 }       
59
60 _PhoneNumberImpl::~_PhoneNumberImpl(void)
61 {
62 }
63
64 _PhoneNumberImpl&
65 _PhoneNumberImpl::operator =(const _PhoneNumberImpl& rhs)
66 {
67         if (this == &rhs)
68         {
69                 return *this;
70         }
71
72         __recordId = rhs.__recordId;
73         __type = rhs.__type;
74         __label = rhs.__label;
75         __number = rhs.__number;
76         __isPhoneTypeChanged = rhs.__isPhoneTypeChanged;
77
78         return *this;
79 }
80
81 bool
82 _PhoneNumberImpl::operator ==(const _PhoneNumberImpl& rhs) const
83 {
84         if (__type != rhs.__type || __label != rhs.__label || __number != rhs.__number)
85         {
86                 return false;
87         }
88         
89         return true;
90 }
91
92 bool
93 _PhoneNumberImpl::Equals(const Object& rhs) const
94 {
95         const _PhoneNumberImpl* pPhoneNumberImpl = dynamic_cast<const _PhoneNumberImpl*>(&rhs);
96
97         if (pPhoneNumberImpl == null)
98         {
99                 return false;
100         }
101
102         return (*this == *pPhoneNumberImpl);
103 }
104
105 int
106 _PhoneNumberImpl::GetHashCode(void) const
107 {
108         int hashCode = __recordId;
109         hashCode += __type;
110         hashCode += __number.GetHashCode();
111         hashCode += __label.GetHashCode();
112
113         return hashCode;
114 }
115
116 bool
117 _PhoneNumberImpl::operator !=(const _PhoneNumberImpl& rhs) const
118 {
119         return !(*this == rhs);
120 }
121
122 PhoneNumberType
123 _PhoneNumberImpl::GetType(void) const
124 {
125         return __type;
126 }
127
128 String
129 _PhoneNumberImpl::GetPhoneNumber(void) const
130 {
131         return __number;
132 }
133
134 void
135 _PhoneNumberImpl::SetType(PhoneNumberType type)
136 {
137         __type = type;
138         __isPhoneTypeChanged = true;
139 }
140
141 result
142 _PhoneNumberImpl::SetPhoneNumber(const String& number)
143 {
144         SysTryReturn(NID_SCL, !number.IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The phone number is empty.", GetErrorMessage(E_INVALID_ARG));
145
146         __number = number;
147
148         return E_SUCCESS;
149 }
150
151 void
152 _PhoneNumberImpl::SetLabel(const String& label)
153 {
154         __label = label;
155 }
156
157 String
158 _PhoneNumberImpl::GetLabel(void) const
159 {
160         return __label;
161 }
162
163 void
164 _PhoneNumberImpl::SetRecordId(int recordId)
165 {
166         __recordId = recordId;
167 }
168
169 int
170 _PhoneNumberImpl::GetRecordId(void) const
171 {
172         return __recordId;
173 }
174
175 bool
176 _PhoneNumberImpl::IsEmpty(void) const
177 {
178         return __number.IsEmpty();
179 }
180
181 bool
182 _PhoneNumberImpl::IsPhoneNumberTypeChanged(void) const
183 {
184         return __isPhoneTypeChanged;
185 }
186
187 _PhoneNumberImpl*
188 _PhoneNumberImpl::GetInstance(PhoneNumber& phoneNumber)
189 {
190         return phoneNumber.__pPhoneNumberImpl;
191 }
192
193 const _PhoneNumberImpl*
194 _PhoneNumberImpl::GetInstance(const PhoneNumber& phoneNumber)
195 {
196         return phoneNumber.__pPhoneNumberImpl;
197 }
198
199 }} // Tizen::Social