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