aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/map-impl.hh
blob: 901ca1e41c634e586bd2f5ab7df2b2d6742d1ce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2007, 2009 Ciaran McCreesh
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis 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., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef PALUDIS_GUARD_PALUDIS_UTIL_MAP_IMPL_HH
#define PALUDIS_GUARD_PALUDIS_UTIL_MAP_IMPL_HH 1

#include <paludis/util/map.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/wrapped_output_iterator-impl.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <map>
#include <iterator>
#include <functional>

/** \file
 * Implementation for paludis/util/map.hh .
 *
 * \ingroup g_data_structures
 */

namespace paludis
{
    /**
     * The default comparator for a Map is std::less<>.
     *
     * \ingroup g_data_structures
     */
    template <typename T_>
    struct PALUDIS_VISIBLE DefaultMapComparator :
        std::less<T_>
    {
    };

    /**
     * Implementation data for a Map.
     *
     * \ingroup g_data_structures
     * \nosubgrouping
     */
#ifndef PALUDIS_NO_DOUBLE_TEMPLATE
    template <>
#endif
    template <typename K_, typename V_, typename C_>
    struct Implementation<Map<K_, V_, C_> >
    {
        std::map<K_, V_, C_> map;
    };

    template <typename K_, typename V_, typename C_>
    struct WrappedForwardIteratorTraits<MapConstIteratorTag<K_, V_, C_> >
    {
        typedef typename std::map<K_, V_, C_>::const_iterator UnderlyingIterator;
    };

    template <typename K_, typename V_, typename C_>
    struct WrappedOutputIteratorTraits<MapInserterTag<K_, V_, C_> >
    {
        typedef std::insert_iterator<std::map<K_, V_, C_> > UnderlyingIterator;
    };
}

template <typename K_, typename V_, typename C_>
paludis::Map<K_, V_, C_>::Map() :
    paludis::PrivateImplementationPattern<paludis::Map<K_, V_, C_> >(new paludis::Implementation<paludis::Map<K_, V_, C_> >)
{
}

template <typename K_, typename V_, typename C_>
paludis::Map<K_, V_, C_>::~Map()
{
}

template <typename K_, typename V_, typename C_>
typename paludis::Map<K_, V_, C_>::ConstIterator
paludis::Map<K_, V_, C_>::begin() const
{
    return ConstIterator(_imp->map.begin());
}

template <typename K_, typename V_, typename C_>
typename paludis::Map<K_, V_, C_>::ConstIterator
paludis::Map<K_, V_, C_>::end() const
{
    return ConstIterator(_imp->map.end());
}

template <typename K_, typename V_, typename C_>
typename paludis::Map<K_, V_, C_>::ConstIterator
paludis::Map<K_, V_, C_>::find(const K_ & k) const
{
    return ConstIterator(_imp->map.find(k));
}

template <typename K_, typename V_, typename C_>
typename paludis::Map<K_, V_, C_>::Inserter
paludis::Map<K_, V_, C_>::inserter()
{
    return Inserter(std::inserter(_imp->map, _imp->map.begin()));
}

template <typename K_, typename V_, typename C_>
bool
paludis::Map<K_, V_, C_>::empty() const
{
    return _imp->map.empty();
}

template <typename K_, typename V_, typename C_>
unsigned
paludis::Map<K_, V_, C_>::size() const
{
    return _imp->map.size();
}

template <typename K_, typename V_, typename C_>
void
paludis::Map<K_, V_, C_>::insert(const K_ & k, const V_ & v)
{
    _imp->map.insert(std::make_pair(k, v));
}

template <typename K_, typename V_, typename C_>
void
paludis::Map<K_, V_, C_>::erase(const typename paludis::Map<K_, V_, C_>::ConstIterator & i)
{
    _imp->map.erase(i->first);
}

template <typename K_, typename V_, typename C_>
void
paludis::Map<K_, V_, C_>::erase(const K_ & i)
{
    _imp->map.erase(i);
}

#endif