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 IdStr Solvable::ident() const
71 NO_SOLVABLE_RETURN( IdStr() );
72 return IdStr( _solvable->name );
75 ResKind Solvable::kind() const
77 NO_SOLVABLE_RETURN( ResKind() );
78 // detect srcpackages by 'arch'
79 switch ( _solvable->arch )
83 return ResKind::srcpackage;
87 const char * ident = IdStr( _solvable->name ).c_str();
88 const char * sep = ::strchr( ident, ':' );
90 // no ':' in package names (hopefully)
92 return ResKind::package;
94 // quick check for well known kinds
99 #define OUTS(K,S) if ( ::strncmp( ident, ResKind::K.c_str(), S ) ) return ResKind::K
101 case 'c': OUTS( patch, 5 ); break;
102 case 'd': OUTS( product, 7 ); break;
103 case 'e': OUTS( selection, 9 ); break;
104 case 'g': OUTS( language, 8 ); break;
105 case 'i': OUTS( script, 6 ); break;
106 case 'k': OUTS( package, 7 ); break;
107 case 'm': OUTS( atom, 4 ); break;
108 case 'p': OUTS( srcpackage, 10 ); break;
109 case 's': OUTS( message, 7 ); break;
110 case 't': OUTS( pattern, 7 );
111 OUTS( system, 6 ); break;
117 return ResKind( std::string( ident, sep-ident ) );
120 std::string Solvable::name() const
122 NO_SOLVABLE_RETURN( std::string() );
123 const char * ident = IdStr( _solvable->name ).c_str();
124 const char * sep = ::strchr( ident, ':' );
125 return( sep ? sep+1 : ident );
128 Edition Solvable::edition() const
130 NO_SOLVABLE_RETURN( Edition() );
131 return Edition( _solvable->evr );
134 ArchId Solvable::arch() const
136 NO_SOLVABLE_RETURN( ArchId() );
137 switch ( _solvable->arch )
141 return ArchId( ARCH_NOARCH );
144 return ArchId( _solvable->arch );
147 VendorId Solvable::vendor() const
149 NO_SOLVABLE_RETURN( VendorId() );
150 return VendorId( _solvable->vendor );
153 Capabilities Solvable::operator[]( Dep which_r ) const
155 NO_SOLVABLE_RETURN( Capabilities() );
157 switch( which_r.inSwitch() )
159 case Dep::PROVIDES_e: offs = _solvable->provides; break;
160 case Dep::REQUIRES_e: offs = _solvable->requires; break;
161 case Dep::CONFLICTS_e: offs = _solvable->conflicts; break;
162 case Dep::OBSOLETES_e: offs = _solvable->obsoletes; break;
163 case Dep::RECOMMENDS_e: offs = _solvable->recommends; break;
164 case Dep::SUGGESTS_e: offs = _solvable->suggests; break;
165 case Dep::FRESHENS_e: offs = _solvable->freshens; break;
166 case Dep::ENHANCES_e: offs = _solvable->enhances; break;
167 case Dep::SUPPLEMENTS_e: offs = _solvable->supplements; break;
169 case Dep::PREREQUIRES_e:
170 // prerequires are a subset of requires
171 if ( (offs = _solvable->requires) )
172 return Capabilities( _solvable->repo->idarraydata + offs, detail::solvablePrereqMarker );
174 return Capabilities();
178 return offs ? Capabilities( _solvable->repo->idarraydata + offs )
182 /******************************************************************
184 ** FUNCTION NAME : operator<<
185 ** FUNCTION TYPE : std::ostream &
187 std::ostream & operator<<( std::ostream & str, const Solvable & obj )
190 return str << "sat::solvable()";
192 return str << "sat::solvable(" << obj.id() << "|"
193 << obj.kind() << ':' << obj.name() << '-' << obj.edition() << '.' << obj.arch() << "){"
194 << obj.repo().name() << "}";
197 /******************************************************************
199 ** FUNCTION NAME : dumpOn
200 ** FUNCTION TYPE : std::ostream &
202 std::ostream & dumpOn( std::ostream & str, const Solvable & obj )
207 #define OUTS(X) if ( ! obj[Dep::X].empty() ) str << endl << " " #X " " << obj[Dep::X]
223 /////////////////////////////////////////////////////////////////
225 ///////////////////////////////////////////////////////////////////
226 /////////////////////////////////////////////////////////////////
228 ///////////////////////////////////////////////////////////////////