]> cygwin.com Git - cygwin-apps/setup.git/blame - package_version.cc
2002-07-05 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / package_version.cc
CommitLineData
7939f6d1
RC
1/*
2 * Copyright (c) 2001, Robert Collins.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins <rbtcollins@hotmail.com>
13 *
14 */
15
16/* this is the parent class for all package operations.
17 */
18
19#if 0
20static const char *cvsid =
21 "\n%%% $Id$\n";
22#endif
bb849dbd
RC
23
24#include "package_version.h"
3c196821
RC
25#include "package_db.h"
26#include "package_meta.h"
27#include "state.h"
28#include "resource.h"
29
30/* a default class to avoid special casing empty packageversions */
31
32/* TODO place into the class header */
33class _defaultversion : public _packageversion
bb849dbd 34{
3c196821
RC
35public:
36 _defaultversion()
37 {
38 // never try to free me!
39 ++references;
40 }
41 String const Name(){return String();}
42 String const Vendor_version() {return String();}
43 String const Package_version() {return String();}
44 String const Canonical_version() {return String();}
45 void setCanonicalVersion (String const &) {}
46 package_status_t Status (){return package_notinstalled;}
47 package_type_t Type () {return package_binary;}
48 String const getfirstfile () {return String();}
49 String const getnextfile () {return String();}
50 String const SDesc () {return String();}
51 void set_sdesc (String const &) {}
52 String const LDesc () {return String();}
53 void set_ldesc (String const &) {}
54 void uninstall (){}
bb849dbd 55};
3c196821
RC
56static _defaultversion defaultversion;
57
58/* the wrapper class */
59packageversion::packageversion() : data (&defaultversion)
60{
61 ++data->references;
62}
63
64/* Create from an actual package */
65packageversion::packageversion (_packageversion *pkg)
66{
67 if (pkg)
68 data = pkg;
69 else
70 data = &defaultversion;
71 ++data->references;
72}
73
74packageversion::packageversion (packageversion const &existing) :
75data(existing.data)
76{
77 ++data->references;
78}
79
80packageversion::~packageversion()
81{
82 if (--data->references == 0)
83 delete data;
84}
85
86packageversion &
87packageversion::operator= (packageversion const &rhs)
88{
89 ++rhs.data->references;
90 if (--data->references == 0)
91 delete data;
92 data = rhs.data;
93 return *this;
94}
95
96bool
97packageversion::operator ! () const
98{
99 return !data->Name().size();
100}
101
102packageversion::operator bool () const
103{
104 return data->Name().size();
105}
106
107bool
108packageversion::operator == (packageversion const &rhs) const
109{
110 if (this == &rhs || data == rhs.data)
111 return true;
112 else
113 return data->Name () == rhs.data->Name() && data->Canonical_version () == rhs.data->Canonical_version();
114}
115
116bool
117packageversion::operator != (packageversion const &rhs) const
118{
119 return ! (*this == rhs);
120}
121
122bool
123packageversion::operator < (packageversion const &rhs) const
124{
125 int t = data->Name ().casecompare (rhs.data->Name());
126 if (t < 0)
127 return true;
128 else if (t > 0)
129 return false;
130 else if (data->Canonical_version().casecompare (rhs.data->Canonical_version()) < 0)
131 return true;
132 return false;
133}
134
135String const
136packageversion::Name () const
137{
138 return data->Name ();
139}
140
141String const
142packageversion::Canonical_version() const
143{
144 return data->Canonical_version();
145}
146
147void
148packageversion::setCanonicalVersion (String const &ver)
149{
150 data->setCanonicalVersion (ver);
151}
152
153String const
154packageversion::getfirstfile ()
155{
156 return data->getfirstfile ();
157}
158
159String const
160packageversion::getnextfile ()
161{
162 return data->getnextfile ();
163}
164
165String const
166packageversion::SDesc () const
167{
168 return data->SDesc ();
169}
170
171void
172packageversion::set_sdesc (String const &sdesc)
173{
174 data->set_sdesc (sdesc);
175}
176
177String const
178packageversion::LDesc () const
179{
180 return data->LDesc ();
181}
182
183void
184packageversion::set_ldesc (String const &ldesc)
185{
186 data->set_ldesc (ldesc);
187}
188
189packageversion
190packageversion::sourcePackage()
191{
192 return data->sourcePackage();
193}
aa1e3b4d
RC
194
195PackageSpecification &
3c196821
RC
196packageversion::sourcePackageSpecification ()
197{
198 return data->sourcePackageSpecification ();
199}
200
201void
202packageversion::setSourcePackageSpecification (PackageSpecification const &spec)
203{
204 data->setSourcePackageSpecification(spec);
205}
206
207vector <vector <PackageSpecification *> *> *
208packageversion::depends()
209{
210 return &data->depends;
211}
212
213vector <vector <PackageSpecification *> *> *
214packageversion::predepends()
215{
216 return &data->predepends;
217}
218
219vector <vector <PackageSpecification *> *> *
220packageversion::recommends()
221{
222 return &data->recommends;
223}
224
225vector <vector <PackageSpecification *> *> *
226packageversion::suggests()
227{
228 return &data->suggests;
229}
230
231vector <vector <PackageSpecification *> *> *
232packageversion::replaces()
233{
234 return &data->replaces;
235}
236
237vector <vector <PackageSpecification *> *> *
238packageversion::conflicts()
239{
240 return &data->conflicts;
241}
242
243vector <vector <PackageSpecification *> *> *
244packageversion::provides()
245{
246 return &data->provides;
247}
248
249
250bool
251packageversion::picked () const
252{
253 return data->picked;
254}
255
256void
257packageversion::pick (bool aBool)
258{
259 data->picked = aBool;
260}
261
262bool
263packageversion::changeRequested () const
264{
265 return data->changeRequested ();
266}
267
268void
269packageversion::uninstall ()
270{
271 data->uninstall ();
272}
273
274packagesource *
275packageversion::source ()
276{
277 return &data->source;
278}
279
280bool
281packageversion::accessible() const
282{
283 return data->accessible();
284}
285
286/* the parent data class */
287
288_packageversion::_packageversion ():picked (false), references (0)
289{
290}
291
292_packageversion::~_packageversion ()
293{
294}
295
296PackageSpecification &
297_packageversion::sourcePackageSpecification ()
aa1e3b4d
RC
298{
299 return _sourcePackage;
300}
301
302void
3c196821 303_packageversion::setSourcePackageSpecification (PackageSpecification const &spec)
aa1e3b4d
RC
304{
305 _sourcePackage = spec;
306}
3c196821
RC
307
308packageversion
309_packageversion::sourcePackage ()
310{
311 if (!sourceVersion)
312 {
313 packagedb db;
314 packagemeta * pkg;
315 pkg = db.findSource (_sourcePackage);
316 /* no valid source meta available, just return the default
317 (blank) package version
318 */
319 if (!pkg)
320 return sourceVersion;
321 set<packageversion>::iterator i=pkg->versions.begin();
322 while (i != pkg->versions.end())
323 {
324 packageversion const & ver = * i;
325 if (_sourcePackage.satisfies (ver))
326 sourceVersion = ver;
327 ++i;
328 }
329 }
330 return sourceVersion;
331}
332
333bool
334_packageversion::accessible() const
335{
3f34f364 336 return ((::source != IDC_SOURCE_CWD) && source.sites.size()) ||
3c196821
RC
337 source.Cached ();
338}
339
340bool
341_packageversion::changeRequested ()
342{
343 return (picked || sourcePackage().picked());
344}
This page took 0.058411 seconds and 5 git commands to generate.