- Changed ResKind implementation to use IdStr.
[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/Capabilities.h"
21 #include "zypp/sat/Capability.h"
22 #include "zypp/sat/IdStr.h"
23
24 #include "zypp/ResTraits.h"
25 #include "zypp/Edition.h"
26 #include "zypp/Dep.h"
27
28 ///////////////////////////////////////////////////////////////////
29 namespace zypp
30 { /////////////////////////////////////////////////////////////////
31   ///////////////////////////////////////////////////////////////////
32   namespace sat
33   { /////////////////////////////////////////////////////////////////
34
35     ///////////////////////////////////////////////////////////////////
36     //
37     //  CLASS NAME : Solvable
38     //
39     /** A \ref Solvable object within the sat \ref Pool.
40      *
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.
46      *
47      * \ref Solvable will hide this inconsistency by treating source
48      * packages as an own kind of solvable and map their arch to
49      * \ref Arch_noarch.
50      */
51     class Solvable : protected detail::PoolMember,
52                      private base::SafeBool<Solvable>
53     {
54       public:
55         /** Default ctor creates \ref nosolvable.*/
56         Solvable()
57         : _id( detail::noSolvableId ) {}
58
59         /** \ref PoolImpl ctor. */
60         explicit Solvable( detail::SolvableIdType id_r )
61         : _id( id_r ) {}
62
63       public:
64         /** Represents no \ref Solvable. */
65         static const Solvable nosolvable;
66
67         /** Evaluate \ref Solvable in a boolean context (\c != \c nosolvable). */
68         using base::SafeBool<Solvable>::operator bool_type;
69
70         /** Return whether this \ref Solvable belongs to the system repo. */
71         bool isSystem() const;
72
73         /** The \ref Repository this \ref Solvable belongs to. */
74         Repo repo() const;
75
76       public:
77         IdStr        ident()   const;
78         ResKind      kind()    const;
79         std::string  name()    const;
80         EvrId        edition() const;
81         ArchId       arch()    const;
82         VendorId     vendor()  const;
83
84       public:
85
86         /** \name Access to the \ref Solvable dependencies.
87          *
88          * \note Prerequires are a subset of requires.
89          */
90         //@{
91         Capabilities operator[]( Dep which_r ) const;
92
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;
103         //@}
104
105
106       public:
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;
111
112       public:
113         /** Expert backdoor. */
114         ::_Solvable * get() const;
115         /** Expert backdoor. */
116         detail::SolvableIdType id() const { return _id; }
117       private:
118         friend base::SafeBool<Solvable>::operator bool_type() const;
119         bool boolTest() const { return get(); }
120       private:
121         detail::SolvableIdType _id;
122         mutable ResKind _kind; // lazy init
123     };
124     ///////////////////////////////////////////////////////////////////
125
126     /** \relates Solvable Stream output */
127     std::ostream & operator<<( std::ostream & str, const Solvable & obj );
128
129     /** \relates Solvable More verbose stream output including dependencies */
130     std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
131
132     /** \relates Solvable */
133     inline bool operator==( const Solvable & lhs, const Solvable & rhs )
134     { return lhs.get() == rhs.get(); }
135
136     /** \relates Solvable */
137     inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
138     { return lhs.get() != rhs.get(); }
139
140     /** \relates Solvable */
141     inline bool operator<( const Solvable & lhs, const Solvable & rhs )
142     { return lhs.get() < rhs.get(); }
143
144     ///////////////////////////////////////////////////////////////////
145     namespace detail
146     { /////////////////////////////////////////////////////////////////
147       ///////////////////////////////////////////////////////////////////
148       //
149       //        CLASS NAME : SolvableIterator
150       //
151       /** */
152       class SolvableIterator : public boost::iterator_adaptor<
153           SolvableIterator                   // Derived
154           , ::_Solvable*                     // Base
155           , Solvable                         // Value
156           , boost::single_pass_traversal_tag // CategoryOrTraversal
157           , Solvable                         // Reference
158           >
159       {
160         public:
161           SolvableIterator()
162           : SolvableIterator::iterator_adaptor_( 0 )
163           {}
164
165           explicit SolvableIterator( const Solvable & val_r )
166           : SolvableIterator::iterator_adaptor_( 0 )
167           { assignVal( val_r ); }
168
169           explicit SolvableIterator( SolvableIdType id_r )
170           : SolvableIterator::iterator_adaptor_( 0 )
171           { assignVal( Solvable( id_r ) ); }
172
173         private:
174           friend class boost::iterator_core_access;
175
176           void increment()
177           { assignVal( _val.nextInPool() ); }
178
179           Solvable dereference() const
180           { return _val; }
181
182           void assignVal( const Solvable & val_r )
183           { _val = val_r; base_reference() = _val.get(); }
184
185           Solvable _val;
186       };
187       ///////////////////////////////////////////////////////////////////
188       /////////////////////////////////////////////////////////////////
189     } // namespace detail
190     ///////////////////////////////////////////////////////////////////
191
192    /////////////////////////////////////////////////////////////////
193   } // namespace sat
194   ///////////////////////////////////////////////////////////////////
195   /////////////////////////////////////////////////////////////////
196 } // namespace zypp
197 ///////////////////////////////////////////////////////////////////
198 #endif // ZYPP_SAT_SOLVABLE_H