Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / sat / Solvable.cc
index b5f0ede..45d2772 100644 (file)
 #include "zypp/OnMediaLocation.h"
 #include "zypp/ZConfig.h"
 
-#include "zypp/ui/Selectable.h"
-
 using std::endl;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
-{
+{ /////////////////////////////////////////////////////////////////
   ///////////////////////////////////////////////////////////////////
   namespace sat
-  {
-    ///////////////////////////////////////////////////////////////////
+  { /////////////////////////////////////////////////////////////////
+
     namespace
     {
       void _doSplit( IdString & _ident, ResKind & _kind, IdString & _name )
@@ -66,8 +64,7 @@ namespace zypp
        }
        return;
       }
-    } // namespace
-    ///////////////////////////////////////////////////////////////////
+    }
 
     Solvable::SplitIdent::SplitIdent( IdString ident_r )
     : _ident( ident_r )
@@ -92,18 +89,16 @@ namespace zypp
     { _doSplit( _ident, _kind, _name ); }
 
     /////////////////////////////////////////////////////////////////
-    // class Solvable
-    /////////////////////////////////////////////////////////////////
 
     const Solvable Solvable::noSolvable;
 
     /////////////////////////////////////////////////////////////////
 
-    detail::CSolvable * Solvable::get() const
+    ::_Solvable * Solvable::get() const
     { return myPool().getSolvable( _id ); }
 
 #define NO_SOLVABLE_RETURN( VAL ) \
-    detail::CSolvable * _solvable( get() ); \
+    ::_Solvable * _solvable( get() ); \
     if ( ! _solvable ) return VAL
 
     Solvable Solvable::nextInPool() const
@@ -114,7 +109,7 @@ namespace zypp
       NO_SOLVABLE_RETURN( noSolvable );
       for ( detail::SolvableIdType next = _id+1; next < unsigned(_solvable->repo->end); ++next )
       {
-        detail::CSolvable * nextS( myPool().getSolvable( next ) );
+        ::_Solvable * nextS( myPool().getSolvable( next ) );
         if ( nextS && nextS->repo == _solvable->repo )
         {
           return Solvable( next );
@@ -123,6 +118,29 @@ namespace zypp
       return noSolvable;
     }
 
+    Repository Solvable::repository() const
+    {
+      NO_SOLVABLE_RETURN( Repository::noRepository );
+      return Repository( _solvable->repo );
+    }
+
+    bool Solvable::isSystem() const
+    {
+      NO_SOLVABLE_RETURN( _id == detail::systemSolvableId );
+      return myPool().isSystemRepo( _solvable->repo );
+    }
+
+    bool Solvable::onSystemByUser() const
+    {
+      return isSystem() && myPool().isOnSystemByUser( ident() );
+    }
+
+    IdString Solvable::ident() const
+    {
+      NO_SOLVABLE_RETURN( IdString() );
+      return IdString( _solvable->name );
+    }
+
     std::string Solvable::lookupStrAttribute( const SolvAttr & attr ) const
     {
       NO_SOLVABLE_RETURN( std::string() );
@@ -134,14 +152,14 @@ namespace zypp
     {
       NO_SOLVABLE_RETURN( std::string() );
       const char * s = 0;
-      if ( !lang_r )
+      if ( lang_r == Locale::noCode )
       {
         s = ::solvable_lookup_str_poollang( _solvable, attr.id() );
       }
       else
       {
-       for ( Locale l( lang_r ); l; l = l.fallback() )
-         if ( (s = ::solvable_lookup_str_lang( _solvable, attr.id(), l.c_str(), 0 )) )
+       for ( Locale l( lang_r ); l != Locale::noCode; l = l.fallback() )
+         if ( (s = ::solvable_lookup_str_lang( _solvable, attr.id(), l.code().c_str(), 0 )) )
            return s;
          // here: no matching locale, so use default
          s = ::solvable_lookup_str_lang( _solvable, attr.id(), 0, 0 );
@@ -155,12 +173,6 @@ namespace zypp
       return ::solvable_lookup_num( _solvable, attr.id(), 0 );
     }
 
-    unsigned long long Solvable::lookupNumAttribute( const SolvAttr & attr, unsigned long long notfound_r ) const
-    {
-      NO_SOLVABLE_RETURN( notfound_r );
-      return ::solvable_lookup_num( _solvable, attr.id(), notfound_r );
-    }
-
     bool Solvable::lookupBoolAttribute( const SolvAttr & attr ) const
     {
       NO_SOLVABLE_RETURN( false );
@@ -197,22 +209,22 @@ namespace zypp
     {
       inline Pathname lookupDatadirIn( Repository repor_r )
       {
-        static const SolvAttr susetagsDatadir( "susetags:datadir" );
+        static const sat::SolvAttr susetagsDatadir( "susetags:datadir" );
         Pathname ret;
         // First look for repo attribute "susetags:datadir". If not found,
         // look into the solvables as Code11 libsolv placed it there.
-        LookupRepoAttr datadir( susetagsDatadir, repor_r );
+        sat::LookupRepoAttr datadir( susetagsDatadir, repor_r );
         if ( ! datadir.empty() )
           ret = datadir.begin().asString();
         else
         {
-          LookupAttr datadir( susetagsDatadir, repor_r );
+          sat::LookupAttr datadir( susetagsDatadir, repor_r );
           if ( ! datadir.empty() )
             ret = datadir.begin().asString();
         }
         return ret;
       }
-    } // namespace
+    }
     ///////////////////////////////////////////////////////////////////
 
     OnMediaLocation Solvable::lookupLocation() const
@@ -259,14 +271,7 @@ namespace zypp
       return ret;
     }
 
-
-    IdString Solvable::ident() const
-    {
-      NO_SOLVABLE_RETURN( IdString() );
-      return IdString( _solvable->name );
-    }
-
-     ResKind Solvable::kind() const
+    ResKind Solvable::kind() const
     {
       NO_SOLVABLE_RETURN( ResKind() );
       // detect srcpackages by 'arch'
@@ -348,87 +353,38 @@ namespace zypp
       //return ArchId( _solvable->arch );
     }
 
-    IdString Solvable::vendor() const
-    {
-      NO_SOLVABLE_RETURN( IdString() );
-      return IdString( _solvable->vendor );
-    }
-
-   Repository Solvable::repository() const
-    {
-      NO_SOLVABLE_RETURN( Repository::noRepository );
-      return Repository( _solvable->repo );
-    }
-
-    RepoInfo Solvable::repoInfo() const
-    { return repository().info(); }
-
-
-    bool Solvable::isSystem() const
-    {
-      NO_SOLVABLE_RETURN( _id == detail::systemSolvableId );
-      return myPool().isSystemRepo( _solvable->repo );
-    }
-
-    bool Solvable::onSystemByUser() const
-    {
-      return isSystem() && myPool().isOnSystemByUser( ident() );
-    }
-
     bool Solvable::multiversionInstall() const
     {
-      NO_SOLVABLE_RETURN( false );
-      return myPool().isMultiversion( *this );
+      return myPool().isMultiversion( ident() );
     }
 
-    Date Solvable::buildtime() const
-    {
-      NO_SOLVABLE_RETURN( Date() );
-      return Date( lookupNumAttribute( SolvAttr::buildtime ) );
-    }
-
-    Date Solvable::installtime() const
-    {
-      NO_SOLVABLE_RETURN( Date() );
-      return Date( lookupNumAttribute( SolvAttr::installtime ) );
-    }
-
-    std::string Solvable::asString() const
+    IdString Solvable::vendor() const
     {
-      NO_SOLVABLE_RETURN( (_id == detail::systemSolvableId ? "systemSolvable" : "noSolvable") );
-      return str::form( "%s-%s.%s",
-                        IdString( _solvable->name ).c_str(),
-                        IdString( _solvable->evr ).c_str(),
-                        IdString( _solvable->arch ).c_str() );
+      NO_SOLVABLE_RETURN( IdString() );
+      return IdString( _solvable->vendor );
     }
 
-    std::string Solvable::asUserString() const\
+    Capabilities Solvable::operator[]( Dep which_r ) const
     {
-      NO_SOLVABLE_RETURN( (_id == detail::systemSolvableId ? "systemSolvable" : "noSolvable") );
-      return str::form( "%s-%s.%s (%s)",
-                        IdString( _solvable->name ).c_str(),
-                        IdString( _solvable->evr ).c_str(),
-                        IdString( _solvable->arch ).c_str(),
-                        repository().asUserString().c_str() );
+      switch( which_r.inSwitch() )
+      {
+        case Dep::PROVIDES_e:    return provides();    break;
+        case Dep::REQUIRES_e:    return requires();    break;
+        case Dep::CONFLICTS_e:   return conflicts();   break;
+        case Dep::OBSOLETES_e:   return obsoletes();   break;
+        case Dep::RECOMMENDS_e:  return recommends();  break;
+        case Dep::SUGGESTS_e:    return suggests();    break;
+        case Dep::ENHANCES_e:    return enhances();    break;
+        case Dep::SUPPLEMENTS_e: return supplements(); break;
+        case Dep::PREREQUIRES_e: return prerequires(); break;
+      }
+      return Capabilities();
     }
 
-    bool Solvable::identical( const Solvable & rhs ) const
+    inline Capabilities _getCapabilities( detail::IdType * idarraydata_r, ::Offset offs_r )
     {
-      NO_SOLVABLE_RETURN( ! rhs.get() );
-      detail::CSolvable * rhssolvable( rhs.get() );
-      return rhssolvable && ( _solvable == rhssolvable || ::solvable_identical( _solvable, rhssolvable ) );
+      return offs_r ? Capabilities( idarraydata_r + offs_r ) : Capabilities();
     }
-
-    ///////////////////////////////////////////////////////////////////
-    namespace
-    {
-      inline Capabilities _getCapabilities( detail::IdType * idarraydata_r, ::Offset offs_r )
-      {
-       return offs_r ? Capabilities( idarraydata_r + offs_r ) : Capabilities();
-      }
-    } // namespace
-    ///////////////////////////////////////////////////////////////////
-
     Capabilities Solvable::provides() const
     {
       NO_SOLVABLE_RETURN( Capabilities() );
@@ -490,7 +446,7 @@ namespace zypp
           ret.insert( *it );
       }
       return ret;
-    }
+   }
 
     CapabilitySet Solvable::valuesOfNamespace( const std::string & namespace_r ) const
     {
@@ -510,9 +466,36 @@ namespace zypp
       return ret;
     }
 
+
+    std::string Solvable::asString() const
+    {
+      NO_SOLVABLE_RETURN( (_id == detail::systemSolvableId ? "systemSolvable" : "noSolvable") );
+      return str::form( "%s-%s.%s",
+                        IdString( _solvable->name ).c_str(),
+                        IdString( _solvable->evr ).c_str(),
+                        IdString( _solvable->arch ).c_str() );
+    }
+
+    std::string Solvable::asUserString() const\
+    {
+      NO_SOLVABLE_RETURN( (_id == detail::systemSolvableId ? "systemSolvable" : "noSolvable") );
+      return str::form( "%s-%s.%s (%s)",
+                        IdString( _solvable->name ).c_str(),
+                        IdString( _solvable->evr ).c_str(),
+                        IdString( _solvable->arch ).c_str(),
+                        repository().asUserString().c_str() );
+    }
+
+    bool Solvable::identical( Solvable rhs ) const
+    {
+      NO_SOLVABLE_RETURN( ! rhs.get() );
+      ::_Solvable * rhssolvable( rhs.get() );
+      return rhssolvable && ( _solvable == rhssolvable || ::solvable_identical( _solvable, rhssolvable ) );
+    }
+
     ///////////////////////////////////////////////////////////////////
     namespace
-    {
+    { /////////////////////////////////////////////////////////////////
       /** Expand \ref Capability and call \c fnc_r for each namescpace:language
        * dependency. Return #invocations of fnc_r, negative if fnc_r returned
        * false to indicate abort.
@@ -558,7 +541,7 @@ namespace zypp
        * dependency. Return #invocations of fnc_r, negative if fnc_r returned
        * false to indicate abort.
        */
-      inline int invokeOnEachSupportedLocale( Capabilities cap_r, function<bool (Locale)> fnc_r )
+      inline int invokeOnEachSupportedLocale( Capabilities cap_r, function<bool (const Locale &)> fnc_r )
       {
         int cnt = 0;
         for_( cit, cap_r.begin(), cap_r.end() )
@@ -584,8 +567,8 @@ namespace zypp
 
         const LocaleSet & _locales;
       };
-    } // namespace
-    ///////////////////////////////////////////////////////////////////
+
+    /////////////////////////////////////////////////////////////////
 
     bool Solvable::supportsLocales() const
     {
@@ -610,87 +593,17 @@ namespace zypp
     bool Solvable::supportsRequestedLocales() const
     { return supportsLocale( myPool().getRequestedLocales() ); }
 
-    LocaleSet Solvable::getSupportedLocales() const
+    void Solvable::getSupportedLocales( LocaleSet & locales_r ) const
     {
-      LocaleSet ret;
-      invokeOnEachSupportedLocale( supplements(), functor::collector( std::inserter( ret, ret.begin() ) ) );
-      return ret;
+      invokeOnEachSupportedLocale( supplements(),
+                                   functor::Collector( std::inserter( locales_r, locales_r.begin() ) ) );
     }
 
-    CpeId Solvable::cpeId() const
-    {
-      NO_SOLVABLE_RETURN( CpeId() );
-      return CpeId( lookupStrAttribute( SolvAttr::cpeid ), CpeId::noThrow );
-    }
-
-    unsigned Solvable::mediaNr() const
-    {
-      NO_SOLVABLE_RETURN( 0U );
-      return lookupNumAttribute( SolvAttr::medianr );
-    }
-
-    ByteCount Solvable::installSize() const
-    {
-      NO_SOLVABLE_RETURN( ByteCount() );
-      return ByteCount( lookupNumAttribute( SolvAttr::installsize ) );
-    }
-
-    ByteCount Solvable::downloadSize() const
-    {
-      NO_SOLVABLE_RETURN( ByteCount() );
-      return ByteCount( lookupNumAttribute( SolvAttr::downloadsize ) );
-    }
-
-    std::string Solvable::distribution() const
-    {
-      NO_SOLVABLE_RETURN( std::string() );
-      return lookupStrAttribute( SolvAttr::distribution );
-    }
-
-    std::string        Solvable::summary( const Locale & lang_r ) const
-    {
-      NO_SOLVABLE_RETURN( std::string() );
-      return lookupStrAttribute( SolvAttr::summary, lang_r );
-    }
-
-    std::string        Solvable::description( const Locale & lang_r ) const
-    {
-      NO_SOLVABLE_RETURN( std::string() );
-      return lookupStrAttribute( SolvAttr::description, lang_r );
-    }
-
-    std::string        Solvable::insnotify( const Locale & lang_r ) const
-    {
-      NO_SOLVABLE_RETURN( std::string() );
-      return lookupStrAttribute( SolvAttr::insnotify, lang_r );
-    }
-
-    std::string        Solvable::delnotify( const Locale & lang_r ) const
-    {
-      NO_SOLVABLE_RETURN( std::string() );
-      return lookupStrAttribute( SolvAttr::delnotify, lang_r );
-    }
-
-    std::string        Solvable::licenseToConfirm( const Locale & lang_r ) const
-    {
-      NO_SOLVABLE_RETURN( std::string() );
-      std::string ret = lookupStrAttribute( SolvAttr::eula, lang_r );
-      if ( ret.empty() && isKind<Product>() )
-      {
-       const RepoInfo & ri( repoInfo() );
-       if ( ri.needToAcceptLicense() || ! ui::Selectable::get( *this )->hasInstalledObj() )
-         ret = ri.getLicense( lang_r ); // bnc#908976: suppress informal license upon update
-      }
-      return ret;
-    }
-
-    bool Solvable::needToAcceptLicense() const
-    {
-      NO_SOLVABLE_RETURN( false );
-      return ( isKind<Product>() ? repoInfo().needToAcceptLicense() : true );
-    }
-
-
+    /******************************************************************
+    **
+    ** FUNCTION NAME : operator<<
+    ** FUNCTION TYPE : std::ostream &
+    */
     std::ostream & operator<<( std::ostream & str, const Solvable & obj )
     {
       if ( ! obj )
@@ -702,6 +615,11 @@ namespace zypp
           << obj.repository().alias() << ")";
     }
 
+    /******************************************************************
+    **
+    ** FUNCTION NAME : dumpOn
+    ** FUNCTION TYPE : std::ostream &
+    */
     std::ostream & dumpOn( std::ostream & str, const Solvable & obj )
     {
       str << obj;
@@ -734,7 +652,9 @@ namespace zypp
       return str;
     }
 
+    /////////////////////////////////////////////////////////////////
   } // namespace sat
   ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////