]> cygwin.com Git - cygwin-apps/setup.git/blame - PackageSpecification.cc
2002-07-05 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / PackageSpecification.cc
CommitLineData
aa1e3b4d
RC
1/*
2 * Copyright (c) 2002, 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#if 0
17static const char *cvsid = "\n%%% $Id$\n";
18#endif
19
20#include "PackageSpecification.h"
21#include "package_version.h"
22
23PackageSpecification::PackageSpecification (String const &packageName)
24 : _packageName (packageName) , _operator (0), _version ()
25{
26}
27
28String const&
29PackageSpecification::packageName () const
30{
31 return _packageName;
32}
33
34void
35PackageSpecification::setOperator (_operators const &anOperator)
36{
37 _operator = &anOperator;
38}
39
40void
41PackageSpecification::setVersion (String const &aVersion)
42{
43 _version = aVersion;
44}
45
46bool
47PackageSpecification::satisfies (packageversion const &aPackage) const
48{
64cd7f94
RC
49 if (_packageName.casecompare (aPackage.Name()) != 0)
50 return false;
51 if (_operator && _version.size()
52 && !_operator->satisfies (aPackage.Canonical_version (), _version))
53 return false;
54 return true;
aa1e3b4d
RC
55}
56
57String
58PackageSpecification::serialise () const
59{
60 return _packageName;
61}
62
63PackageSpecification &
64PackageSpecification::operator= (PackageSpecification const &rhs)
65{
66 _packageName = rhs._packageName;
67 return *this;
68}
69
70std::ostream &
71operator << (std::ostream &os, PackageSpecification const &spec)
72{
73 os << spec._packageName;
74 if (spec._operator)
75 os << " " << spec._operator->caption() << " " << spec._version;
76 return os;
77}
78
79const PackageSpecification::_operators PackageSpecification::Equals(0);
80const PackageSpecification::_operators PackageSpecification::LessThan(1);
81const PackageSpecification::_operators PackageSpecification::MoreThan(2);
82const PackageSpecification::_operators PackageSpecification::LessThanEquals(3);
83const PackageSpecification::_operators PackageSpecification::MoreThanEquals(4);
84
85char const *
86PackageSpecification::_operators::caption () const
87{
88 switch (_value)
89 {
90 case 0:
91 return "==";
92 case 1:
93 return "<";
94 case 2:
95 return ">";
96 case 3:
97 return "<=";
98 case 4:
99 return ">=";
100 }
101 // Pacify GCC: (all case options are checked above)
102 return "Unknown operator";
103}
64cd7f94
RC
104
105bool
106PackageSpecification::_operators::satisfies (String const &lhs, String const &rhs) const
107{
108 switch (_value)
109 {
110 case 0:
111 return lhs.casecompare (rhs) == 0;
112 case 1:
113 return lhs.casecompare (rhs) < 0;
114 case 2:
115 return lhs.casecompare (rhs) > 0;
116 case 3:
117 return lhs.casecompare (rhs) <= 0;
118 case 4:
119 return lhs.casecompare (rhs) >= 0;
120 }
121 return false;
122}
This page took 0.083054 seconds and 5 git commands to generate.