00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_EDITION_H
00013 #define ZYPP_EDITION_H
00014
00015 #include <iosfwd>
00016 #include <functional>
00017 #include <string>
00018
00019 #include "zypp/base/PtrTypes.h"
00020
00021 #include "zypp/RelCompare.h"
00022 #include "zypp/Range.h"
00023
00025 namespace zypp
00026 {
00027
00029
00030
00031
00068 class Edition
00069 {
00070 public:
00072 typedef unsigned epoch_t;
00073
00075 static const epoch_t noepoch = 0;
00076
00081 static const Edition noedition;
00082
00083 public:
00085 Edition();
00086
00090 Edition( const std::string & edition_r );
00091
00095 Edition( const std::string & version_r,
00096 const std::string & release_r,
00097 epoch_t epoch_r = noepoch );
00098
00103 Edition( const std::string & version_r,
00104 const std::string & release_r,
00105 const std::string & epoch_r );
00106
00108 ~Edition();
00109
00110 public:
00112 epoch_t epoch() const;
00113
00115 const std::string & version() const;
00116
00118 const std::string & release() const;
00119
00121 std::string asString() const;
00122
00123 public:
00131 static int compare( const Edition & lhs, const Edition & rhs );
00132
00134 int compare( const Edition & rhs ) const
00135 { return compare( *this, rhs ); }
00136
00140 typedef Compare<Edition> Compare;
00141
00145 typedef Range<Edition> CompareRange;
00146
00147 public:
00152 static int match( const Edition & lhs, const Edition & rhs );
00153
00155 int match( const Edition & rhs ) const
00156 { return match( *this, rhs ); }
00157
00161 struct Match: public std::binary_function<Edition,Edition,int>
00162 {
00163 int operator()( const Edition & lhs, const Edition & rhs ) const
00164 { return Edition::match( lhs, rhs ); }
00165 };
00166
00170 typedef Range<Edition, Match> MatchRange;
00171
00172 private:
00174 struct Impl;
00176 RW_pointer<Impl> _pimpl;
00177 };
00179
00181 inline std::ostream & operator<<( std::ostream & str, const Edition & obj )
00182 { return str << obj.asString(); }
00183
00187 inline bool operator==( const Edition & lhs, const Edition & rhs )
00188 { return compareByRel( Rel::EQ, lhs, rhs ); }
00189
00191 inline bool operator!=( const Edition & lhs, const Edition & rhs )
00192 { return compareByRel( Rel::NE, lhs, rhs ); }
00193
00195 inline bool operator<( const Edition & lhs, const Edition & rhs )
00196 { return compareByRel( Rel::LT, lhs, rhs ); }
00197
00199 inline bool operator<=( const Edition & lhs, const Edition & rhs )
00200 { return compareByRel( Rel::LE, lhs, rhs ); }
00201
00203 inline bool operator>( const Edition & lhs, const Edition & rhs )
00204 { return compareByRel( Rel::GT, lhs, rhs ); }
00205
00207 inline bool operator>=( const Edition & lhs, const Edition & rhs )
00208 { return compareByRel( Rel::GE, lhs, rhs ); }
00210
00212 }
00214
00216 namespace std
00217 {
00218
00220 template<>
00221 inline bool less<zypp::Edition>::operator()( const zypp::Edition & lhs, const zypp::Edition & rhs ) const
00222 { return lhs.asString() < rhs.asString(); }
00223
00225 template<>
00226 inline bool equal_to<zypp::Edition>::operator()( const zypp::Edition & lhs, const zypp::Edition & rhs ) const
00227 { return lhs.asString() == rhs.asString(); }
00228
00230 }
00232
00233 #endif // ZYPP_EDITION_H