1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright (C) 2011 Canonical Ltd
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 3 as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Authored by: Andrea Azzaronea <azzaronea@gmail.com>
21
#include <boost/utility.hpp>
23
#include "FavoriteStorePrivate.h"
32
std::vector<std::string> GetNewbies(std::list<std::string> const& old, std::list<std::string> const& fresh)
35
auto sorted_fresh(fresh);
40
std::vector<std::string> result;
41
std::set_difference(sorted_fresh.begin(), sorted_fresh.end(), sorted_old.begin(), sorted_old.end(),
42
std::inserter(result, result.end()));
47
void GetSignalAddedInfo(std::list<std::string> const& favs, std::vector<std::string> const& newbies,
48
std::string const& path, std::string& position, bool& before)
50
auto it = std::find(favs.begin(), favs.end(), path);
51
before = (it == favs.begin());
54
if (before and favs.size() > 1)
56
while (it != favs.end() && std::find(newbies.begin(), newbies.end(), *it) != newbies.end())
64
position = *(boost::prior(it));
69
std::vector<std::string> GetRemoved(std::list<std::string> const& old, std::list<std::string> const& fresh)
72
auto sorted_fresh(fresh);
77
std::vector<std::string> result;
78
std::set_difference(sorted_old.begin(), sorted_old.end(), sorted_fresh.begin(), sorted_fresh.end(),
79
std::inserter(result, result.end()));
85
bool NeedToBeReordered(std::list<std::string> const& old, std::list<std::string> const& fresh)
88
auto sorted_fresh(fresh);
93
std::vector<std::string> ignore_old, ignore_fresh;
95
std::set_difference(sorted_old.begin(), sorted_old.end(), sorted_fresh.begin(), sorted_fresh.end(),
96
std::inserter(ignore_old, ignore_old.end()));
97
std::set_difference(sorted_fresh.begin(), sorted_fresh.end(), sorted_old.begin(), sorted_old.end(),
98
std::inserter(ignore_fresh, ignore_fresh.end()));
100
auto it_old = old.begin();
101
auto it_fresh = fresh.begin();
103
while (it_old != old.end() && it_fresh != fresh.end())
106
while (it_old != old.end() && std::find(ignore_old.begin(), ignore_old.end(), *it_old) != ignore_old.end())
109
while (it_fresh != fresh.end() && std::find(ignore_fresh.begin(), ignore_fresh.end(), *it_fresh) != ignore_fresh.end())
112
if (it_old == old.end() || it_fresh == fresh.end())
115
if (*it_old != *it_fresh)
129
} // namespace internal