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