README: document some recent changes in the build environment
[cygwin-setup.git] / PackageSpecification.cc
blobc64d509178ad1b6dd230217bd231fbc805f4619e
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 #if 0
17 static const char *cvsid = "\n%%% $Id$\n";
18 #endif
20 #include "PackageSpecification.h"
21 #include <iostream>
22 #include "package_version.h"
24 PackageSpecification::PackageSpecification (const std::string& packageName)
25 : _packageName (packageName) , _operator (0), _version ()
29 const std::string&
30 PackageSpecification::packageName () const
32 return _packageName;
35 void
36 PackageSpecification::setOperator (_operators const &anOperator)
38 _operator = &anOperator;
41 void
42 PackageSpecification::setVersion (const std::string& aVersion)
44 _version = aVersion;
47 bool
48 PackageSpecification::satisfies (packageversion const &aPackage) const
50 if (casecompare(_packageName, aPackage.Name()) != 0)
51 return false;
52 if (_operator && _version.size()
53 && !_operator->satisfies (aPackage.Canonical_version (), _version))
54 return false;
55 return true;
58 std::string
59 PackageSpecification::serialise () const
61 return _packageName;
64 PackageSpecification &
65 PackageSpecification::operator= (PackageSpecification const &rhs)
67 _packageName = rhs._packageName;
68 return *this;
71 std::ostream &
72 operator << (std::ostream &os, PackageSpecification const &spec)
74 os << spec._packageName;
75 if (spec._operator)
76 os << " " << spec._operator->caption() << " " << spec._version;
77 return os;
80 const PackageSpecification::_operators PackageSpecification::Equals(0);
81 const PackageSpecification::_operators PackageSpecification::LessThan(1);
82 const PackageSpecification::_operators PackageSpecification::MoreThan(2);
83 const PackageSpecification::_operators PackageSpecification::LessThanEquals(3);
84 const PackageSpecification::_operators PackageSpecification::MoreThanEquals(4);
86 char const *
87 PackageSpecification::_operators::caption () const
89 switch (_value)
91 case 0:
92 return "==";
93 case 1:
94 return "<";
95 case 2:
96 return ">";
97 case 3:
98 return "<=";
99 case 4:
100 return ">=";
102 // Pacify GCC: (all case options are checked above)
103 return "Unknown operator";
106 bool
107 PackageSpecification::_operators::satisfies (const std::string& lhs,
108 const std::string& rhs) const
110 switch (_value)
112 case 0:
113 return casecompare(lhs, rhs) == 0;
114 case 1:
115 return casecompare(lhs, rhs) < 0;
116 case 2:
117 return casecompare(lhs, rhs) > 0;
118 case 3:
119 return casecompare(lhs, rhs) <= 0;
120 case 4:
121 return casecompare(lhs, rhs) >= 0;
123 return false;