// // Copyright (c) 2013 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 FScl_AccountImpl.cpp * @brief This is the implementation for _AccountImpl class. * * This file contains definitions of @e _AccountImpl class. */ #include #include #include #include #include #include "FScl_AccountImpl.h" #include "FScl_AccountProviderImpl.h" #include using namespace Tizen::Base; using namespace Tizen::Base::Collection; namespace Tizen { namespace Social { _AccountImpl::_AccountImpl(const Tizen::Base::String& userName) : __id(INVALID_RECORD_ID) { std::unique_ptr pExtendedData(new (std::nothrow) HashMap()); SysTryReturnVoidResult(NID_SCL, pExtendedData != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pExtendedData->Construct(); SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r)); __pExtendedData = std::move(pExtendedData); __userName = userName; } _AccountImpl::_AccountImpl(const _AccountImpl& rhs) { std::unique_ptr pExtendedData(new (std::nothrow) HashMap()); SysTryReturnVoidResult(NID_SCL, pExtendedData != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pExtendedData->Construct(); SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r)); std::unique_ptr pMapEnum((rhs.__pExtendedData)->GetMapEnumeratorN()); SysTryReturnVoidResult(NID_SCL, pMapEnum != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); std::unique_ptr pKey(null); std::unique_ptr pVal(null); String* pStr = null; while (pMapEnum->MoveNext() == E_SUCCESS) { pStr = static_cast (pMapEnum->GetKey()); pKey.reset(new (std::nothrow) String(*pStr)); SysTryReturnVoidResult(NID_SCL, pKey != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pStr = static_cast (pMapEnum->GetValue()); pVal.reset(new (std::nothrow) String(*pStr)); SysTryReturnVoidResult(NID_SCL, pVal != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pExtendedData->Add(pKey.get(), pVal.get()); SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r)); pKey.release(); pVal.release(); } __pExtendedData = std::move(pExtendedData); __id = rhs.__id; __userName = rhs.__userName; __accountProvider = rhs.__accountProvider; } _AccountImpl::~_AccountImpl(void) { // empty body. } _AccountImpl& _AccountImpl::operator =(const _AccountImpl& rhs) { if (this == &rhs) { return *this; } std::unique_ptr pExtendedData(new (std::nothrow) HashMap()); SysTryReturn(NID_SCL, pExtendedData != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pExtendedData->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r)); result prevResult = GetLastResult(); std::unique_ptr pMapEnum((rhs.__pExtendedData)->GetMapEnumeratorN()); SysTryReturn(NID_SCL, pMapEnum != null, *this, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); SetLastResult(prevResult); std::unique_ptr pKey(null); std::unique_ptr pVal(null); String* pStr = null; while (pMapEnum->MoveNext() == E_SUCCESS) { pStr = static_cast (pMapEnum->GetKey()); pKey.reset(new (std::nothrow) String(*pStr)); SysTryReturn(NID_SCL, pKey != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pStr = static_cast (pMapEnum->GetValue()); pVal.reset(new (std::nothrow) String(*pStr)); SysTryReturn(NID_SCL, pVal != null, *this, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pExtendedData->Add(pKey.get(), pVal.get()); SysTryReturn(NID_SCL, !IsFailed(r), *this, r, "[%s] Propagating.", GetErrorMessage(r)); pKey.release(); pVal.release(); } __pExtendedData = std::move(pExtendedData); __id = rhs.__id; __userName = rhs.__userName; __accountProvider = rhs.__accountProvider; return *this; } bool _AccountImpl::Equals(const Object& rhs) const { const _AccountImpl* pAccountImpl = dynamic_cast (&rhs); if (pAccountImpl == null) { return false; } if (__id != pAccountImpl->__id || __userName != pAccountImpl->__userName) { return false; } if (*(_AccountProviderImpl::GetInstance(__accountProvider)) != *(_AccountProviderImpl::GetInstance(pAccountImpl->__accountProvider))) { return false; } if (!(__pExtendedData->Equals(*(pAccountImpl->__pExtendedData)))) { return false; } return true; } int _AccountImpl::GetHashCode(void) const { int hashCode = 0xffffffff & __id; hashCode += hashCode; return hashCode; } AccountId _AccountImpl::GetId(void) const { return __id; } AccountProvider _AccountImpl::GetAccountProvider(void) const { return __accountProvider; } String _AccountImpl::GetUserName(void) const { return __userName; } IMap* _AccountImpl::GetExtendedDataN(void) const { ClearLastResult(); std::unique_ptr pExtendedData(new (std::nothrow) HashMap()); SysTryReturn(NID_SCL, pExtendedData != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pExtendedData->Construct(); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Failed to construct pExtendedData.", GetErrorMessage(r)); std::unique_ptr pMapEnum(__pExtendedData->GetMapEnumeratorN()); SysTryReturn(NID_SCL, pMapEnum != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); std::unique_ptr pKey(null); std::unique_ptr pVal(null); String* pStr = null; while (pMapEnum->MoveNext() == E_SUCCESS) { pStr = static_cast (pMapEnum->GetKey()); pKey.reset(new (std::nothrow) String(*pStr)); SysTryReturn(NID_SCL, pKey != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); pStr = static_cast (pMapEnum->GetValue()); pVal.reset(new (std::nothrow) String(*pStr)); SysTryReturn(NID_SCL, pVal != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); r = pExtendedData->Add(pKey.get(), pVal.get()); SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r)); pKey.release(); pVal.release(); } return pExtendedData.release(); } void _AccountImpl::SetId(AccountId accountId) { __id = accountId; } void _AccountImpl::SetAccountProvider(const AccountProvider& accountProvider) { __accountProvider = accountProvider; } result _AccountImpl::SetUserName(const String& userName) { SysTryReturnResult(NID_SCL, !(userName.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. The userName is an empty string."); __userName = userName; return E_SUCCESS; } result _AccountImpl::SetExtendedData(const String& key, const Tizen::Base::String& value) { SysTryReturnResult(NID_SCL, !(key.IsEmpty()), E_INVALID_ARG, "Invalid argument is used. The key is an empty string."); std::unique_ptr pValue(new (std::nothrow) String(value)); SysTryReturn(NID_SCL, pValue != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); if (__pExtendedData->ContainsKey(key)) { result r = __pExtendedData->SetValue(key, pValue.get()); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); pValue.release(); } else { std::unique_ptr pKey(new (std::nothrow) String(key)); SysTryReturn(NID_SCL, pKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = __pExtendedData->Add(pKey.get(), pValue.get()); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); pKey.release(); pValue.release(); } return E_SUCCESS; } const _AccountImpl* _AccountImpl::GetInstance(const Account& account) { return account.__pAccountImpl; } _AccountImpl* _AccountImpl::GetInstance(Account& account) { return account.__pAccountImpl; } }} //Tizen::Social