Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / Capability.h
index b9f5fca..6471fe7 100644 (file)
 
 #include <iosfwd>
 
-#include "zypp/base/SafeBool.h"
-#include "zypp/base/Deprecated.h"
-
+#include "zypp/APIConfig.h"
 #include "zypp/sat/detail/PoolMember.h"
 
 #include "zypp/IdString.h"
 #include "zypp/Edition.h"
 #include "zypp/Rel.h"
 #include "zypp/ResTraits.h"
-
+#include "zypp/ResolverNamespace.h"
 #include "zypp/CapMatch.h"
 
 ///////////////////////////////////////////////////////////////////
@@ -34,7 +32,7 @@ namespace zypp
   class CapDetail;
   class Arch;
 
-  typedef std::tr1::unordered_set<Capability> CapabilitySet;
+  typedef std::unordered_set<Capability> CapabilitySet;
 
   ///////////////////////////////////////////////////////////////////
   //
@@ -45,20 +43,20 @@ namespace zypp
    * A Capability: <tt>"name[.arch] [op edition]"</tt>
    *
    * If a certain \ref ResKind is specified upon construction, the
-   * capabilities name part is prefixed accordingly. If no \ref ResKind
-   * is specified, it's assumed you refer to a package or the name is
-   * already prefixed:
+   * capabilities name part is prefixed, unless it already conatins a
+   * well known kind spec. If no \ref ResKind is specified, it's assumed
+   * you refer to a package or the name is already prefixed:
    * \code
    * Capability( "foo" )                   ==> 'foo'
    * Capability( "foo", ResKind::package ) ==> 'foo'
    * Capability( "foo", ResKind::pattern ) ==> 'pattern:foo'
    * Capability( "pattern:foo" )           ==> 'pattern:foo'
-     * // avoid this:
-   * Capability( "pattern:foo", ResKind::pattern ) ==> 'pattern:pattern:foo'
+   * // in doubt an explicit name prefix wins:
+   * Capability( "pattern:foo", ResKind::package ) ==> 'pattern:foo'
+   * Capability( "package:foo", ResKind::pattern ) ==> 'foo'
    * \endcode
    */
-  class Capability: protected sat::detail::PoolMember,
-                    private base::SafeBool<Capability>
+  class Capability: protected sat::detail::PoolMember
   {
     public:
       enum CtorFlag { PARSED, UNPARSED };
@@ -70,7 +68,7 @@ namespace zypp
       /** Ctor from id. */
       explicit Capability( sat::detail::IdType id_r ) : _id( id_r ) {}
 
-      /** \name Ctors parsing a Capability: <tt>"name[.arch] [op edition]"</tt>
+      /** \name Ctors parsing a Capability: <tt>"name[.arch] [op edition]"</tt> or <tt>( arch, "name [op edition]")</tt>
       */
       //@{
       /** Ctor from string.
@@ -81,12 +79,22 @@ namespace zypp
       explicit Capability( const char * str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
       /** \overload */
       explicit Capability( const std::string & str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
-      /** \overload Convenience for parsed (name only) packages. */
+      /** \overload Explicitly specify the \c arch. */
+      Capability( const Arch & arch_r, const char * str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
+      /** \overload Explicitly specify the \c arch. */
+      Capability( const Arch & arch_r, const std::string & str_r, const ResKind & prefix_r = ResKind(), CtorFlag flag_r = UNPARSED );
+
+      /** \overload Convenience for parsed (name only, no <tt>"[op edition]</tt>) packages: <tt>Capability( "glibc", PARSED ); */
       Capability( const char * str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
       /** \overload */
       Capability( const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
+      /** \overload Explicitly specify the \c arch. */
+      Capability( const Arch & arch_r, const char * str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
+      /** \overload */
+      Capability( const Arch & arch_r, const std::string & str_r, CtorFlag flag_r, const ResKind & prefix_r = ResKind() );
       //@}
 
+
       /** \name Ctors parsing a broken down Capability: <tt>( "name[.arch]", op, edition )</tt>
       */
       //@{
@@ -115,6 +123,15 @@ namespace zypp
       Capability( const Arch & arch_r, const std::string & name_r, Rel op_r, const Edition & ed_r, const ResKind & prefix_r = ResKind() );
       //@}
 
+      /** \name Ctor creating a namespace: capability.
+       * An empty \a value_r (std::string or IdString) will also be mapped to IdString::Null,
+       * creating a namespace: capability which in most contexts matches all members of this namespace.
+       */
+      //@{
+      Capability( ResolverNamespace namespace_r, IdString value_r = IdString::Null );
+      Capability( ResolverNamespace namespace_r, const char * value_r )                : Capability( namespace_r, IdString(value_r) ) {}
+      Capability( ResolverNamespace namespace_r, const std::string & value_r ) : Capability( namespace_r, IdString(value_r) ) {}
+      //@}
     public:
       /** No or Null \ref Capability ( Id \c 0 ). */
       static const Capability Null;
@@ -123,10 +140,10 @@ namespace zypp
       static const Capability Empty;
 
     public:
-#ifndef SWIG // Swig treats it as syntax error
       /** Evaluate in a boolean context <tt>( ! empty() )</tt>. */
-      using base::SafeBool<Capability>::operator bool_type;
-#endif
+      explicit operator bool() const
+      { return ! empty(); }
+
       /** Whether the \ref Capability is empty.
        * This is true for \ref Null and \ref Empty.
        */
@@ -200,6 +217,37 @@ namespace zypp
       static bool isInterestingFileSpec( const std::string & name_r ) { return isInterestingFileSpec( name_r.c_str() ); }
       static bool isInterestingFileSpec( const char * name_r );
 
+      /** \ref Capability parser also guessing \c "libzypp-1.2.3-4.5.x86_64" formats.
+       *
+       * The argument might be in the form \c "libzypp-devel-1.2.3.x86_64".
+       * Passed to the Capability ctor, this would correctly be parsed as name
+       * capability, because actually the edition part had to be separated by a
+       * \c '=', and the architecture had to be appended to the name.
+       * So this is how it actually had to look like: \c "libzypp-devel.x86_64=1.2.3"
+       *
+       * Obviously we have to guess if, and where to split name and edition. In
+       * fact \c "devel" could also be the version and \c "1.2.3" would be the
+       * release then.
+       *
+       * Assuming this Capability should be provided by some package in
+       * the \ref ResPool, we check this. If unprovided, we substitute the last,
+       * (or one but last) \c '-' by a \c '='. If the name part (without version)
+       * of the resulting Capability matches a package name (not provides!) in
+       * the \ref ResPool, this Capability is returned.
+       *
+       * Otherwise we return the Capability originally created from
+       * \a str_r.
+       *
+       * \note: As this method will access the global pool, the returned
+       * result depends on the pools content.
+       */
+      static Capability guessPackageSpec( const std::string & str_r );
+      /** \overload Taking an additional bool indicating whether \c str_r made
+       * a valid \ref Capability (\c true) or the result was was guessed by
+       * rewiting a \c '-' to \c '='. (\c false).
+       */
+      static Capability guessPackageSpec( const std::string & str_r, bool & rewrote_r );
+
     public:
       /** Expert backdoor. */
       sat::detail::IdType id() const
@@ -208,11 +256,6 @@ namespace zypp
       /** Match two Capabilities */
       static CapMatch _doMatch( sat::detail::IdType lhs,  sat::detail::IdType rhs );
     private:
-#ifndef SWIG // Swig treats it as syntax error
-      friend base::SafeBool<Capability>::operator bool_type() const;
-#endif
-      bool boolTest() const { return ! empty(); }
-    private:
       sat::detail::IdType _id;
   };
   ///////////////////////////////////////////////////////////////////
@@ -263,7 +306,7 @@ namespace zypp
         EXPRESSION = 0x04
       };
 
-      /** Enum values corresponding with libsatsolver defines.
+      /** Enum values corresponding with libsolv defines.
        * \note MPL check in PoolImpl.cc
       */
       enum CapRel