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>
17 static const char *cvsid
= "\n%%% $Id$\n";
20 #include "PackageSpecification.h"
22 #include "package_version.h"
24 PackageSpecification::PackageSpecification (const std::string
& packageName
)
25 : _packageName (packageName
) , _operator (0), _version ()
30 PackageSpecification::packageName () const
36 PackageSpecification::setOperator (_operators
const &anOperator
)
38 _operator
= &anOperator
;
42 PackageSpecification::setVersion (const std::string
& aVersion
)
48 PackageSpecification::satisfies (packageversion
const &aPackage
) const
50 if (casecompare(_packageName
, aPackage
.Name()) != 0)
52 if (_operator
&& _version
.size()
53 && !_operator
->satisfies (aPackage
.Canonical_version (), _version
))
59 PackageSpecification::serialise () const
64 PackageSpecification
&
65 PackageSpecification::operator= (PackageSpecification
const &rhs
)
67 _packageName
= rhs
._packageName
;
72 operator << (std::ostream
&os
, PackageSpecification
const &spec
)
74 os
<< spec
._packageName
;
76 os
<< " " << spec
._operator
->caption() << " " << spec
._version
;
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);
87 PackageSpecification::_operators::caption () const
102 // Pacify GCC: (all case options are checked above)
103 return "Unknown operator";
107 PackageSpecification::_operators::satisfies (const std::string
& lhs
,
108 const std::string
& rhs
) const
113 return casecompare(lhs
, rhs
) == 0;
115 return casecompare(lhs
, rhs
) < 0;
117 return casecompare(lhs
, rhs
) > 0;
119 return casecompare(lhs
, rhs
) <= 0;
121 return casecompare(lhs
, rhs
) >= 0;