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"
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////
35 { /////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////
39 // CLASS NAME : Solvable
41 /** A \ref Solvable object within the sat \ref Pool.
43 * \note Unfortunately libsatsolver combines the objects kind and
44 * name in a single identifier \c "pattern:kde_multimedia",
45 * \b except for packages and source packes. They are not prefixed
46 * by any kind string. Instead the architecture is abused to store
47 * \c "src" and \c "nosrc" values.
49 * \ref Solvable will hide this inconsistency by treating source
50 * packages as an own kind of solvable and map their arch to
55 class Solvable : protected detail::PoolMember,
56 private base::SafeBool<Solvable>
59 /** Default ctor creates \ref nosolvable.*/
61 : _id( detail::noSolvableId ) {}
63 /** \ref PoolImpl ctor. */
64 explicit Solvable( detail::SolvableIdType id_r )
68 /** Represents no \ref Solvable. */
69 static const Solvable nosolvable;
71 /** Evaluate \ref Solvable in a boolean context (\c != \c nosolvable). */
72 using base::SafeBool<Solvable>::operator bool_type;
74 /** Return whether this \ref Solvable belongs to the system repo. */
75 bool isSystem() const;
77 /** The \ref Repository this \ref Solvable belongs to. */
83 * returns the string attribute value for \ref attr
84 * or an empty string if it does not exists.
86 std::string lookupStrAttribute( const SolvAttr &attr ) const;
89 * returns the numeric attribute value for \ref attr
90 * or 0 if it does not exists.
92 unsigned lookupNumAttribute( const SolvAttr &attr ) const;
95 * returns the media location: media number in \ref medianr,
96 * file name as return value. The file name is possibly prepended
97 * with a subdirectory.
99 std::string lookupLocation(unsigned &medianr) const;
103 * This is the solvables \ref name, \b except for packages and
104 * source packes, prefixed by it's \ref kind.
106 IdString ident() const;
108 ResKind kind() const;
109 /** Test whether a Solvable is of a certain \ref ResKind. */
110 bool isKind( const ResKind & kind_r ) const;
112 std::string name() const;
113 Edition edition() const;
116 IdString vendor() const;
120 /** \name Access to the \ref Solvable dependencies.
122 * \note Prerequires are a subset of requires.
125 Capabilities operator[]( Dep which_r ) const;
127 Capabilities provides() const;
128 Capabilities requires() const;
129 Capabilities conflicts() const;
130 Capabilities obsoletes() const;
131 Capabilities recommends() const;
132 Capabilities suggests() const;
133 Capabilities freshens() const;
134 Capabilities enhances() const;
135 Capabilities supplements() const;
136 Capabilities prerequires() const;
140 /** Return next Solvable in \ref Pool (or \ref nosolvable). */
141 Solvable nextInPool() const;
142 /** Return next Solvable in \ref Repo (or \ref nosolvable). */
143 Solvable nextInRepo() const;
146 /** Expert backdoor. */
147 ::_Solvable * get() const;
148 /** Expert backdoor. */
149 detail::SolvableIdType id() const { return _id; }
151 friend base::SafeBool<Solvable>::operator bool_type() const;
152 bool boolTest() const { return get(); }
154 detail::SolvableIdType _id;
156 ///////////////////////////////////////////////////////////////////
158 /** \relates Solvable Stream output */
159 std::ostream & operator<<( std::ostream & str, const Solvable & obj );
161 /** \relates Solvable More verbose stream output including dependencies */
162 std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
164 /** \relates Solvable */
165 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
166 { return lhs.get() == rhs.get(); }
168 /** \relates Solvable */
169 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
170 { return lhs.get() != rhs.get(); }
172 /** \relates Solvable */
173 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
174 { return lhs.get() < rhs.get(); }
176 ///////////////////////////////////////////////////////////////////
178 { /////////////////////////////////////////////////////////////////
179 ///////////////////////////////////////////////////////////////////
181 // CLASS NAME : SolvableIterator
184 class SolvableIterator : public boost::iterator_adaptor<
185 SolvableIterator // Derived
186 , ::_Solvable* // Base
188 , boost::single_pass_traversal_tag // CategoryOrTraversal
189 , Solvable // Reference
194 : SolvableIterator::iterator_adaptor_( 0 )
197 explicit SolvableIterator( const Solvable & val_r )
198 : SolvableIterator::iterator_adaptor_( 0 )
199 { assignVal( val_r ); }
201 explicit SolvableIterator( SolvableIdType id_r )
202 : SolvableIterator::iterator_adaptor_( 0 )
203 { assignVal( Solvable( id_r ) ); }
206 friend class boost::iterator_core_access;
209 { assignVal( _val.nextInPool() ); }
211 Solvable dereference() const
214 void assignVal( const Solvable & val_r )
215 { _val = val_r; base_reference() = _val.get(); }
219 ///////////////////////////////////////////////////////////////////
220 /////////////////////////////////////////////////////////////////
221 } // namespace detail
222 ///////////////////////////////////////////////////////////////////
224 /////////////////////////////////////////////////////////////////
226 ///////////////////////////////////////////////////////////////////
228 /** \relates sat::Solvable Test whether a \ref sat::Solvable is of a certain Kind. */
230 inline bool isKind( const sat::Solvable & solvable_r )
231 { return solvable_r.isKind( ResTraits<_Res>::kind ); }
233 /////////////////////////////////////////////////////////////////
235 ///////////////////////////////////////////////////////////////////
236 #endif // ZYPP_SAT_SOLVABLE_H