prepare namespace callback
[platform/upstream/libzypp.git] / zypp / sat / Solvable.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Solvable.h
10  *
11 */
12 #ifndef ZYPP_SAT_SOLVABLE_H
13 #define ZYPP_SAT_SOLVABLE_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/SafeBool.h"
18
19 #include "zypp/sat/detail/PoolMember.h"
20 #include "zypp/sat/SolvAttr.h"
21
22 #include "zypp/ResTraits.h"
23 #include "zypp/IdString.h"
24 #include "zypp/Edition.h"
25 #include "zypp/Arch.h"
26 #include "zypp/Dep.h"
27 #include "zypp/Capabilities.h"
28 #include "zypp/Capability.h"
29
30 ///////////////////////////////////////////////////////////////////
31 namespace zypp
32 { /////////////////////////////////////////////////////////////////
33   ///////////////////////////////////////////////////////////////////
34   namespace sat
35   { /////////////////////////////////////////////////////////////////
36
37     ///////////////////////////////////////////////////////////////////
38     //
39     //  CLASS NAME : Solvable
40     //
41     /** A \ref Solvable object within the sat \ref Pool.
42      *
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.
48      *
49      * \ref Solvable will hide this inconsistency by treating source
50      * packages as an own kind of solvable and map their arch to
51      * \ref Arch_noarch.
52      *
53      *
54      */
55     class Solvable : protected detail::PoolMember,
56                      private base::SafeBool<Solvable>
57     {
58       public:
59         /** Default ctor creates \ref nosolvable.*/
60         Solvable()
61         : _id( detail::noSolvableId ) {}
62
63         /** \ref PoolImpl ctor. */
64         explicit Solvable( detail::SolvableIdType id_r )
65         : _id( id_r ) {}
66
67       public:
68         /** Represents no \ref Solvable. */
69         static const Solvable nosolvable;
70
71         /** Evaluate \ref Solvable in a boolean context (\c != \c nosolvable). */
72         using base::SafeBool<Solvable>::operator bool_type;
73
74         /** Return whether this \ref Solvable belongs to the system repo. */
75         bool isSystem() const;
76
77         /** The \ref Repository this \ref Solvable belongs to. */
78         Repo repo() const;
79
80       public:
81
82         /**
83          * returns the string attribute value for \ref attr
84          * or an empty string if it does not exists.
85          */
86         std::string lookupStrAttribute( const SolvAttr &attr ) const;
87
88         /**
89          * returns the numeric attribute value for \ref attr
90          * or 0 if it does not exists.
91          */
92         unsigned lookupNumAttribute( const SolvAttr &attr ) const;
93
94         /**
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.
98          */
99         std::string lookupLocation(unsigned &medianr) const;
100
101       public:
102         /** The identifier.
103          * This is the solvables \ref name, \b except for packages and
104          * source packes, prefixed by it's \ref kind.
105          */
106         IdString     ident()    const;
107
108         ResKind      kind()     const;
109         /** Test whether a Solvable is of a certain \ref ResKind. */
110         bool         isKind( const ResKind & kind_r ) const;
111
112         std::string  name()     const;
113         Edition      edition()  const;
114         Arch         arch()     const;
115
116         IdString     vendor()   const;
117
118       public:
119
120         /** \name Access to the \ref Solvable dependencies.
121          *
122          * \note Prerequires are a subset of requires.
123          */
124         //@{
125         Capabilities operator[]( Dep which_r ) const;
126
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;
137         //@}
138
139       public:
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;
144
145       public:
146         /** Expert backdoor. */
147         ::_Solvable * get() const;
148         /** Expert backdoor. */
149         detail::SolvableIdType id() const { return _id; }
150       private:
151         friend base::SafeBool<Solvable>::operator bool_type() const;
152         bool boolTest() const { return get(); }
153       private:
154         detail::SolvableIdType _id;
155     };
156     ///////////////////////////////////////////////////////////////////
157
158     /** \relates Solvable Stream output */
159     std::ostream & operator<<( std::ostream & str, const Solvable & obj );
160
161     /** \relates Solvable More verbose stream output including dependencies */
162     std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
163
164     /** \relates Solvable */
165     inline bool operator==( const Solvable & lhs, const Solvable & rhs )
166     { return lhs.get() == rhs.get(); }
167
168     /** \relates Solvable */
169     inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
170     { return lhs.get() != rhs.get(); }
171
172     /** \relates Solvable */
173     inline bool operator<( const Solvable & lhs, const Solvable & rhs )
174     { return lhs.get() < rhs.get(); }
175
176     ///////////////////////////////////////////////////////////////////
177     namespace detail
178     { /////////////////////////////////////////////////////////////////
179       ///////////////////////////////////////////////////////////////////
180       //
181       //        CLASS NAME : SolvableIterator
182       //
183       /** */
184       class SolvableIterator : public boost::iterator_adaptor<
185           SolvableIterator                   // Derived
186           , ::_Solvable*                     // Base
187           , const Solvable                   // Value
188           , boost::forward_traversal_tag     // CategoryOrTraversal
189           , const Solvable                   // Reference
190           >
191       {
192         public:
193           SolvableIterator()
194           : SolvableIterator::iterator_adaptor_( 0 )
195           {}
196
197           explicit SolvableIterator( const Solvable & val_r )
198           : SolvableIterator::iterator_adaptor_( 0 )
199           { assignVal( val_r ); }
200
201           explicit SolvableIterator( SolvableIdType id_r )
202           : SolvableIterator::iterator_adaptor_( 0 )
203           { assignVal( Solvable( id_r ) ); }
204
205         private:
206           friend class boost::iterator_core_access;
207
208           Solvable dereference() const
209           { return _val; }
210
211           void increment()
212           { assignVal( _val.nextInPool() ); }
213
214         private:
215           void assignVal( const Solvable & val_r )
216           { _val = val_r; base_reference() = _val.get(); }
217
218           Solvable _val;
219       };
220       ///////////////////////////////////////////////////////////////////
221       /////////////////////////////////////////////////////////////////
222     } // namespace detail
223     ///////////////////////////////////////////////////////////////////
224
225    /////////////////////////////////////////////////////////////////
226   } // namespace sat
227   ///////////////////////////////////////////////////////////////////
228
229   /** \relates sat::Solvable Test whether a \ref sat::Solvable is of a certain Kind. */
230   template<class _Res>
231   inline bool isKind( const sat::Solvable & solvable_r )
232   { return solvable_r.isKind( ResTraits<_Res>::kind ); }
233
234   /////////////////////////////////////////////////////////////////
235 } // namespace zypp
236 ///////////////////////////////////////////////////////////////////
237 #endif // ZYPP_SAT_SOLVABLE_H