Added comparison operators to Edition interfacae.
authorMichael Andres <ma@suse.de>
Tue, 22 Nov 2005 12:45:39 +0000 (12:45 +0000)
committerMichael Andres <ma@suse.de>
Tue, 22 Nov 2005 12:45:39 +0000 (12:45 +0000)
zypp/Arch.h
zypp/Edition.cc
zypp/Edition.h
zypp/RelOp.h
zypp/base/PtrTypes.h

index c86b0a1..f4b1d7c 100644 (file)
@@ -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<zypp::Arch>::operator()( const zypp::Arch & lhs, const zypp::Arch & rhs ) const
     { return lhs.asString() < rhs.asString(); }
index 8fa1914..2078ba4 100644 (file)
@@ -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
 ///////////////////////////////////////////////////////////////////
index 1ba5894..bea8ab0 100644 (file)
@@ -16,6 +16,7 @@
 #include <string>
 
 #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<Impl> _pimpl;
+    base::ImplPtr<Impl> _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<zypp::Edition>::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<zypp::Edition>::operator()( const zypp::Edition & lhs, const zypp::Edition & rhs ) const
+    { return lhs.asString() == rhs.asString(); }
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+
 #endif // ZYPP_EDITION_H
index daae2ff..39220ae 100644 (file)
@@ -16,6 +16,7 @@
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
+  /** Relational operators. */
   enum RelOp { ANY, EQ, NE, LT, LE, GT, GE, NONE };
 
   /////////////////////////////////////////////////////////////////
index ea38208..48b3819 100644 (file)
@@ -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;
       };
     /////////////////////////////////////////////////////////////////