]> cygwin.com Git - cygwin-apps/setup.git/blob - PackageSpecification.cc
Use solver to check for problems and produce a list of package transactions
[cygwin-apps/setup.git] / PackageSpecification.cc
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 #include "PackageSpecification.h"
17 #include <iostream>
18 #include "package_version.h"
19
20 PackageSpecification::PackageSpecification (const std::string& packageName)
21 : _packageName (packageName) , _operator (Equals), _version ()
22 {
23 }
24
25 const std::string&
26 PackageSpecification::packageName () const
27 {
28 return _packageName;
29 }
30
31 const PackageSpecification::_operators
32 PackageSpecification::op() const
33 {
34 return _operator;
35 }
36
37 const std::string&
38 PackageSpecification::version() const
39 {
40 return _version;
41 }
42
43 void
44 PackageSpecification::setOperator (_operators anOperator)
45 {
46 _operator = anOperator;
47 }
48
49 void
50 PackageSpecification::setVersion (const std::string& aVersion)
51 {
52 _version = aVersion;
53 }
54
55 bool
56 PackageSpecification::satisfies (packageversion const &aPackage) const
57 {
58 if (casecompare(_packageName, aPackage.Name()) != 0)
59 return false;
60
61 // The default values of _operator = Equals and _version is an empty-string
62 // match any version
63 if (_version.size())
64 {
65 int comparison = casecompare(aPackage.Canonical_version (), _version);
66 switch (_operator)
67 {
68 case Equals:
69 return (comparison == 0);
70 case LessThan:
71 return (comparison < 0);
72 case MoreThan:
73 return (comparison > 0);
74 case LessThanEquals:
75 return (comparison <= 0);
76 case MoreThanEquals:
77 return (comparison >= 0);
78 default:
79 return false;
80 }
81 }
82 return true;
83 }
84
85 std::ostream &
86 operator << (std::ostream &os, PackageSpecification const &spec)
87 {
88 os << spec._packageName;
89 if (spec._operator)
90 os << " " << PackageSpecification::caption(spec._operator) << " " << spec._version;
91 return os;
92 }
93
94 char const *
95 PackageSpecification::caption (_operators _value)
96 {
97 switch (_value)
98 {
99 case Equals:
100 return "==";
101 case LessThan:
102 return "<";
103 case MoreThan:
104 return ">";
105 case LessThanEquals:
106 return "<=";
107 case MoreThanEquals:
108 return ">=";
109 }
110 // Pacify GCC: (all case options are checked above)
111 return "Unknown operator";
112 }
This page took 0.041955 seconds and 5 git commands to generate.