From 81eba9570d2e212fb4339b7cacdb61bb9b27302c Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Tue, 22 Nov 2005 12:45:39 +0000 Subject: [PATCH] Added comparison operators to Edition interfacae. --- zypp/Arch.h | 38 ++++++++++++++++++++------- zypp/Edition.cc | 15 +++++------ zypp/Edition.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++----- zypp/RelOp.h | 1 + zypp/base/PtrTypes.h | 9 +++++-- 5 files changed, 110 insertions(+), 27 deletions(-) diff --git a/zypp/Arch.h b/zypp/Arch.h index c86b0a1..f4b1d7c 100644 --- a/zypp/Arch.h +++ b/zypp/Arch.h @@ -55,26 +55,40 @@ namespace zypp }; /////////////////////////////////////////////////////////////////// - //@{ - /** \relates Arch Builtin architecture. - * Outside Arch, because some names, like \c i388, are used - * as \c #define, thus unusable as identifier. + /** \name Builtin architecture constants. + * + * Defined outside Arch as e.g. \c Arch_i386, because some names, + * like \c i388, are used as \c #define, thus unusable as identifier + * like \c Arch::i386. */ + //@{ + /** \relates Arch */ extern const Arch Arch_noarch; + /** \relates Arch */ extern const Arch Arch_x86_64; + /** \relates Arch */ extern const Arch Arch_athlon; + /** \relates Arch */ extern const Arch Arch_i686; + /** \relates Arch */ extern const Arch Arch_i586; + /** \relates Arch */ extern const Arch Arch_i486; + /** \relates Arch */ extern const Arch Arch_i386; + /** \relates Arch */ extern const Arch Arch_s390x; + /** \relates Arch */ extern const Arch Arch_s390; + /** \relates Arch */ extern const Arch Arch_ppc64; + /** \relates Arch */ extern const Arch Arch_ppc; + /** \relates Arch */ extern const Arch Arch_ia64; //@} @@ -86,31 +100,35 @@ namespace zypp /////////////////////////////////////////////////////////////////// - //@{ - /** \relates Arch */ + /** \relates Arch stream output. */ inline std::ostream & operator<<( std::ostream & str, const Arch & obj ) { return str << obj.asString(); } - + /** \name Comparison based on string value. */ + //@{ + /** \relates Arch */ inline bool operator==( const Arch & lhs, const Arch & rhs ) { return lhs.asString() == rhs.asString(); } + /** \relates Arch */ inline bool operator==( const Arch & lhs, const std::string & rhs ) { return lhs.asString() == rhs; } + /** \relates Arch */ inline bool operator==( const std::string & lhs, const Arch & rhs ) { return lhs == rhs.asString(); } - + /** \relates Arch */ inline bool operator!=( const Arch & lhs, const Arch & rhs ) { return !( lhs == rhs ); } + /** \relates Arch */ inline bool operator!=( const Arch & lhs, const std::string & rhs ) { return !( lhs == rhs ); } + /** \relates Arch */ inline bool operator!=( const std::string & lhs, const Arch & rhs ) { return !( lhs == rhs ); } - //@} /////////////////////////////////////////////////////////////////// @@ -138,7 +156,7 @@ namespace zypp /////////////////////////////////////////////////////////////////// namespace std { ///////////////////////////////////////////////////////////////// - /** \relates Arch Order relation for std::container classes. */ + /** \relates Arch Default order for std::container based on string value.*/ template<> inline bool less::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const { return lhs.asString() < rhs.asString(); } diff --git a/zypp/Edition.cc b/zypp/Edition.cc index 8fa1914..2078ba4 100644 --- a/zypp/Edition.cc +++ b/zypp/Edition.cc @@ -69,6 +69,10 @@ namespace zypp Edition::~Edition() {} + /** \todo Beautyfy */ + std::string Edition::asString() const + { return _pimpl->_version + "-" + _pimpl->_release; } + Edition::epoch_t Edition::epoch() const { return _pimpl->_epoch; } @@ -78,16 +82,11 @@ namespace zypp const std::string & Edition::release() const { return _pimpl->_release; } - /****************************************************************** - ** - ** FUNCTION NAME : operator<< - ** FUNCTION TYPE : std::ostream & - */ - std::ostream & operator<<( std::ostream & str, const Edition & obj ) + /** \todo implement */ + bool Edition::compare( RelOp op, const Edition & lhs, const Edition & rhs ) { - return str << obj.version() << '-' << obj.release(); + return false; } - ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/Edition.h b/zypp/Edition.h index 1ba5894..bea8ab0 100644 --- a/zypp/Edition.h +++ b/zypp/Edition.h @@ -16,6 +16,7 @@ #include #include "zypp/base/PtrTypes.h" + #include "zypp/RelOp.h" /////////////////////////////////////////////////////////////////// @@ -30,16 +31,16 @@ namespace zypp class Edition { public: - /** */ + /** Type of an epoch. */ typedef unsigned epoch_t; public: - /** Default ctor */ + /** Default ctor. */ Edition(); - /** */ + /** Ctor taking \a version_r, \a release_r and optional \a epoch_r */ Edition( const std::string & version_r, const std::string & release_r, - epoch_t epoch = 0 ); + epoch_t epoch_r = 0 ); /** Dtor */ ~Edition(); @@ -51,18 +52,77 @@ namespace zypp /** */ const std::string & release() const; + /** String representation of Edition. */ + std::string asString() const; + + public: + /** Compare Editions by relationam operator \a op. + * \see RelOp. + */ + static bool compare( RelOp op, const Edition & lhs, const Edition & rhs ); + private: /** Hides implementation */ struct Impl; /** Pointer to implementation */ - base::shared_ptr _pimpl; + base::ImplPtr _pimpl; }; /////////////////////////////////////////////////////////////////// - /** \relates Edition Stream output */ - extern std::ostream & operator<<( std::ostream & str, const Edition & obj ); + /** \relates Edition Stream output. */ + inline std::ostream & operator<<( std::ostream & str, const Edition & obj ) + { return str << obj.asString(); } + + /** \name Comaprison based on epoch, version, and release. */ + //@{ + + /** \relates Edition */ + inline bool operator==( const Edition & lhs, const Edition & rhs ) + { return Edition::compare( EQ, lhs, rhs ); } + + /** \relates Edition */ + inline bool operator!=( const Edition & lhs, const Edition & rhs ) + { return Edition::compare( NE, lhs, rhs );; } + + /** \relates Edition */ + inline bool operator<( const Edition & lhs, const Edition & rhs ) + { return Edition::compare( LT, lhs, rhs ); } + + /** \relates Edition */ + inline bool operator<=( const Edition & lhs, const Edition & rhs ) + { return Edition::compare( LE, lhs, rhs ); } + + /** \relates Edition */ + inline bool operator>( const Edition & lhs, const Edition & rhs ) + { return Edition::compare( GT, lhs, rhs ); } + + /** \relates Edition */ + inline bool operator>=( const Edition & lhs, const Edition & rhs ) + { return Edition::compare( GE, lhs, rhs ); } + + /** \relates Edition */ + inline int compare( const Edition & lhs, const Edition & rhs ) + { return lhs == rhs ? 0 : ( lhs < rhs ? -1 : 1 ); } + + //@} ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////// +namespace std +{ ///////////////////////////////////////////////////////////////// + /** \relates Edition Default order for std::container based on string value.*/ + template<> + inline bool less::operator()( const zypp::Edition & lhs, const zypp::Edition & rhs ) const + { return lhs.asString() < rhs.asString(); } + /** \relates Edition Equality for std::container classes based on string value. */ + template<> + inline bool equal_to::operator()( const zypp::Edition & lhs, const zypp::Edition & rhs ) const + { return lhs.asString() == rhs.asString(); } + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// + #endif // ZYPP_EDITION_H diff --git a/zypp/RelOp.h b/zypp/RelOp.h index daae2ff..39220ae 100644 --- a/zypp/RelOp.h +++ b/zypp/RelOp.h @@ -16,6 +16,7 @@ namespace zypp { ///////////////////////////////////////////////////////////////// + /** Relational operators. */ enum RelOp { ANY, EQ, NE, LT, LE, GT, GE, NONE }; ///////////////////////////////////////////////////////////////// diff --git a/zypp/base/PtrTypes.h b/zypp/base/PtrTypes.h index ea38208..48b3819 100644 --- a/zypp/base/PtrTypes.h +++ b/zypp/base/PtrTypes.h @@ -84,6 +84,11 @@ namespace zypp : _dptr( dptr ) {} + explicit + ImplPtr( _Ptr dptr ) + : _dptr( dptr ) + {} + _D & operator*() { return *_dptr; } const _D & operator*() const { return *_dptr; }; _D * operator->() { return _dptr.get(); } @@ -93,7 +98,7 @@ namespace zypp _D * unconst() const { return _dptr.get(); } - private: + _Ptr _dptr; }; /////////////////////////////////////////////////////////////////// @@ -125,7 +130,7 @@ namespace zypp _D * unconst() const { return _dptr; } - private: + _P * _dptr; }; ///////////////////////////////////////////////////////////////// -- 2.7.4