Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / sat / Solvable.h
index 0e71c5e..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"
@@ -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;
@@ -73,10 +70,9 @@ namespace zypp
         /** Represents no \ref Solvable. */
         static const Solvable noSolvable;
 
-#ifndef SWIG // Swig treats it as syntax error
         /** Evaluate \ref Solvable in a boolean context (\c != \c noSolvable). */
-        using base::SafeBool<Solvable>::operator bool_type;
-#endif
+        explicit operator bool() const
+        { return get(); }
 
         /** Return whether this \ref Solvable belongs to the system repo.
          * \note This includes the otherwise hidden systemSolvable.
@@ -190,6 +186,9 @@ namespace zypp
         */
         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.
          */
@@ -276,14 +275,6 @@ namespace zypp
             ResKind  kind()  const { return _kind; }
             IdString name()  const { return _name; }
 
-           /** Return an idents explicit kind prefix, or \ref ResKind() if none.
-            * Mainly to detect wheter a given ident string is explicitly prefixed
-            * by a known kind (e.g \c pattern:foo or \c package:foo).
-            */
-           static ResKind explicitKind( IdString ident_r )             { return explicitKind( ident_r.c_str() );  }
-           static ResKind explicitKind( const char * ident_r );
-           static ResKind explicitKind( const std::string & ident_r )  { return explicitKind( ident_r.c_str() );  }
-
           private:
             IdString  _ident;
             ResKind   _kind;
@@ -295,11 +286,7 @@ namespace zypp
         ::_Solvable * get() const;
         /** Expert backdoor. */
         IdType id() const { return _id; }
-      private:
-#ifndef SWIG // Swig treats it as syntax error
-        friend base::SafeBool<Solvable>::operator bool_type() const;
-#endif
-        bool boolTest() const { return get(); }
+
       private:
         IdType _id;
     };
@@ -311,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(); }
@@ -331,6 +321,37 @@ namespace zypp
     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
     { /////////////////////////////////////////////////////////////////