aboutsummaryrefslogtreecommitdiff
path: root/paludis/create_output_manager_info.cc
blob: eedfb6274ea6b733debc85e4a750b4a19db80a14 (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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2009, 2010, 2011 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
 */

#include <paludis/create_output_manager_info.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/exception.hh>
#include <paludis/util/set.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/serialise-impl.hh>
#include <paludis/action.hh>
#include <paludis/name.hh>
#include <ostream>

using namespace paludis;

#include <paludis/create_output_manager_info-se.cc>

namespace
{
    struct GetFlagsVisitor
    {
        std::shared_ptr<Set<std::string> > visit(const InstallAction &) const
        {
            return std::make_shared<Set<std::string>>();
        }

        std::shared_ptr<Set<std::string> > visit(const UninstallAction &) const
        {
            return std::make_shared<Set<std::string>>();
        }

        std::shared_ptr<Set<std::string> > visit(const PretendAction &) const
        {
            return std::make_shared<Set<std::string>>();
        }

        std::shared_ptr<Set<std::string> > visit(const FetchAction & a) const
        {
            std::shared_ptr<Set<std::string> > result(std::make_shared<Set<std::string>>());
            if (a.options.ignore_unfetched())
                result->insert(FetchAction::ignore_unfetched_flag_name());
            return result;
        }

        std::shared_ptr<Set<std::string> > visit(const PretendFetchAction &) const
        {
            return std::make_shared<Set<std::string>>();
        }

        std::shared_ptr<Set<std::string> > visit(const ConfigAction &) const
        {
            return std::make_shared<Set<std::string>>();
        }

        std::shared_ptr<Set<std::string> > visit(const InfoAction &) const
        {
            return std::make_shared<Set<std::string>>();
        }
    };

    std::shared_ptr<Set<std::string> > get_flags(const Action & a)
    {
        return a.accept_returning<std::shared_ptr<Set<std::string> > >(GetFlagsVisitor());
    }
}

namespace paludis
{
    template <>
    struct Imp<CreateOutputManagerForPackageIDActionInfo>
    {
        const std::shared_ptr<const PackageID> id;
        const std::string action_name;
        const std::shared_ptr<const Set<std::string> > action_flags;
        const OutputExclusivity output_exclusivity;
        const ClientOutputFeatures client_output_features;

        Imp(const std::shared_ptr<const PackageID> & i,
                const std::string & a,
                const std::shared_ptr<const Set<std::string> > & f,
                const OutputExclusivity e,
                const ClientOutputFeatures & c) :
            id(i),
            action_name(a),
            action_flags(f),
            output_exclusivity(e),
            client_output_features(c)
        {
        }
    };

    template <>
    struct Imp<CreateOutputManagerForRepositorySyncInfo>
    {
        const RepositoryName repo_name;
        const OutputExclusivity output_exclusivity;
        const ClientOutputFeatures client_output_features;

        Imp(const RepositoryName & r, const OutputExclusivity e, const ClientOutputFeatures & c) :
            repo_name(r),
            output_exclusivity(e),
            client_output_features(c)
        {
        }
    };
}

const std::shared_ptr<CreateOutputManagerInfo>
CreateOutputManagerInfo::deserialise(Deserialisation & d)
{
    if (d.class_name() == "CreateOutputManagerForPackageIDActionInfo")
        return CreateOutputManagerForPackageIDActionInfo::deserialise(d);
    else if (d.class_name() == "CreateOutputManagerForRepositorySyncInfo")
        return CreateOutputManagerForRepositorySyncInfo::deserialise(d);
    else
        throw InternalError(PALUDIS_HERE, "unknown class '" + stringify(d.class_name()) + "'");
}

CreateOutputManagerForPackageIDActionInfo::CreateOutputManagerForPackageIDActionInfo(
        const std::shared_ptr<const PackageID> & i,
        const Action & a,
        const OutputExclusivity e,
        const ClientOutputFeatures & c) :
    _imp(i, a.simple_name(), get_flags(a), e, c)
{
}

CreateOutputManagerForPackageIDActionInfo::CreateOutputManagerForPackageIDActionInfo(
        const std::shared_ptr<const PackageID> & i,
        const std::string & a,
        const std::shared_ptr<const Set<std::string> > & f,
        const OutputExclusivity e,
        const ClientOutputFeatures & c) :
    _imp(i, a, f, e, c)
{
}

CreateOutputManagerForPackageIDActionInfo::~CreateOutputManagerForPackageIDActionInfo()
{
}

const std::shared_ptr<const PackageID>
CreateOutputManagerForPackageIDActionInfo::package_id() const
{
    return _imp->id;
}

const std::string
CreateOutputManagerForPackageIDActionInfo::action_name() const
{
    return _imp->action_name;
}

const std::shared_ptr<const Set<std::string> >
CreateOutputManagerForPackageIDActionInfo::action_flags() const
{
    return _imp->action_flags;
}

OutputExclusivity
CreateOutputManagerForPackageIDActionInfo::output_exclusivity() const
{
    return _imp->output_exclusivity;
}

const ClientOutputFeatures
CreateOutputManagerForPackageIDActionInfo::client_output_features() const
{
    return _imp->client_output_features;
}

void
CreateOutputManagerForPackageIDActionInfo::serialise(Serialiser & s) const
{
    s.object("CreateOutputManagerForPackageIDActionInfo")
        .member(SerialiserFlags<serialise::might_be_null, serialise::container>(), "action_flags", action_flags())
        .member(SerialiserFlags<>(), "action_name", action_name())
        .member(SerialiserFlags<>(), "output_exclusivity", stringify(output_exclusivity()))
        .member(SerialiserFlags<serialise::might_be_null>(), "package_id", package_id())
        .member(SerialiserFlags<>(), "client_output_features", client_output_features())
        ;
}

const std::shared_ptr<CreateOutputManagerForPackageIDActionInfo>
CreateOutputManagerForPackageIDActionInfo::deserialise(Deserialisation & d)
{
    Deserialisator v(d, "CreateOutputManagerForPackageIDActionInfo");

    std::shared_ptr<Set<std::string> > action_flags(std::make_shared<Set<std::string>>());
    Deserialisator vv(*v.find_remove_member("action_flags"), "c");
    for (int n(1), n_end(vv.member<int>("count") + 1) ; n != n_end ; ++n)
        action_flags->insert(vv.member<std::string>(stringify(n)));

    return std::make_shared<CreateOutputManagerForPackageIDActionInfo>(
                v.member<std::shared_ptr<const PackageID> >("package_id"),
                v.member<std::string>("action_name"),
                action_flags,
                destringify<OutputExclusivity>(v.member<std::string>("output_exclusivity")),
                v.member<ClientOutputFeatures>("client_output_features")
                );
}

CreateOutputManagerForRepositorySyncInfo::CreateOutputManagerForRepositorySyncInfo(
        const RepositoryName & r, const OutputExclusivity e, const ClientOutputFeatures & c) :
    _imp(r, e, c)
{
}

CreateOutputManagerForRepositorySyncInfo::~CreateOutputManagerForRepositorySyncInfo()
{
}

const RepositoryName
CreateOutputManagerForRepositorySyncInfo::repository_name() const
{
    return _imp->repo_name;
}

OutputExclusivity
CreateOutputManagerForRepositorySyncInfo::output_exclusivity() const
{
    return _imp->output_exclusivity;
}

const ClientOutputFeatures
CreateOutputManagerForRepositorySyncInfo::client_output_features() const
{
    return _imp->client_output_features;
}

void
CreateOutputManagerForRepositorySyncInfo::serialise(Serialiser & s) const
{
    s.object("CreateOutputManagerForRepositorySyncInfo")
        .member(SerialiserFlags<>(), "repository_name", stringify(repository_name()))
        .member(SerialiserFlags<>(), "output_exclusivity", stringify(output_exclusivity()))
        .member(SerialiserFlags<>(), "client_output_features", client_output_features())
        ;
}

const std::shared_ptr<CreateOutputManagerForRepositorySyncInfo>
CreateOutputManagerForRepositorySyncInfo::deserialise(Deserialisation & d)
{
    Deserialisator v(d, "CreateOutputManagerForRepositorySyncInfo");
    return std::make_shared<CreateOutputManagerForRepositorySyncInfo>(
                RepositoryName(v.member<std::string>("repo_name")),
                destringify<OutputExclusivity>(v.member<std::string>("output_exclusivity")),
                v.member<ClientOutputFeatures>("client_output_features")
                );
}

namespace paludis
{
    template class Pimp<CreateOutputManagerForRepositorySyncInfo>;
    template class Pimp<CreateOutputManagerForPackageIDActionInfo>;
}