PlaylistVector.cxx 1.54 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * http://www.musicpd.org
 *
 * 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.
 */

#include "config.h"
21
#include "PlaylistVector.hxx"
Max Kellermann's avatar
Max Kellermann committed
22
#include "DatabaseLock.hxx"
23

24 25
#include <algorithm>

26 27 28
#include <assert.h>
#include <string.h>

29 30
PlaylistVector::iterator
PlaylistVector::find(const char *name)
31
{
32
	assert(holding_db_lock());
33
	assert(name != nullptr);
34

35 36
	return std::find_if(begin(), end(),
			    PlaylistInfo::CompareName(name));
37 38
}

39
bool
40
PlaylistVector::UpdateOrInsert(PlaylistInfo &&pi)
41
{
42 43
	assert(holding_db_lock());

44 45 46
	auto i = find(pi.name.c_str());
	if (i != end()) {
		if (pi.mtime == i->mtime)
47 48
			return false;

49
		i->mtime = pi.mtime;
50
	} else
51
		push_back(std::move(pi));
52 53

	return true;
54 55 56
}

bool
57
PlaylistVector::erase(const char *name)
58
{
59 60
	assert(holding_db_lock());

61 62
	auto i = find(name);
	if (i == end())
63 64
		return false;

65
	erase(i);
66 67
	return true;
}