2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file AddressBookStorage.cpp
19 * @author Kisub Song (kisubs.song@samsung.com)
25 #include <dpl/exception.h>
26 #include "AddressBookStorage.h"
32 using namespace WrtDeviceApis::Commons;
33 using namespace TizenApis::Api::Contact;
34 //using namespace TizenApis::Api::Tizen;
36 AddressBookStorage::AddressBookStorage() :
37 m_addressBooks(new AddressBookArray()),
38 m_defaultAddressBookIndex(-1)
42 AddressBookStorage::~AddressBookStorage()
46 void AddressBookStorage::insert(AddressBookPtr addressBook, bool setAsDefault)
53 index = m_addressBooks->size();
55 // just use index as id (very simple)
60 addressBook->setId(id);
62 m_addressBooks->push_back(addressBook);
64 if(m_defaultAddressBookIndex == -1 || setAsDefault)
65 m_defaultAddressBookIndex = index;
68 AddressBookPtr AddressBookStorage::getAddressBook(const std::string &id)
70 if(m_idMap.find(id) == m_idMap.end())
71 ThrowMsg(NotFoundException, "No AddressBook id:" << id);
73 int index = m_idMap[id];
75 if(static_cast<int>(m_addressBooks->size()) <= index)
76 ThrowMsg(NotFoundException, "No AddressBook id:" << id);
78 return m_addressBooks->at(index);
81 AddressBookPtr AddressBookStorage::getDefaultAddressBook() const
83 if(m_defaultAddressBookIndex == -1 || m_addressBooks->size() == 0)
84 ThrowMsg(PlatformException, "Invalid request");
86 return m_addressBooks->at(m_defaultAddressBookIndex);
89 AddressBookArrayPtr AddressBookStorage::getAddressBooks() const
91 AddressBookArrayPtr newArray(new AddressBookArray());
93 for(AddressBookArray::iterator i = m_addressBooks->begin(); i != m_addressBooks->end(); i++)
94 newArray->push_back(*i);