Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / sat / Solvable.h
index 07e39be..2113b42 100644 (file)
@@ -14,8 +14,6 @@
 
 #include <iosfwd>
 
-#include "zypp/base/SafeBool.h"
-
 #include "zypp/sat/detail/PoolMember.h"
 #include "zypp/sat/SolvAttr.h"
 #include "zypp/ResTraits.h"
@@ -44,7 +42,7 @@ namespace zypp
     //
     /** A \ref Solvable object within the sat \ref Pool.
      *
-     * \note Unfortunately libsatsolver combines the objects kind and
+     * \note Unfortunately libsolv combines the objects kind and
      * name in a single identifier \c "pattern:kde_multimedia",
      * \b except for packages and source packes. They are not prefixed
      * by any kind string. Instead the architecture is abused to store
@@ -54,8 +52,7 @@ namespace zypp
      * packages as an own kind of solvable and map their arch to
      * \ref Arch_noarch.
      */
-    class Solvable : protected detail::PoolMember,
-                     private base::SafeBool<Solvable>
+    class Solvable : protected detail::PoolMember
     {
       public:
         typedef sat::detail::SolvableIdType IdType;
@@ -74,13 +71,21 @@ namespace zypp
         static const Solvable noSolvable;
 
         /** Evaluate \ref Solvable in a boolean context (\c != \c noSolvable). */
-        using base::SafeBool<Solvable>::operator bool_type;
+        explicit operator bool() const
+        { return get(); }
 
         /** Return whether this \ref Solvable belongs to the system repo.
          * \note This includes the otherwise hidden systemSolvable.
-        */
+        */
         bool isSystem() const;
 
+       /** Whether this is known to be installed on behalf of a user request.
+        * \note This is a hint guessed by evaluating an available install history.
+        * Returns \c false for non-system (uninstalled) solvables, or if no history
+        * is available.
+        */
+       bool onSystemByUser() const;
+
         /** The \ref Repository this \ref Solvable belongs to. */
         Repository repository() const;
 
@@ -98,10 +103,10 @@ namespace zypp
         std::string lookupStrAttribute( const SolvAttr & attr ) const;
         /** \overload Trying to look up a translated string attribute.
          *
-         * Returns the translation for \c lang_r (\b no fallback locales).
+         * Returns the translation for \c lang_r.
          *
          * Passing an empty \ref Locale will return the string for the
-         * current default locale (\see \ref ZConfig::defaultTextLocale),
+         * current default locale (\see \ref ZConfig::TextLocale),
          * \b considering all fallback locales.
          *
          * Returns an empty string if no translation is available.
@@ -112,7 +117,7 @@ namespace zypp
          * returns the numeric attribute value for \ref attr
          * or 0 if it does not exists.
          */
-        unsigned lookupNumAttribute( const SolvAttr & attr ) const;
+        unsigned long long lookupNumAttribute( const SolvAttr & attr ) const;
 
         /**
          * returns the boolean attribute value for \ref attr
@@ -147,8 +152,19 @@ namespace zypp
         IdString     ident()    const;
 
         ResKind      kind()     const;
-        /** Test whether a Solvable is of a certain \ref ResKind. */
-        bool         isKind( const ResKind & kind_r ) const;
+        /** Test whether a Solvable is of a certain \ref ResKind.
+        * The test is far cheaper than actually retriveing and
+         * comparing the \ref kind.
+        */
+        bool isKind( const ResKind & kind_r ) const;
+        /** \overload */
+        template<class _Res>
+        bool isKind() const
+        { return isKind( resKind<_Res>() ); }
+        /** \overload Extend the test to a range of \ref ResKind. */
+        template<class _Iterator>
+        bool isKind( _Iterator begin, _Iterator end )
+        { for_( it, begin, end ) if ( isKind( *it ) ) return true; return false; }
 
         std::string  name()     const;
         Edition      edition()  const;
@@ -156,7 +172,33 @@ namespace zypp
 
         IdString     vendor()   const;
 
-      public:
+        /** 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;
+
+        /** String representation <tt>"ident-edition.arch"</tt> or \c "noSolvable"
+         * \code
+         *   product:openSUSE-11.1.x86_64
+         *   autoyast2-2.16.19-0.1.src
+         *   noSolvable
+         * \endcode
+        */
+        std::string asString() const;
+
+       /** String representation <tt>"ident-edition.arch(repo)"</tt> or \c "noSolvable" */
+        std::string asUserString() const;
+
+        /** Test whether two Solvables have the same content.
+         * Basically the same name, edition, arch, vendor and buildtime.
+         */
+        bool identical( Solvable rhs ) const;
+
+        /** Test for same name-version-release.arch */
+        bool sameNVRA( Solvable rhs ) const
+        { return( ident() == rhs.ident() && edition() == rhs.edition() && arch() == rhs.arch() ); }
+
+     public:
 
         /** \name Access to the \ref Solvable dependencies.
          *
@@ -171,17 +213,22 @@ namespace zypp
         Capabilities obsoletes()   const;
         Capabilities recommends()  const;
         Capabilities suggests()    const;
-        Capabilities freshens()    const;
         Capabilities enhances()    const;
         Capabilities supplements() const;
         Capabilities prerequires() const;
-        //@}
 
-      public:
-        /** Returns true if the solvable is satisfied */
-        bool isSatisfied() const;
-        /** Returns true if the solvable is satisfied */
-        bool isBroken() const { return !isSatisfied(); }
+        /** Return the namespaced provides <tt>'namespace([value])[ op edition]'</tt> of this Solvable. */
+        CapabilitySet providesNamespace( const std::string & namespace_r ) const;
+
+        /** Return <tt>'value[ op edition]'</tt> for namespaced provides <tt>'namespace(value)[ op edition]'</tt>.
+         * Similar to \ref providesNamespace, but the namespace is stripped from the
+         * dependencies. This is convenient if the namespace denotes packages that
+         * should be looked up. E.g. the \c weakremover namespace used in a products
+         * release package denotes the packages that were dropped from the distribution.
+         * \see \ref Product::droplist
+         */
+        CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const;
+        //@}
 
       public:
         /** \name Locale support. */
@@ -209,14 +256,37 @@ namespace zypp
         /** Return next Solvable in \ref Repo (or \ref noSolvable). */
         Solvable nextInRepo() const;
 
+        /** Helper that splits an identifier into kind and name or vice versa.
+        * \note In case \c name_r is preceded by a well known kind spec, the
+        * \c kind_r argument is ignored, and kind is derived from name.
+         * \see \ref ident
+         */
+        class SplitIdent
+        {
+          public:
+            SplitIdent() {}
+            SplitIdent( IdString ident_r );
+            SplitIdent( const char * ident_r );
+            SplitIdent( const std::string & ident_r );
+            SplitIdent( ResKind kind_r, IdString name_r );
+            SplitIdent( ResKind kind_r, const C_Str & name_r );
+
+            IdString ident() const { return _ident; }
+            ResKind  kind()  const { return _kind; }
+            IdString name()  const { return _name; }
+
+          private:
+            IdString  _ident;
+            ResKind   _kind;
+            IdString  _name;
+        };
+
       public:
         /** Expert backdoor. */
         ::_Solvable * get() const;
         /** Expert backdoor. */
         IdType id() const { return _id; }
-      private:
-        friend base::SafeBool<Solvable>::operator bool_type() const;
-        bool boolTest() const { return get(); }
+
       private:
         IdType _id;
     };
@@ -228,6 +298,9 @@ namespace zypp
     /** \relates Solvable More verbose stream output including dependencies */
     std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
 
+    /** \relates Solvable XML output */
+    std::ostream & dumpAsXmlOn( std::ostream & str, const Solvable & obj );
+
     /** \relates Solvable */
     inline bool operator==( const Solvable & lhs, const Solvable & rhs )
     { return lhs.get() == rhs.get(); }
@@ -240,6 +313,45 @@ namespace zypp
     inline bool operator<( const Solvable & lhs, const Solvable & rhs )
     { return lhs.get() < rhs.get(); }
 
+    /** \relates Solvable Test for same content. */
+    inline bool identical( Solvable lhs, Solvable rhs )
+    { return lhs.identical( rhs ); }
+
+    /** \relates Solvable Test for same name version release and arch. */
+    inline bool sameNVRA( Solvable lhs, Solvable rhs )
+    { return lhs.sameNVRA( rhs ); }
+
+
+    /** \relates Solvable Compare according to \a kind and \a name. */
+    inline int compareByN( const Solvable & lhs, const Solvable & rhs )
+    {
+      int res = 0;
+      if ( lhs != rhs )
+      {
+       if ( (res = lhs.kind().compare( rhs.kind() )) == 0 )
+         res = lhs.name().compare( rhs.name() );
+      }
+      return res;
+    }
+
+    /** \relates Solvable Compare according to \a kind, \a name and \a edition. */
+    inline int compareByNVR( const Solvable & lhs, const Solvable & rhs )
+    {
+      int res = compareByN( lhs, rhs );
+      if ( res == 0 )
+       res = lhs.edition().compare( rhs.edition() );
+      return res;
+    }
+
+    /** \relates Solvable Compare according to \a kind, \a name, \a edition and \a arch. */
+    inline int compareByNVRA( const Solvable & lhs, const Solvable & rhs )
+    {
+      int res = compareByNVR( lhs, rhs );
+      if ( res == 0 )
+       res = lhs.arch().compare( rhs.arch() );
+      return res;
+    }
+
     ///////////////////////////////////////////////////////////////////
     namespace detail
     { /////////////////////////////////////////////////////////////////
@@ -289,7 +401,7 @@ namespace zypp
     } // namespace detail
     ///////////////////////////////////////////////////////////////////
 
-   /////////////////////////////////////////////////////////////////
+    /////////////////////////////////////////////////////////////////
   } // namespace sat
   ///////////////////////////////////////////////////////////////////
 
@@ -298,7 +410,33 @@ namespace zypp
   inline bool isKind( const sat::Solvable & solvable_r )
   { return solvable_r.isKind( ResTraits<_Res>::kind ); }
 
+  class PoolItem;
+  ///////////////////////////////////////////////////////////////////
+  namespace sat
+  { /////////////////////////////////////////////////////////////////
+    /** To Solvable transform functor.
+     * \relates Solvable
+     * \relates sat::SolvIterMixin
+     */
+    struct asSolvable
+    {
+      typedef Solvable result_type;
+
+      Solvable operator()( Solvable solv_r ) const
+      { return solv_r; }
+
+      Solvable operator()( const PoolItem & pi_r ) const;
+
+      Solvable operator()( const ResObject_constPtr & res_r ) const;
+    };
+    /////////////////////////////////////////////////////////////////
+  } // namespace sat
+  ///////////////////////////////////////////////////////////////////
+
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
+
+ZYPP_DEFINE_ID_HASHABLE( ::zypp::sat::Solvable );
+
 #endif // ZYPP_SAT_SOLVABLE_H