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 int lookupNumAttribute( const SolvAttr &attr ) const;
96 * This is the solvables \ref name, \b except for packages and
97 * source packes, prefixed by it's \ref kind.
99 IdString ident() const;
101 ResKind kind() const;
102 /** Test whether a Solvable is of a certain \ref ResKind. */
103 bool isKind( const ResKind & kind_r ) const;
105 std::string name() const;
106 Edition edition() const;
109 IdString vendor() const;
113 /** \name Access to the \ref Solvable dependencies.
115 * \note Prerequires are a subset of requires.
118 Capabilities operator[]( Dep which_r ) const;
120 Capabilities provides() const;
121 Capabilities requires() const;
122 Capabilities conflicts() const;
123 Capabilities obsoletes() const;
124 Capabilities recommends() const;
125 Capabilities suggests() const;
126 Capabilities freshens() const;
127 Capabilities enhances() const;
128 Capabilities supplements() const;
129 Capabilities prerequires() const;
133 /** Return next Solvable in \ref Pool (or \ref nosolvable). */
134 Solvable nextInPool() const;
135 /** Return next Solvable in \ref Repo (or \ref nosolvable). */
136 Solvable nextInRepo() const;
139 /** Expert backdoor. */
140 ::_Solvable * get() const;
141 /** Expert backdoor. */
142 detail::SolvableIdType id() const { return _id; }
144 friend base::SafeBool<Solvable>::operator bool_type() const;
145 bool boolTest() const { return get(); }
147 detail::SolvableIdType _id;
149 ///////////////////////////////////////////////////////////////////
151 /** \relates Solvable Stream output */
152 std::ostream & operator<<( std::ostream & str, const Solvable & obj );
154 /** \relates Solvable More verbose stream output including dependencies */
155 std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
157 /** \relates Solvable */
158 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
159 { return lhs.get() == rhs.get(); }
161 /** \relates Solvable */
162 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
163 { return lhs.get() != rhs.get(); }
165 /** \relates Solvable */
166 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
167 { return lhs.get() < rhs.get(); }
169 ///////////////////////////////////////////////////////////////////
171 { /////////////////////////////////////////////////////////////////
172 ///////////////////////////////////////////////////////////////////
174 // CLASS NAME : SolvableIterator
177 class SolvableIterator : public boost::iterator_adaptor<
178 SolvableIterator // Derived
179 , ::_Solvable* // Base
181 , boost::single_pass_traversal_tag // CategoryOrTraversal
182 , Solvable // Reference
187 : SolvableIterator::iterator_adaptor_( 0 )
190 explicit SolvableIterator( const Solvable & val_r )
191 : SolvableIterator::iterator_adaptor_( 0 )
192 { assignVal( val_r ); }
194 explicit SolvableIterator( SolvableIdType id_r )
195 : SolvableIterator::iterator_adaptor_( 0 )
196 { assignVal( Solvable( id_r ) ); }
199 friend class boost::iterator_core_access;
202 { assignVal( _val.nextInPool() ); }
204 Solvable dereference() const
207 void assignVal( const Solvable & val_r )
208 { _val = val_r; base_reference() = _val.get(); }
212 ///////////////////////////////////////////////////////////////////
213 /////////////////////////////////////////////////////////////////
214 } // namespace detail
215 ///////////////////////////////////////////////////////////////////
217 /////////////////////////////////////////////////////////////////
219 ///////////////////////////////////////////////////////////////////
221 /** \relates sat::Solvable Test whether a \ref sat::Solvable is of a certain Kind. */
223 inline bool isKind( const sat::Solvable & solvable_r )
224 { return solvable_r.isKind( ResTraits<_Res>::kind ); }
226 /////////////////////////////////////////////////////////////////
228 ///////////////////////////////////////////////////////////////////
229 #endif // ZYPP_SAT_SOLVABLE_H