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
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 #include "PackageSpecification.h"
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
)
32 PackageSpecification::packageName () const
37 const PackageSpecification::_operators
38 PackageSpecification::op() const
44 PackageSpecification::version() const
50 PackageSpecification::setOperator (_operators anOperator
)
52 _operator
= anOperator
;
56 PackageSpecification::setVersion (const std::string
& aVersion
)
62 PackageSpecification::satisfies (packageversion
const &aPackage
) const
64 if (casecompare(_packageName
, aPackage
.Name()) != 0)
67 // The default values of _operator = Equals and _version is an empty-string
71 int comparison
= casecompare(aPackage
.Canonical_version (), _version
);
75 return (comparison
== 0);
77 return (comparison
< 0);
79 return (comparison
> 0);
81 return (comparison
<= 0);
83 return (comparison
>= 0);
92 operator << (std::ostream
&os
, PackageSpecification
const &spec
)
94 os
<< spec
._packageName
;
96 os
<< " " << PackageSpecification::caption(spec
._operator
) << " " << spec
._version
;
101 PackageSpecification::caption (_operators _value
)
116 // Pacify GCC: (all case options are checked above)
117 return "Unknown operator";