Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / Resolvable.h
index 4430b6c..a27a5cb 100644 (file)
 #include "zypp/base/NonCopyable.h"
 #include "zypp/base/PtrTypes.h"
 
-#include "zypp/sat/SolvableType.h"
+#include "zypp/sat/Solvable.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
-{
+{ /////////////////////////////////////////////////////////////////
+
   class PoolItem;
+
   ///////////////////////////////////////////////////////////////////
-  /// \class Resolvable
-  /// \brief Base for resolvable objects
-  ///
-  /// \note \ref Resolvable is a SolvableType, which provides direct
-  /// access to many of the underlying sat::Solvables properties.
-  /// Don't add common properties here, but in \ref sat::Solvable
-  /// and extend \ref sat::SolvableType.
-  ///
-  /// In most cases you want to retrieve the common properties directly
-  /// from a \ref PoolItem or \ref sat::Solvable. Construction from and
-  /// explicit conversion to sat::Solvable are supported. Next goal is
-  /// to get rid of the smart pointer hierarchy. A Resolvable is actually
-  /// an unsigned and derived classes contain no data, so it makes little
-  /// sense to wrap this into ReferenceCounted smart pointer.
-  ///
-  /// \todo Merge with ResObject
-  /// \todo Get rid of refcout/smart_prt bloat, as this type is actually IdBased (i.e. sizeof(unsigned))
-  ///////////////////////////////////////////////////////////////////
-  class Resolvable : public sat::SolvableType<Resolvable>,
+  //
+  //   CLASS NAME : Resolvable
+  //
+  /** Interface base for resolvable objects (identification and dependencies).
+   * \todo Merge with ResObject
+  */
+  class Resolvable : protected zypp::sat::Solvable,    // Note: gcc bug #52841 prohibits using just sat::Solvable
                      public base::ReferenceCounted, private base::NonCopyable
   {
     friend std::ostream & operator<<( std::ostream & str, const Resolvable & obj );
@@ -59,9 +49,91 @@ namespace zypp
     typedef TraitsType::constPtrType constPtr;
 
   public:
-    /** This is a \ref sat::SolvableType. */
-    explicit operator sat::Solvable() const
-    { return _solvable; }
+    /** Whether this represents an installed solvable. */
+    bool isSystem() const
+    { return sat::Solvable::isSystem(); }
+
+    /** \copydoc sat::Solvable::onSystemByUser() */
+    bool onSystemByUser() const
+    { return sat::Solvable::onSystemByUser(); }
+
+    IdString ident() const
+    { return sat::Solvable::ident(); }
+
+    ResKind kind() const
+    { return sat::Solvable::kind(); }
+
+    bool isKind( const ResKind & kind_r ) const
+    { return sat::Solvable::isKind( kind_r ); }
+
+    template<class _Res>
+    bool isKind() const
+    { return sat::Solvable::isKind<_Res>(); }
+
+    std::string name() const
+    { return sat::Solvable::name(); }
+
+    Edition edition() const
+    { return sat::Solvable::edition(); }
+
+    Arch arch() const
+    { return sat::Solvable::arch(); }
+
+    /** Whether different versions of this package can be installed at the same time.
+     * Per default \c false. \see also \ref ZConfig::multiversion.
+     */
+    bool multiversionInstall() const
+    { return sat::Solvable::multiversionInstall(); }
+
+    using sat::Solvable::asString;
+    using sat::Solvable::asUserString;
+
+    /** \name Dependencies. */
+    //@{
+    /** Select by Dep. */
+    Capabilities dep( Dep which_r ) const
+    { return operator[]( which_r ); }
+
+    Capabilities operator[]( Dep which_r ) const
+    { return sat::Solvable::operator[]( which_r ); }
+
+    Capabilities provides()    const
+    { return sat::Solvable::provides(); }
+
+    Capabilities requires()    const
+    { return sat::Solvable::requires(); }
+
+    Capabilities conflicts()   const
+    { return sat::Solvable::conflicts(); }
+
+    Capabilities obsoletes()   const
+    { return sat::Solvable::obsoletes(); }
+
+    Capabilities recommends()  const
+    { return sat::Solvable::recommends(); }
+
+    Capabilities suggests()    const
+    { return sat::Solvable::suggests(); }
+
+    Capabilities enhances()    const
+    { return sat::Solvable::enhances(); }
+
+    Capabilities supplements() const
+    { return sat::Solvable::supplements(); }
+
+    Capabilities prerequires() const
+    { return sat::Solvable::prerequires(); }
+
+    CapabilitySet providesNamespace( const std::string & namespace_r ) const
+    { return sat::Solvable::providesNamespace( namespace_r ); }
+
+    CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const
+    { return sat::Solvable::valuesOfNamespace( namespace_r ); }
+    //@}
+
+  public:
+    /** Access the corresponding \ref sat:::Solvable. */
+    const sat::Solvable & satSolvable() const { return *this; }
 
     /** Access the corresponding \ref PoolItem. */
     PoolItem poolItem() const;
@@ -73,9 +145,6 @@ namespace zypp
     virtual ~Resolvable();
     /** Helper for stream output */
     virtual std::ostream & dumpOn( std::ostream & str ) const;
-
-  private:
-    sat::Solvable _solvable;
  };
  ///////////////////////////////////////////////////////////////////
 
@@ -87,90 +156,102 @@ namespace zypp
  inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
  { return dumpOn( str, obj.satSolvable() ); }
 
- /** Test whether a Resolvable::Ptr is of a certain Kind.
-  * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
-  * of the specified Kind.
-  * \relates Resolvable
-  * \code
-  * isKind<Package>(resPtr);
-  * \endcode
 /** Test whether a Resolvable::Ptr is of a certain Kind.
+   * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
+   * of the specified Kind.
+   * \relates Resolvable
+   * \code
+   * isKind<Package>(resPtr);
+   * \endcode
   */
template<class TRes>
- inline bool isKind( const Resolvable::constPtr & p )
{ return p && p->isKind<TRes>(); }
-
- // Specialization for Resolvable: Always true.
- template<>
- inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
- { return !!p; }
-
- // Specialization for ResObject: Always true.
- template<>
- inline bool isKind<ResObject>( const Resolvable::constPtr & p )
- { return !!p; }
-
-
- /** Convert Resolvable::Ptr into Ptr of a certain Kind.
-  * \return \c NULL iff \a p is \c NULL or points to a Resolvable
-  * not of the specified Kind.
-  * \relates Resolvable
-  * \code
-  * asKind<Package>(resPtr);
-  * \endcode
 template<class _Res>
   inline bool isKind( const Resolvable::constPtr & p )
   { return p && p->kind() == ResTraits<_Res>::kind; }
+
 // Specialization for Resolvable: Always true.
 template<>
   inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
   { return !!p; }
+
 // Specialization for ResObject: Always true.
 template<>
   inline bool isKind<ResObject>( const Resolvable::constPtr & p )
   { return !!p; }
+
+
 /** Convert Resolvable::Ptr into Ptr of a certain Kind.
+   * \return \c NULL iff \a p is \c NULL or points to a Resolvable
+   * not of the specified Kind.
+   * \relates Resolvable
+   * \code
+   * asKind<Package>(resPtr);
+   * \endcode
   */
template<class TRes>
inline typename ResTraits<TRes>::PtrType asKind( const Resolvable::Ptr & p )
{ return dynamic_pointer_cast<TRes>(p); }
 template<class _Res>
   inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
   { return dynamic_pointer_cast<_Res>(p); }
 
template<class TRes>
inline typename ResTraits<TRes>::constPtrType asKind( const Resolvable::constPtr & p )
{ return dynamic_pointer_cast<const TRes>(p); }
 template<class _Res>
   inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
   { return dynamic_pointer_cast<const _Res>(p); }
 
   ///////////////////////////////////////////////////////////////////
 
-  /** \relates Resolvable Compare Resolvable::constPtr according to \a kind and \a name.
-   * \deprecated Get rid of refcout/smart_prt bloat, use
-   */
-  inline int compareByN( const Resolvable::constPtr & lhs, const Resolvable::constPtr & rhs )
+  /** \relates Resolvable Compare Resolvable::constPtr according to
+   *  \a kind and \a name.
+  */
+  inline int compareByN( const Resolvable::constPtr & lhs,
+                         const Resolvable::constPtr & rhs )
   {
-    int ret = 0;
-    if ( lhs != rhs )
-    {
-      if ( lhs && rhs )
-       ret = compareByN( *lhs, *rhs );
-      else
-       ret = lhs ? 1 : -1;
-    }
-    return ret;
+    if ( lhs == rhs )
+      return 0;
+    if ( ! (lhs && rhs) )
+      return lhs ? 1 : -1;
+    int res = 0;
+    if ( (res = lhs->kind().compare( rhs->kind() )) )
+      return res;
+    return lhs->name().compare( rhs->name() );
   }
 
-  /** \relates Resolvable Compare according to \a kind, \a name and \a edition. */
-  inline int compareByNVR( const Resolvable::constPtr & lhs, const Resolvable::constPtr & rhs )
+  /** \relates Resolvable Compare Resolvable::constPtr according to
+   *  \a kind, \a name and \a edition(compare!).
+  */
+  inline int compareByNVR( const Resolvable::constPtr & lhs,
+                           const Resolvable::constPtr & rhs )
   {
-    int ret = 0;
-    if ( lhs != rhs )
-    {
-      if ( lhs && rhs )
-       ret = compareByNVR( *lhs, *rhs );
-      else
-       ret = lhs ? 1 : -1;
-    }
-    return ret;
+    if ( lhs == rhs )
+      return 0;
+    if ( ! (lhs && rhs) )
+      return lhs ? 1 : -1;
+    int res = 0;
+    if ( (res = lhs->kind().compare( rhs->kind() )) )
+      return res;
+    if ( (res = lhs->name().compare( rhs->name() )) )
+      return res;
+    return lhs->edition().compare( rhs->edition() );
   }
 
-  /** \relates Resolvable Compare Resolvable::constPtr according to \a kind, \a name, \a edition and \a arch. */
-  inline int compareByNVRA( const Resolvable::constPtr & lhs, const Resolvable::constPtr & rhs )
+  /** \relates Resolvable Compare Resolvable::constPtr according to
+   *  \a kind, \a name, \a edition(compare!) and \a arch.
+  */
+  inline int compareByNVRA( const Resolvable::constPtr & lhs,
+                            const Resolvable::constPtr & rhs )
   {
-    int ret = 0;
-    if ( lhs != rhs )
-    {
-      if ( lhs && rhs )
-       ret = compareByNVRA( *lhs, *rhs );
-      else
-       ret = lhs ? 1 : -1;
-    }
-    return ret;
+    if ( lhs == rhs )
+      return 0;
+    if ( ! (lhs && rhs) )
+      return lhs ? 1 : -1;
+    int res = 0;
+    if ( (res = lhs->kind().compare( rhs->kind() )) )
+      return res;
+    if ( (res = lhs->name().compare( rhs->name() )) )
+      return res;
+    if ( (res = lhs->edition().compare( rhs->edition() )) )
+      return res;
+    return lhs->arch().compare( rhs->arch() );
   }
+
+  /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
 #endif // ZYPP_RESOLVABLE_H