app-data-container.cpp 2.36 KB
Newer Older
Ronan's avatar
Ronan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * app-data-container.cpp
 * Copyright (C) 2010-2017 Belledonne Communications SARL
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

20
#include <memory>
Ronan's avatar
Ronan committed
21

22
#include "linphone/utils/utils.h"
Ronan's avatar
Ronan committed
23 24 25 26 27 28 29 30
#include "app-data-container.h"

// =============================================================================

using namespace std;

LINPHONE_BEGIN_NAMESPACE

31 32
// -----------------------------------------------------------------------------

Ronan's avatar
Ronan committed
33 34
class AppDataContainerPrivate {
public:
35
	shared_ptr<unordered_map<string, string>> appData;
Ronan's avatar
Ronan committed
36 37 38 39
};

// -----------------------------------------------------------------------------

40 41 42 43
AppDataContainer::AppDataContainer () : mPrivate(new AppDataContainerPrivate) {
	L_D();
	d->appData = make_shared<unordered_map<string, string>>();
}
Ronan's avatar
Ronan committed
44

45 46 47 48
AppDataContainer::AppDataContainer (const AppDataContainer &src) : mPrivate(new AppDataContainerPrivate) {
	L_D();
	d->appData = src.getPrivate()->appData;
}
Ronan's avatar
Ronan committed
49 50 51 52 53

AppDataContainer::~AppDataContainer () {
	delete mPrivate;
}

54 55 56 57
AppDataContainer &AppDataContainer::operator= (const AppDataContainer &src) {
	L_D();
	if (this != &src)
		d->appData = src.getPrivate()->appData;
Ronan's avatar
Ronan committed
58 59 60
	return *this;
}

61 62 63 64 65
const unordered_map<string, string> &AppDataContainer::getAppDataMap () const {
	L_D();
	return *d->appData.get();
}

66
const string &AppDataContainer::getAppData (const string &name) const {
Ronan's avatar
Ronan committed
67
	L_D();
68
	auto it = d->appData->find(name);
69
	return it == d->appData->cend() ? Utils::getEmptyConstRefObject<string>() : it->second;
Ronan's avatar
Ronan committed
70 71 72 73
}

void AppDataContainer::setAppData (const string &name, const string &appData) {
	L_D();
74
	(*d->appData)[name] = appData;
Ronan's avatar
Ronan committed
75 76 77 78
}

void AppDataContainer::setAppData (const string &name, string &&appData) {
	L_D();
79
	(*d->appData)[name] = move(appData);
Ronan's avatar
Ronan committed
80 81 82
}

LINPHONE_END_NAMESPACE