1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Solvable.h
12 #ifndef ZYPP_SAT_SOLVABLE_H
13 #define ZYPP_SAT_SOLVABLE_H
17 #include "zypp/base/SafeBool.h"
19 #include "zypp/sat/detail/PoolMember.h"
20 #include "zypp/sat/SolvAttr.h"
22 #include "zypp/ResTraits.h"
23 #include "zypp/IdString.h"
24 #include "zypp/Edition.h"
25 #include "zypp/Arch.h"
27 #include "zypp/Capabilities.h"
28 #include "zypp/Capability.h"
29 #include "zypp/Locale.h"
31 ///////////////////////////////////////////////////////////////////
33 { /////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////
36 { /////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////
40 // CLASS NAME : Solvable
42 /** A \ref Solvable object within the sat \ref Pool.
44 * \note Unfortunately libsatsolver combines the objects kind and
45 * name in a single identifier \c "pattern:kde_multimedia",
46 * \b except for packages and source packes. They are not prefixed
47 * by any kind string. Instead the architecture is abused to store
48 * \c "src" and \c "nosrc" values.
50 * \ref Solvable will hide this inconsistency by treating source
51 * packages as an own kind of solvable and map their arch to
56 class Solvable : protected detail::PoolMember,
57 private base::SafeBool<Solvable>
60 /** Default ctor creates \ref nosolvable.*/
62 : _id( detail::noSolvableId ) {}
64 /** \ref PoolImpl ctor. */
65 explicit Solvable( detail::SolvableIdType id_r )
69 /** Represents no \ref Solvable. */
70 static const Solvable nosolvable;
72 /** Evaluate \ref Solvable in a boolean context (\c != \c nosolvable). */
73 using base::SafeBool<Solvable>::operator bool_type;
75 /** Return whether this \ref Solvable belongs to the system repo. */
76 bool isSystem() const;
78 /** The \ref Repository this \ref Solvable belongs to. */
84 * returns the string attribute value for \ref attr
85 * or an empty string if it does not exists.
87 std::string lookupStrAttribute( const SolvAttr &attr ) const;
90 * returns the numeric attribute value for \ref attr
91 * or 0 if it does not exists.
93 unsigned lookupNumAttribute( const SolvAttr &attr ) const;
96 * returns the media location: media number in \ref medianr,
97 * file name as return value. The file name is possibly prepended
98 * with a subdirectory.
100 std::string lookupLocation(unsigned &medianr) const;
105 bool lookupBoolAttribute( const SolvAttr &attr ) const;
109 * This is the solvables \ref name, \b except for packages and
110 * source packes, prefixed by it's \ref kind.
112 IdString ident() const;
114 ResKind kind() const;
115 /** Test whether a Solvable is of a certain \ref ResKind. */
116 bool isKind( const ResKind & kind_r ) const;
118 std::string name() const;
119 Edition edition() const;
122 IdString vendor() const;
126 /** \name Access to the \ref Solvable dependencies.
128 * \note Prerequires are a subset of requires.
131 Capabilities operator[]( Dep which_r ) const;
133 Capabilities provides() const;
134 Capabilities requires() const;
135 Capabilities conflicts() const;
136 Capabilities obsoletes() const;
137 Capabilities recommends() const;
138 Capabilities suggests() const;
139 Capabilities freshens() const;
140 Capabilities enhances() const;
141 Capabilities supplements() const;
142 Capabilities prerequires() const;
146 /** \name Locale support. */
148 /** Whether this \c Solvable claims to support locales. */
149 bool supportsLocales() const;
150 /** Whether this \c Solvable supports a specific \ref Locale. */
151 bool supportsLocale( const Locale & locale_r ) const;
152 /** Whether this \c Solvable supports at least one of the specified locales. */
153 bool supportsLocale( const LocaleSet & locales_r ) const;
154 /** Whether this \c Solvable supports at least one requested locale.
155 * \see \ref Pool::setRequestedLocales
157 bool supportsRequestedLocales() const;
158 /** Return the supported locales via locales_r. */
159 void getSupportedLocales( LocaleSet & locales_r ) const;
161 LocaleSet getSupportedLocales() const
162 { LocaleSet ret; getSupportedLocales( ret ); return ret; }
166 /** Return next Solvable in \ref Pool (or \ref nosolvable). */
167 Solvable nextInPool() const;
168 /** Return next Solvable in \ref Repo (or \ref nosolvable). */
169 Solvable nextInRepo() const;
172 /** Expert backdoor. */
173 ::_Solvable * get() const;
174 /** Expert backdoor. */
175 detail::SolvableIdType id() const { return _id; }
177 friend base::SafeBool<Solvable>::operator bool_type() const;
178 bool boolTest() const { return get(); }
180 detail::SolvableIdType _id;
182 ///////////////////////////////////////////////////////////////////
184 /** \relates Solvable Stream output */
185 std::ostream & operator<<( std::ostream & str, const Solvable & obj );
187 /** \relates Solvable More verbose stream output including dependencies */
188 std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
190 /** \relates Solvable */
191 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
192 { return lhs.get() == rhs.get(); }
194 /** \relates Solvable */
195 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
196 { return lhs.get() != rhs.get(); }
198 /** \relates Solvable */
199 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
200 { return lhs.get() < rhs.get(); }
202 ///////////////////////////////////////////////////////////////////
204 { /////////////////////////////////////////////////////////////////
205 ///////////////////////////////////////////////////////////////////
207 // CLASS NAME : SolvableIterator
210 class SolvableIterator : public boost::iterator_adaptor<
211 SolvableIterator // Derived
212 , ::_Solvable* // Base
213 , const Solvable // Value
214 , boost::forward_traversal_tag // CategoryOrTraversal
215 , const Solvable // Reference
220 : SolvableIterator::iterator_adaptor_( 0 )
223 explicit SolvableIterator( const Solvable & val_r )
224 : SolvableIterator::iterator_adaptor_( 0 )
225 { assignVal( val_r ); }
227 explicit SolvableIterator( SolvableIdType id_r )
228 : SolvableIterator::iterator_adaptor_( 0 )
229 { assignVal( Solvable( id_r ) ); }
232 friend class boost::iterator_core_access;
234 Solvable dereference() const
238 { assignVal( _val.nextInPool() ); }
241 void assignVal( const Solvable & val_r )
242 { _val = val_r; base_reference() = _val.get(); }
246 ///////////////////////////////////////////////////////////////////
247 /////////////////////////////////////////////////////////////////
248 } // namespace detail
249 ///////////////////////////////////////////////////////////////////
251 /////////////////////////////////////////////////////////////////
253 ///////////////////////////////////////////////////////////////////
255 /** \relates sat::Solvable Test whether a \ref sat::Solvable is of a certain Kind. */
257 inline bool isKind( const sat::Solvable & solvable_r )
258 { return solvable_r.isKind( ResTraits<_Res>::kind ); }
260 /////////////////////////////////////////////////////////////////
262 ///////////////////////////////////////////////////////////////////
263 #endif // ZYPP_SAT_SOLVABLE_H