Adjustment to dialog layout for translation
[cygwin-setup.git] / PackageSpecification.cc
blobb58ad8048644a27b02fb1b2e11e94817dfd35bf0
1 /*
2 * Copyright (c) 2002, Robert Collins.
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.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 #include "PackageSpecification.h"
17 #include <iostream>
18 #include "package_version.h"
20 PackageSpecification::PackageSpecification (const std::string& packageName)
21 : _packageName (packageName) , _operator (Equals), _version ()
25 PackageSpecification::PackageSpecification (const std::string& packageName,
26 const std::string& packageVersion)
27 : _packageName (packageName) , _operator (Equals), _version (packageVersion)
31 const std::string&
32 PackageSpecification::packageName () const
34 return _packageName;
37 const PackageSpecification::_operators
38 PackageSpecification::op() const
40 return _operator;
43 const std::string&
44 PackageSpecification::version() const
46 return _version;
49 void
50 PackageSpecification::setOperator (_operators anOperator)
52 _operator = anOperator;
55 void
56 PackageSpecification::setVersion (const std::string& aVersion)
58 _version = aVersion;
61 bool
62 PackageSpecification::satisfies (packageversion const &aPackage) const
64 if (casecompare(_packageName, aPackage.Name()) != 0)
65 return false;
67 // The default values of _operator = Equals and _version is an empty-string
68 // match any version
69 if (_version.size())
71 int comparison = casecompare(aPackage.Canonical_version (), _version);
72 switch (_operator)
74 case Equals:
75 return (comparison == 0);
76 case LessThan:
77 return (comparison < 0);
78 case MoreThan:
79 return (comparison > 0);
80 case LessThanEquals:
81 return (comparison <= 0);
82 case MoreThanEquals:
83 return (comparison >= 0);
84 default:
85 return false;
88 return true;
91 std::ostream &
92 operator << (std::ostream &os, PackageSpecification const &spec)
94 os << spec._packageName;
95 if (spec._operator)
96 os << " " << PackageSpecification::caption(spec._operator) << " " << spec._version;
97 return os;
100 char const *
101 PackageSpecification::caption (_operators _value)
103 switch (_value)
105 case Equals:
106 return "==";
107 case LessThan:
108 return "<";
109 case MoreThan:
110 return ">";
111 case LessThanEquals:
112 return "<=";
113 case MoreThanEquals:
114 return ">=";
116 // Pacify GCC: (all case options are checked above)
117 return "Unknown operator";