1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Solvable.cc
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/Gettext.h"
16 #include "zypp/base/Exception.h"
18 #include "zypp/sat/detail/PoolImpl.h"
19 #include "zypp/sat/IdStr.h"
20 #include "zypp/sat/Solvable.h"
21 #include "zypp/sat/Repo.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
32 const Solvable Solvable::nosolvable;
34 /////////////////////////////////////////////////////////////////
36 ::_Solvable * Solvable::get() const
37 { return myPool().getSolvable( _id ); }
39 #define NO_SOLVABLE_RETURN( VAL ) \
40 ::_Solvable * _solvable( get() ); \
41 if ( ! _solvable ) return VAL
43 Solvable Solvable::nextInPool() const
44 { return Solvable( myPool().getNextId( _id ) ); }
46 Solvable Solvable::nextInRepo() const
48 NO_SOLVABLE_RETURN( nosolvable );
49 for ( detail::SolvableIdType next = _id+1; next < unsigned(_solvable->repo->end); ++next )
51 ::_Solvable * nextS( myPool().getSolvable( next ) );
52 if ( nextS && nextS->repo == _solvable->repo )
54 return Solvable( next );
60 Repo Solvable::repo() const
62 NO_SOLVABLE_RETURN( Repo::norepo );
63 return Repo( _solvable->repo );
66 bool Solvable::isSystem() const
67 { return repo().isSystemRepo(); }
69 NameId Solvable::name() const
71 NO_SOLVABLE_RETURN( NameId() );
72 return NameId( _solvable->name ); }
74 EvrId Solvable::evr() const
76 NO_SOLVABLE_RETURN( EvrId() );
77 return EvrId( _solvable->evr );
80 ArchId Solvable::arch() const
82 NO_SOLVABLE_RETURN( ArchId() );
83 return ArchId( _solvable->arch );
86 VendorId Solvable::vendor() const
88 NO_SOLVABLE_RETURN( VendorId() );
89 return VendorId( _solvable->vendor );
92 Capabilities Solvable::operator[]( Dep which_r ) const
94 NO_SOLVABLE_RETURN( Capabilities() );
96 switch( which_r.inSwitch() )
98 case Dep::PROVIDES_e: offs = _solvable->provides; break;
99 case Dep::REQUIRES_e: offs = _solvable->requires; break;
100 case Dep::CONFLICTS_e: offs = _solvable->conflicts; break;
101 case Dep::OBSOLETES_e: offs = _solvable->obsoletes; break;
102 case Dep::RECOMMENDS_e: offs = _solvable->recommends; break;
103 case Dep::SUGGESTS_e: offs = _solvable->suggests; break;
104 case Dep::FRESHENS_e: offs = _solvable->freshens; break;
105 case Dep::ENHANCES_e: offs = _solvable->enhances; break;
106 case Dep::SUPPLEMENTS_e: offs = _solvable->supplements; break;
108 case Dep::PREREQUIRES_e:
109 // prerequires are a subset of requires
110 if ( (offs = _solvable->requires) )
111 return Capabilities( _solvable->repo->idarraydata + offs, detail::solvablePrereqMarker );
113 return Capabilities();
117 return offs ? Capabilities( _solvable->repo->idarraydata + offs )
121 /******************************************************************
123 ** FUNCTION NAME : operator<<
124 ** FUNCTION TYPE : std::ostream &
126 std::ostream & operator<<( std::ostream & str, const Solvable & obj )
129 return str << "sat::solvable()";
131 return str << "sat::solvable(" << obj.id() << "|"
132 << obj.name() << '-' << obj.evr() << '.' << obj.arch() << "){"
133 << obj.repo().name() << "}";
136 /******************************************************************
138 ** FUNCTION NAME : dumpOn
139 ** FUNCTION TYPE : std::ostream &
141 std::ostream & dumpOn( std::ostream & str, const Solvable & obj )
146 #define OUTS(X) if ( ! obj[Dep::X].empty() ) str << endl << " " #X " " << obj[Dep::X]
162 /////////////////////////////////////////////////////////////////
164 ///////////////////////////////////////////////////////////////////
165 /////////////////////////////////////////////////////////////////
167 ///////////////////////////////////////////////////////////////////