- fixed ModaliasCap/HalCap index
authorMichael Andres <ma@suse.de>
Thu, 16 Mar 2006 15:39:57 +0000 (15:39 +0000)
committerMichael Andres <ma@suse.de>
Thu, 16 Mar 2006 15:39:57 +0000 (15:39 +0000)
- fixed ModaliasCap creation in CapFactory
- Added SystemResObject (Resovable of kind 'system' )

zypp/CapFactory.cc
zypp/Makefile.am
zypp/ResTraits.cc
zypp/ResTraits.h
zypp/SystemResObject.cc [new file with mode: 0644]
zypp/SystemResObject.h [new file with mode: 0644]
zypp/capability/HalCap.cc
zypp/capability/ModaliasCap.cc
zypp/detail/ResolvableImpl.cc
zypp/solver/detail/ResolverInfoMisc.cc

index 4dd046c..fa7b9f8 100644 (file)
@@ -287,13 +287,13 @@ namespace zypp
      * \todo Fix incaccuracy.
     */
     static CapabilityImpl::Ptr buildHal( const Resolvable::Kind & refers_r,
-                                              const std::string & name_r,
-                                              Rel op_r = Rel::ANY,
-                                              const std::string & value_r = std::string() )
+                                         const std::string & name_r,
+                                         Rel op_r = Rel::ANY,
+                                         const std::string & value_r = std::string() )
     {
       if ( op_r != Rel::ANY )
        {
-         ZYPP_THROW( Exception("Unsupported kind of Hal Capability") );
+         ZYPP_THROW( Exception("Unsupported kind of Hal Capability '" + op_r.asString() + "'") );
        }
 
       //split:   hal(name) [op string]
@@ -303,11 +303,11 @@ namespace zypp
        {
          // Hal always refers to 'System' kind of Resolvable.
          return usetInsert
-         ( new capability::HalCap( ResTraits<System>::kind,
+         ( new capability::HalCap( ResTraits<SystemResObject>::kind,
                                    what[1].str() ) );
        }
       // otherwise
-      ZYPP_THROW( Exception("Unsupported kind of Hal Capability") );
+      ZYPP_THROW( Exception("Unsupported kind of Hal Capability '" + name_r + "'") );
       return NULL; // make gcc happy
     }
 
@@ -321,13 +321,13 @@ namespace zypp
      * \todo Fix incaccuracy.
     */
     static CapabilityImpl::Ptr buildModalias( const Resolvable::Kind & refers_r,
-                                              const std::string & name_r,
-                                              Rel op_r = Rel::ANY,
-                                              const std::string & value_r = std::string() )
+                                              const std::string & name_r,
+                                              Rel op_r = Rel::ANY,
+                                              const std::string & value_r = std::string() )
     {
       if ( op_r != Rel::ANY )
        {
-         ZYPP_THROW( Exception("Unsupported kind of Modalias Capability") );
+         ZYPP_THROW( Exception("Unsupported kind of Modalias Capability  '" + op_r.asString() + "'") );
        }
 
       //split:   modalias(name) [op string]
@@ -337,11 +337,11 @@ namespace zypp
        {
          // Modalias always refers to 'System' kind of Resolvable.
          return usetInsert
-         ( new capability::ModaliasCap( ResTraits<System>::kind,
-                                   what[1].str() ) );
+         ( new capability::ModaliasCap( ResTraits<SystemResObject>::kind,
+                                         what[1].str() ) );
        }
       // otherwise
-      ZYPP_THROW( Exception("Unsupported kind of Modalias Capability") );
+      ZYPP_THROW( Exception("Unsupported kind of Modalias Capability'" + name_r + "'") );
       return NULL; // make gcc happy
     }
   };
@@ -385,43 +385,44 @@ namespace zypp
        {
          return Capability( Impl::buildHal( refers_r, strval_r ) );
        }
-      else if ( Impl::isFileSpec( strval_r ) )
+      if ( Impl::isModaliasSpec( strval_r ) )
+        {
+          return Capability( Impl::buildModalias( refers_r, strval_r ) );
+        }
+      if ( Impl::isFileSpec( strval_r ) )
         {
           return Capability( Impl::buildFile( refers_r, strval_r ) );
         }
-      else
-       {
-         // strval_r has at least two words which could make 'op edition'?
-         // improve regex!
-         str::regex  rx( "(.*[^ \t])([ \t]+)([^ \t]+)([ \t]+)([^ \t]+)" );
-         str::smatch what;
-         if( str::regex_match( strval_r.begin(), strval_r.end(),what, rx ) )
-           {
-             Rel op;
-             Edition edition;
-             try
-               {
-                 op = Rel(what[3].str());
-                 edition = Edition(what[5].str());
-               }
-             catch ( Exception & excpt )
-               {
-                 // So they don't make valid 'op edition'
-                 ZYPP_CAUGHT( excpt );
-                 DBG << "Trying named cap for: " << strval_r << endl;
-                 // See whether it makes a named cap.
-                 return Capability( Impl::buildNamed( refers_r, strval_r ) );
-               }
-
-             // Valid 'op edition'
-             return Capability ( Impl::buildVersioned( refers_r,
-                                                       what[1].str(), op, edition ) );
-           }
-         //else
-         // not a VersionedCap
-
-         return Capability( Impl::buildNamed( refers_r, strval_r ) );
-       }
+
+      // strval_r has at least two words which could make 'op edition'?
+      // improve regex!
+      str::regex  rx( "(.*[^ \t])([ \t]+)([^ \t]+)([ \t]+)([^ \t]+)" );
+      str::smatch what;
+      if( str::regex_match( strval_r.begin(), strval_r.end(),what, rx ) )
+        {
+          Rel op;
+          Edition edition;
+          try
+            {
+              op = Rel(what[3].str());
+              edition = Edition(what[5].str());
+            }
+          catch ( Exception & excpt )
+            {
+              // So they don't make valid 'op edition'
+              ZYPP_CAUGHT( excpt );
+              DBG << "Trying named cap for: " << strval_r << endl;
+              // See whether it makes a named cap.
+              return Capability( Impl::buildNamed( refers_r, strval_r ) );
+            }
+
+          // Valid 'op edition'
+          return Capability ( Impl::buildVersioned( refers_r,
+                                                    what[1].str(), op, edition ) );
+        }
+      //else
+      // not a VersionedCap
+      return Capability( Impl::buildNamed( refers_r, strval_r ) );
     }
   catch ( Exception & excpt )
     {
@@ -445,6 +446,10 @@ namespace zypp
        {
          return Capability( Impl::buildHal( refers_r, name_r, Rel(op_r), edition_r ) );
        }
+      if ( Impl::isModaliasSpec( name_r ) )
+       {
+         return Capability( Impl::buildModalias( refers_r, name_r, Rel(op_r), edition_r ) );
+       }
       // Try creating Rel and Edition, then parse
       return parse( refers_r, name_r, Rel(op_r), Edition(edition_r) );
     }
@@ -469,8 +474,11 @@ namespace zypp
        {
          return Capability( Impl::buildHal( refers_r, name_r, op_r, edition_r.asString() ) );
        }
-      return Capability
-      ( Impl::buildVersioned( refers_r, name_r, op_r, edition_r ) );
+      if ( Impl::isModaliasSpec( name_r ) )
+       {
+         return Capability( Impl::buildModalias( refers_r, name_r, op_r, edition_r.asString() ) );
+       }
+      return Capability( Impl::buildVersioned( refers_r, name_r, op_r, edition_r ) );
     }
   catch ( Exception & excpt )
     {
index 745f18d..21ce03c 100644 (file)
@@ -35,6 +35,7 @@ pkginclude_HEADERS = NeedAType.h \
        Rel.h           \
        RelCompare.h    \
        ResObject.h     \
+       SystemResObject.h       \
        Resolvable.h    \
        ResTraits.h     \
        ResStatus.h     \
@@ -114,6 +115,7 @@ lib@PACKAGE@_la_SOURCES = \
        Range.cc        \
        Rel.cc          \
        ResObject.cc    \
+       SystemResObject.cc      \
        Resolvable.cc   \
        ResTraits.cc    \
        ResStatus.cc    \
index 235a766..473cbf8 100644 (file)
@@ -36,7 +36,7 @@ namespace zypp
     const ResolvableTraits::KindType ResTraits<Atom>    ::kind( "Atom" );
 
   template<>
-    const ResolvableTraits::KindType ResTraits<System>  ::kind( "System" );
+    const ResolvableTraits::KindType ResTraits<SystemResObject>   ::kind( "System" );
 
   template<>
     const ResolvableTraits::KindType ResTraits<SrcPackage>  ::kind( "SrcPackage" );
index e8abff8..dea2079 100644 (file)
@@ -33,7 +33,7 @@ namespace zypp
   class Message;
   class Language;
 
-  class System;
+  class SystemResObject;
 
   /** Base of ResTraits. Defines the Resolvable::Kind type. */
   struct ResolvableTraits
diff --git a/zypp/SystemResObject.cc b/zypp/SystemResObject.cc
new file mode 100644 (file)
index 0000000..309f7f9
--- /dev/null
@@ -0,0 +1,63 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/SystemResObject.cc
+ *
+*/
+//#include <iostream>
+//#include "zypp/base/Logger.h"
+
+#include "zypp/SystemResObject.h"
+#include "zypp/CapFactory.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   METHOD NAME : SystemResObject::SystemResObject
+  //   METHOD TYPE : Ctor
+  //
+  SystemResObject::SystemResObject( const NVRAD & nvrad_r )
+  : ResObject( TraitsType::kind, nvrad_r )
+  {}
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   METHOD NAME : SystemResObject::~SystemResObject
+  //   METHOD TYPE : Dtor
+  //
+  SystemResObject::~SystemResObject()
+  {}
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   METHOD NAME : SystemResObject::instance()
+  //   METHOD TYPE : SystemResObject::Ptr
+  //
+  SystemResObject::Ptr SystemResObject::instance()
+  {
+    static Ptr _ptr;
+    if ( ! _ptr )
+      {
+        NVRAD dataCollect( "system" );
+        dataCollect[Dep::PROVIDES].insert( CapFactory().halEvalCap() );
+        dataCollect[Dep::PROVIDES].insert( CapFactory().modaliasEvalCap() );
+
+        detail::ResImplTraits<detail::SystemResObjectImplIf>::Ptr sysImpl;
+        _ptr = detail::makeResolvableAndImpl( dataCollect, sysImpl );
+      }
+
+    return _ptr ;
+  }
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/SystemResObject.h b/zypp/SystemResObject.h
new file mode 100644 (file)
index 0000000..6370b5c
--- /dev/null
@@ -0,0 +1,78 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/SystemResObject.h
+ *
+*/
+#ifndef ZYPP_SYSTEMRESOBJECT_H
+#define ZYPP_SYSTEMRESOBJECT_H
+
+#include "zypp/ResObject.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+  class SystemResObject;
+
+  ///////////////////////////////////////////////////////////////////
+  namespace detail
+  { /////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    //  CLASS NAME : SystemResObjectImplIf
+    //
+    /** Abstract SystemResObject implementation interface.
+    */
+    class SystemResObjectImplIf : public ResObjectImplIf
+    {
+    public:
+      typedef SystemResObject ResType;
+    };
+    ///////////////////////////////////////////////////////////////////
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace detail
+  ///////////////////////////////////////////////////////////////////
+
+  ///////////////////////////////////////////////////////////////////
+  //
+  //   CLASS NAME : SystemResObject
+  //
+  /** */
+  class SystemResObject : public ResObject
+  {
+  public:
+    typedef detail::SystemResObjectImplIf Impl;
+    typedef SystemResObject               Self;
+    typedef ResTraits<Self>               TraitsType;
+    typedef TraitsType::PtrType           Ptr;
+    typedef TraitsType::constPtrType      constPtr;
+
+    /** Default SystemResObject instance. */
+    static Ptr instance();
+
+  protected:
+    /** Ctor */
+    SystemResObject( const NVRAD & nvrad_r );
+    /** Dtor */
+    virtual ~SystemResObject();
+
+  private:
+    /** Access implementation */
+    virtual Impl & pimpl() = 0;
+    /** Access implementation */
+    virtual const Impl & pimpl() const = 0;
+  };
+  ///////////////////////////////////////////////////////////////////
+
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SYSTEMRESOBJECT_H
index 257808b..c99af80 100644 (file)
@@ -54,9 +54,7 @@ namespace zypp
 
     std::string HalCap::index() const
     {
-      std::string ret( "hal(" );
-      ret += _name;
-      return ret += ")";
+      return "hal()";
     }
 
     bool HalCap::isEvalCmd() const
index 58febf6..ca79d6a 100644 (file)
@@ -9,6 +9,9 @@
 /** \file zypp/capability/ModaliasCap.cc
  *
 */
+#include <iostream>
+#include "zypp/base/Logger.h"
+
 #include "zypp/capability/ModaliasCap.h"
 #include "zypp/target/modalias/Modalias.h"
 
@@ -54,9 +57,7 @@ namespace zypp
 
     std::string ModaliasCap::index() const
     {
-      std::string ret( "modalias(" );
-      ret += _name;
-      return ret += ")";
+      return "modalias()";
     }
 
     bool ModaliasCap::isEvalCmd() const
index fb2f17d..309716d 100644 (file)
@@ -57,10 +57,11 @@ namespace zypp
 
       bool operator()( const Capability & cap_r ) const
       {
-       if (cap_r.index().substr( 0, 9 ) == "modalias(") {
-           deps[Dep::SUPPLEMENTS].insert( CapFactory().parse( ResTraits<System>::kind, cap_r.index() ) );
-           return true;        // strip from provides
-       }
+       if ( isKind<capability::ModaliasCap>(cap_r) )
+          {
+           deps[Dep::SUPPLEMENTS].insert( cap_r );
+            return true;       // strip from provides
+          }
 
        if (cap_r.index().substr( 0, 7 ) != "locale(")
            return false;
@@ -81,11 +82,6 @@ namespace zypp
                next = provides.size()-1;                       // none left, set next to end-1 (strip trailing ')' )
 
            string loc( provides, pos, next-pos );
-           if (loc.size() < 2
-               || loc.size() > 5)
-           {
-               WAR << "Looks wrong " << cap_r.index() << endl;
-           }
            if (_zypp) _zypp->availableLocale( Locale( loc ) );
            deps[Dep::FRESHENS].insert( f.parse( ResTraits<Language>::kind, loc ) );
            pos = next + 1;
index 874037e..0ab2cca 100644 (file)
@@ -59,7 +59,7 @@ ResolverInfoMisc::dumpOn( std::ostream & os ) const
     switch (_trigger) {
        case ResolverInfoMisc::NONE:            os << "none"; break;
        case ResolverInfoMisc::OBSOLETE:        os << "obsoletes"; break;
-       case ResolverInfoMisc::REQUIRE:         os << "requires"; break;            
+       case ResolverInfoMisc::REQUIRE:         os << "requires"; break;
        case ResolverInfoMisc::CONFLICT:        os << "conflicts"; break;
     }
     os << endl;
@@ -117,7 +117,7 @@ translateResTraits (const Resolvable::Kind & kind)
        // Translator: Notation for atom (part of a patch)
        return _( "atom" );
     }
-    else if (kind == ResTraits<System>::kind) {
+    else if (kind == ResTraits<SystemResObject>::kind) {
        // Translator: Notation for computer system
        return _( "system" );
     }
@@ -567,7 +567,7 @@ ResolverInfoMisc::copy (void) const
     cpy->_other_capability = _other_capability;
     cpy->_action = _action;
     cpy->_trigger = _trigger;
-    
+
     return cpy;
 }