~ubuntu-branches/ubuntu/trusty/tagcoll2/trusty-proposed

« back to all changes in this revision

Viewing changes to tagcoll/stream/patcher.tcc

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Fontaine
  • Date: 2006-11-18 12:15:11 UTC
  • Revision ID: james.westby@ubuntu.com-20061118121511-nic9no49s64crb7i
Tags: upstream-2.0.4
ImportĀ upstreamĀ versionĀ 2.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Classes handling tag patches
 
3
 *
 
4
 * Copyright (C) 2003  Enrico Zini <enrico@debian.org>
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
19
 */
 
20
 
 
21
#ifndef TAGCOLL_PATCHES_CPP
 
22
#define TAGCOLL_PATCHES_CPP
 
23
 
 
24
#include <tagcoll/patch.h>
 
25
 
 
26
using namespace std;
 
27
using namespace wibble::operators;
 
28
 
 
29
namespace tagcoll {
 
30
 
 
31
template <class ITEM, class TAG>
 
32
void PatchList<ITEM, TAG>::addPatch(const Patch<ITEM, TAG>& patch)
 
33
{
 
34
        // Filter out empty patches
 
35
        if (patch.added.empty() && patch.removed.empty())
 
36
                return;
 
37
 
 
38
        iterator i = this->find(patch.getItem());
 
39
        if (i == this->end())
 
40
                insert(make_pair<ITEM, Patch<ITEM, TAG> >(patch.getItem(), patch));
 
41
        else
 
42
                i->second.mergeWith(patch);
 
43
}
 
44
 
 
45
template <class ITEM, class TAG>
 
46
void PatchList<ITEM, TAG>::addPatch(const PatchList<ITEM, TAG>& patches)
 
47
{
 
48
        for (typename PatchList<ITEM, TAG>::const_iterator i = patches.begin();
 
49
                        i != patches.end(); i++)
 
50
                addPatch(i->second);
 
51
}
 
52
 
 
53
template <class ITEM, class TAG> template<typename COLL1, typename COLL2>
 
54
void PatchList<ITEM, TAG>::addPatch(const COLL1& im1, const COLL2& im2)
 
55
{
 
56
        for (typename COLL1::const_iterator i1 = im1.begin();
 
57
                        i1 != im1.end(); ++i1)
 
58
        {
 
59
                std::set<TAG> ts2 = im2.getTags(i1->first);
 
60
                std::set<TAG> added = ts2 - i1->second;
 
61
                std::set<TAG> removed = i1->second - ts2;
 
62
                if (!added.empty() || !removed.empty())
 
63
                        addPatch(Patch<ITEM, TAG>(i1->first, added, removed));
 
64
        }
 
65
}
 
66
 
 
67
template <class ITEM, class TAG>
 
68
std::set<TAG> PatchList<ITEM, TAG>::patch(const ITEM& item, const std::set<TAG>& tagset) const
 
69
{
 
70
        // Find the patch record for this item
 
71
        const_iterator p = this->find(item);
 
72
        if (p == this->end())
 
73
                // If there are no patches, return the tagset unchanged
 
74
                return tagset;
 
75
 
 
76
        // There are patches: apply them:
 
77
        return p->second.apply(tagset);
 
78
}
 
79
 
 
80
template <class ITEM, class TAG>
 
81
PatchList<ITEM, TAG> PatchList<ITEM, TAG>::getReverse() const
 
82
{
 
83
        PatchList<ITEM, TAG> res;
 
84
        for (typename PatchList<ITEM, TAG>::const_iterator i = this->begin();
 
85
                        i != this->end(); i++)
 
86
                res.addPatch(i->second.getReverse());
 
87
        return res;
 
88
}
 
89
 
 
90
 
 
91
/*
 
92
template <class ITEM>
 
93
void PatchList<ITEM>::consume(const ITEM& item, const std::set<string>& tags)
 
94
{
 
95
        patches.insert(make_pair(item, tags));
 
96
}
 
97
 
 
98
// Output the patch list to a TagcollConsumer
 
99
template <class ITEM>
 
100
void PatchList<ITEM>::output(TagcollConsumer<ITEM, std::string>& consumer) const
 
101
{
 
102
        for (typename map< ITEM, std::set<string> >::const_iterator i = patches.begin();
 
103
                        i != patches.end(); i++)
 
104
                if (i->second.size() == 0)
 
105
                        consumer.consume(i->first);
 
106
                else
 
107
                        consumer.consume(i->first, i->second);
 
108
}
 
109
*/
 
110
 
 
111
}
 
112
 
 
113
#endif
 
114
 
 
115
// vim:set ts=4 sw=4: