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/Capabilities.h"
21 #include "zypp/sat/Capability.h"
22 #include "zypp/sat/IdStr.h"
24 #include "zypp/ResTraits.h"
25 #include "zypp/Edition.h"
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////
33 { /////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////
37 // CLASS NAME : Solvable
39 /** A \ref Solvable object within the sat \ref Pool.
41 * \note Unfortunately libsatsolver combines the objects kind and
42 * name in a single identifier \c "pattern:kde_multimedia",
43 * \b except for packages and source packes. They are not prefixed
44 * by any kind string. Instead the architecture is abused to store
45 * \c "src" and \c "nosrc" values.
47 * \ref Solvable will hide this inconsistency by treating source
48 * packages as an own kind of solvable and map their arch to
51 class Solvable : protected detail::PoolMember,
52 private base::SafeBool<Solvable>
55 /** Default ctor creates \ref nosolvable.*/
57 : _id( detail::noSolvableId ) {}
59 /** \ref PoolImpl ctor. */
60 explicit Solvable( detail::SolvableIdType id_r )
64 /** Represents no \ref Solvable. */
65 static const Solvable nosolvable;
67 /** Evaluate \ref Solvable in a boolean context (\c != \c nosolvable). */
68 using base::SafeBool<Solvable>::operator bool_type;
70 /** Return whether this \ref Solvable belongs to the system repo. */
71 bool isSystem() const;
73 /** The \ref Repository this \ref Solvable belongs to. */
79 std::string name() const;
80 EvrId edition() const;
82 VendorId vendor() const;
86 /** \name Access to the \ref Solvable dependencies.
88 * \note Prerequires are a subset of requires.
91 Capabilities operator[]( Dep which_r ) const;
93 Capabilities provides() const;
94 Capabilities requires() const;
95 Capabilities conflicts() const;
96 Capabilities obsoletes() const;
97 Capabilities recommends() const;
98 Capabilities suggests() const;
99 Capabilities freshens() const;
100 Capabilities enhances() const;
101 Capabilities supplements() const;
102 Capabilities prerequires() const;
107 /** Return next Solvable in \ref Pool (or \ref nosolvable). */
108 Solvable nextInPool() const;
109 /** Return next Solvable in \ref Repo (or \ref nosolvable). */
110 Solvable nextInRepo() const;
113 /** Expert backdoor. */
114 ::_Solvable * get() const;
115 /** Expert backdoor. */
116 detail::SolvableIdType id() const { return _id; }
118 friend base::SafeBool<Solvable>::operator bool_type() const;
119 bool boolTest() const { return get(); }
121 detail::SolvableIdType _id;
122 mutable ResKind _kind; // lazy init
124 ///////////////////////////////////////////////////////////////////
126 /** \relates Solvable Stream output */
127 std::ostream & operator<<( std::ostream & str, const Solvable & obj );
129 /** \relates Solvable More verbose stream output including dependencies */
130 std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
132 /** \relates Solvable */
133 inline bool operator==( const Solvable & lhs, const Solvable & rhs )
134 { return lhs.get() == rhs.get(); }
136 /** \relates Solvable */
137 inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
138 { return lhs.get() != rhs.get(); }
140 /** \relates Solvable */
141 inline bool operator<( const Solvable & lhs, const Solvable & rhs )
142 { return lhs.get() < rhs.get(); }
144 ///////////////////////////////////////////////////////////////////
146 { /////////////////////////////////////////////////////////////////
147 ///////////////////////////////////////////////////////////////////
149 // CLASS NAME : SolvableIterator
152 class SolvableIterator : public boost::iterator_adaptor<
153 SolvableIterator // Derived
154 , ::_Solvable* // Base
156 , boost::single_pass_traversal_tag // CategoryOrTraversal
157 , Solvable // Reference
162 : SolvableIterator::iterator_adaptor_( 0 )
165 explicit SolvableIterator( const Solvable & val_r )
166 : SolvableIterator::iterator_adaptor_( 0 )
167 { assignVal( val_r ); }
169 explicit SolvableIterator( SolvableIdType id_r )
170 : SolvableIterator::iterator_adaptor_( 0 )
171 { assignVal( Solvable( id_r ) ); }
174 friend class boost::iterator_core_access;
177 { assignVal( _val.nextInPool() ); }
179 Solvable dereference() const
182 void assignVal( const Solvable & val_r )
183 { _val = val_r; base_reference() = _val.get(); }
187 ///////////////////////////////////////////////////////////////////
188 /////////////////////////////////////////////////////////////////
189 } // namespace detail
190 ///////////////////////////////////////////////////////////////////
192 /////////////////////////////////////////////////////////////////
194 ///////////////////////////////////////////////////////////////////
195 /////////////////////////////////////////////////////////////////
197 ///////////////////////////////////////////////////////////////////
198 #endif // ZYPP_SAT_SOLVABLE_H