libept
utils.h
Go to the documentation of this file.
1 /*
2  * Ready-made utility classes for Debtags
3  *
4  * Copyright (C) 2003--2007 Enrico Zini <enrico@debian.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 #ifndef EPT_DEBTAGS_UTILS_H
22 #define EPT_DEBTAGS_UTILS_H
23 
24 #include <wibble/mixin.h>
25 #include <ept/debtags/tag.h>
26 
27 namespace ept {
28 namespace debtags {
29 
34 template<typename OUT>
35 class TagToFacet : public wibble::mixin::OutputIterator< TagToFacet<OUT> >
36 {
37 protected:
38  OUT out;
39 
40 public:
41  TagToFacet(const OUT& out) : out(out) {}
42 
43  template<typename ITEMS, typename TAGS>
44  TagToFacet<OUT>& operator=(const std::pair<ITEMS, TAGS>& data)
45  {
46  std::set< Facet > facets;
47  for (typename TAGS::const_iterator i = data.second.begin();
48  i != data.second.end(); ++i)
49  facets.insert(i->facet());
50  *out = make_pair(data.first, facets);
51  ++out;
52  return *this;
53  }
54 };
55 
56 template<typename OUT>
57 static TagToFacet<OUT> tagToFacet(const OUT& out)
58 {
59  return TagToFacet<OUT>(out);
60 }
61 
62 }
63 }
64 
65 // vim:set ts=4 sw=4:
66 #endif