aboutsummaryrefslogtreecommitdiff
path: root/paludis/fake_repository.cc
blob: d594b7ba73f89b21ea7522a9a402aabff15f89c9 (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
 *
 * 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
 */

#include <map>
#include <paludis/fake_repository.hh>
#include <paludis/util/stringify.hh>
#include <paludis/version_metadata.hh>

using namespace paludis;

namespace paludis
{
    /**
     * Implementation data for FakeRepository.
     */
    template<>
    struct Implementation<FakeRepository> :
        private InstantiationPolicy<Implementation<FakeRepository>, instantiation_method::NonCopyableTag>,
        InternalCounted<Implementation<FakeRepository> >
    {
        /// Our category names.
        CategoryNamePartCollection::Pointer category_names;

        /// Our package names.
        std::map<CategoryNamePart, PackageNamePartCollection::Pointer > package_names;

        /// Our versions.
        std::map<QualifiedPackageName, VersionSpecCollection::Pointer > versions;

        /// Our metadata.
        std::map<std::string, VersionMetadata::Pointer > metadata;

        /// (Empty) provides map.
        const std::map<QualifiedPackageName, QualifiedPackageName> provide_map;

        /// Constructor.
        Implementation() :
            category_names(new CategoryNamePartCollection)
        {
        }
    };
}

FakeRepository::FakeRepository(const RepositoryName & name) :
    Repository(name),
    PrivateImplementationPattern<FakeRepository>(new Implementation<FakeRepository>)
{
    _info.insert(std::make_pair(std::string("format"), std::string("fake")));
}

FakeRepository::~FakeRepository()
{
}

bool
FakeRepository::do_has_category_named(const CategoryNamePart & c) const
{
    return (_imp->category_names->end() != _imp->category_names->find(c));
}

bool
FakeRepository::do_has_package_named(const CategoryNamePart & c,
        const PackageNamePart & p) const
{
    return has_category_named(c) &&
        (_imp->package_names.find(c)->second->end() !=
         _imp->package_names.find(c)->second->find(p));
}

CategoryNamePartCollection::ConstPointer
FakeRepository::do_category_names() const
{
    return _imp->category_names;
}

QualifiedPackageNameCollection::ConstPointer
FakeRepository::do_package_names(const CategoryNamePart & c) const
{
    if (! has_category_named(c))
        throw InternalError(PALUDIS_HERE, "no category named " + stringify(c));
    QualifiedPackageNameCollection::Pointer result(new QualifiedPackageNameCollection);
    PackageNamePartCollection::Iterator p(_imp->package_names.find(c)->second->begin()),
        p_end(_imp->package_names.find(c)->second->end());
    for ( ; p != p_end ; ++p)
        result->insert(QualifiedPackageName(c, *p));
    return result;
}

VersionSpecCollection::ConstPointer
FakeRepository::do_version_specs(const QualifiedPackageName & n) const
{
    if (! has_category_named(n.get<qpn_category>()))
        throw InternalError(PALUDIS_HERE, "no category");
    if (! has_package_named(n.get<qpn_category>(), n.get<qpn_package>()))
        throw InternalError(PALUDIS_HERE, "no package");
    return _imp->versions.find(n)->second;
}

bool
FakeRepository::do_has_version(const CategoryNamePart & c,
        const PackageNamePart & p, const VersionSpec & v) const
{
    if (! has_category_named(c))
        throw InternalError(PALUDIS_HERE, "no category");
    if (! has_package_named(c, p))
        throw InternalError(PALUDIS_HERE, "no package");
    return _imp->versions.find(QualifiedPackageName(c, p))->second->find(v) !=
        _imp->versions.find(QualifiedPackageName(c, p))->second->end();
}

void
FakeRepository::add_category(const CategoryNamePart & c)
{
    _imp->category_names->insert(c);
    _imp->package_names.insert(std::make_pair(c, new PackageNamePartCollection));
}

void
FakeRepository::add_package(const CategoryNamePart & c, const PackageNamePart & p)
{
    add_category(c);
    _imp->package_names.find(c)->second->insert(p);
    _imp->versions.insert(std::make_pair(QualifiedPackageName(c, p),
                new VersionSpecCollection));
}

VersionMetadata::Pointer
FakeRepository::add_version(const CategoryNamePart & c, const PackageNamePart & p,
        const VersionSpec & v)
{
    add_package(c, p);
    _imp->versions.find(QualifiedPackageName(c, p))->second->insert(v);
    _imp->metadata.insert(
            std::make_pair(stringify(c) + "/" + stringify(p) + "-" + stringify(v), new VersionMetadata));
    VersionMetadata::Pointer r(_imp->metadata.find(stringify(c) +
                "/" + stringify(p) + "-" + stringify(v))->second);
    r->set(vmk_slot, "0");
    r->set(vmk_keywords, "test");
    return r;
}

VersionMetadata::ConstPointer
FakeRepository::do_version_metadata(
        const CategoryNamePart & c, const PackageNamePart & p, const VersionSpec & v) const
{
    if (! has_version(c, p, v))
        throw InternalError(PALUDIS_HERE, "no version");
    return _imp->metadata.find(stringify(c) + "/" + stringify(p) + "-" + stringify(v))->second;
}

bool
FakeRepository::do_query_repository_masks(const CategoryNamePart &,
        const PackageNamePart &, const VersionSpec &) const
{
    return false;
}

bool
FakeRepository::do_query_profile_masks(const CategoryNamePart &,
        const PackageNamePart &, const VersionSpec &) const
{
    return false;
}

UseFlagState
FakeRepository::do_query_use(const UseFlagName &, const PackageDatabaseEntry *) const
{
    return use_unspecified;
}

bool
FakeRepository::do_query_use_mask(const UseFlagName &) const
{
    return false;
}

bool
FakeRepository::do_is_arch_flag(const UseFlagName &) const
{
    return false;
}

bool
FakeRepository::do_is_expand_flag(const UseFlagName &) const
{
    return false;
}

bool
FakeRepository::do_is_licence(const std::string &) const
{
    return false;
}

bool
FakeRepository::do_is_mirror(const std::string &) const
{
    return false;
}

void
FakeRepository::do_install(const QualifiedPackageName &, const VersionSpec &, const InstallOptions &) const
{
}

void
FakeRepository::do_uninstall(const QualifiedPackageName &, const VersionSpec &, const InstallOptions &) const
{
}

DepAtom::Pointer
FakeRepository::do_package_set(const std::string &) const
{
    AllDepAtom::Pointer result(0);

    return result;
}

bool
FakeRepository::do_sync() const
{
    return false;
}

void
FakeRepository::invalidate() const
{
}

Repository::ProvideMapIterator
FakeRepository::begin_provide_map() const
{
    return _imp->provide_map.begin();
}

Repository::ProvideMapIterator
FakeRepository::end_provide_map() const
{
    return _imp->provide_map.end();
}