- added some locale support to sat::Solvable.
[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 #include "zypp/Locale.h"
30
31 ///////////////////////////////////////////////////////////////////
32 namespace zypp
33 { /////////////////////////////////////////////////////////////////
34   ///////////////////////////////////////////////////////////////////
35   namespace sat
36   { /////////////////////////////////////////////////////////////////
37
38     ///////////////////////////////////////////////////////////////////
39     //
40     //  CLASS NAME : Solvable
41     //
42     /** A \ref Solvable object within the sat \ref Pool.
43      *
44      * \note Unfortunately libsatsolver combines the objects kind and
45      * name in a single identifier \c "pattern:kde_multimedia",
46      * \b except for packages and source packes. They are not prefixed
47      * by any kind string. Instead the architecture is abused to store
48      * \c "src" and \c "nosrc" values.
49      *
50      * \ref Solvable will hide this inconsistency by treating source
51      * packages as an own kind of solvable and map their arch to
52      * \ref Arch_noarch.
53      *
54      *
55      */
56     class Solvable : protected detail::PoolMember,
57                      private base::SafeBool<Solvable>
58     {
59       public:
60         /** Default ctor creates \ref nosolvable.*/
61         Solvable()
62         : _id( detail::noSolvableId ) {}
63
64         /** \ref PoolImpl ctor. */
65         explicit Solvable( detail::SolvableIdType id_r )
66         : _id( id_r ) {}
67
68       public:
69         /** Represents no \ref Solvable. */
70         static const Solvable nosolvable;
71
72         /** Evaluate \ref Solvable in a boolean context (\c != \c nosolvable). */
73         using base::SafeBool<Solvable>::operator bool_type;
74
75         /** Return whether this \ref Solvable belongs to the system repo. */
76         bool isSystem() const;
77
78         /** The \ref Repository this \ref Solvable belongs to. */
79         Repo repo() const;
80
81       public:
82
83         /**
84          * returns the string attribute value for \ref attr
85          * or an empty string if it does not exists.
86          */
87         std::string lookupStrAttribute( const SolvAttr &attr ) const;
88
89         /**
90          * returns the numeric attribute value for \ref attr
91          * or 0 if it does not exists.
92          */
93         unsigned lookupNumAttribute( const SolvAttr &attr ) const;
94
95         /**
96          * returns the media location: media number in \ref medianr,
97          * file name as return value.  The file name is possibly prepended
98          * with a subdirectory.
99          */
100         std::string lookupLocation(unsigned &medianr) const;
101
102         /**
103          *
104          */
105         bool lookupBoolAttribute( const SolvAttr &attr ) const;
106
107       public:
108         /** The identifier.
109          * This is the solvables \ref name, \b except for packages and
110          * source packes, prefixed by it's \ref kind.
111          */
112         IdString     ident()    const;
113
114         ResKind      kind()     const;
115         /** Test whether a Solvable is of a certain \ref ResKind. */
116         bool         isKind( const ResKind & kind_r ) const;
117
118         std::string  name()     const;
119         Edition      edition()  const;
120         Arch         arch()     const;
121
122         IdString     vendor()   const;
123
124       public:
125
126         /** \name Access to the \ref Solvable dependencies.
127          *
128          * \note Prerequires are a subset of requires.
129          */
130         //@{
131         Capabilities operator[]( Dep which_r ) const;
132
133         Capabilities provides()    const;
134         Capabilities requires()    const;
135         Capabilities conflicts()   const;
136         Capabilities obsoletes()   const;
137         Capabilities recommends()  const;
138         Capabilities suggests()    const;
139         Capabilities freshens()    const;
140         Capabilities enhances()    const;
141         Capabilities supplements() const;
142         Capabilities prerequires() const;
143         //@}
144
145       public:
146         /** \name Locale support. */
147         //@{
148         /** Whether this \c Solvable claims to support locales. */
149         bool supportsLocales() const;
150         /** Whether this \c Solvable supports a specific \ref Locale. */
151         bool supportsLocale( const Locale & locale_r ) const;
152         /** Whether this \c Solvable supports at least one of the specified locales. */
153         bool supportsLocale( const LocaleSet & locales_r ) const;
154         /** Whether this \c Solvable supports at least one requested locale.
155          * \see \ref Pool::setRequestedLocales
156         */
157         bool supportsRequestedLocales() const;
158         /** Return the supported locales via locales_r. */
159         void getSupportedLocales( LocaleSet & locales_r ) const;
160         /** \overload */
161         LocaleSet getSupportedLocales() const
162         { LocaleSet ret; getSupportedLocales( ret ); return ret; }
163         //@}
164
165       public:
166         /** Return next Solvable in \ref Pool (or \ref nosolvable). */
167         Solvable nextInPool() const;
168         /** Return next Solvable in \ref Repo (or \ref nosolvable). */
169         Solvable nextInRepo() const;
170
171       public:
172         /** Expert backdoor. */
173         ::_Solvable * get() const;
174         /** Expert backdoor. */
175         detail::SolvableIdType id() const { return _id; }
176       private:
177         friend base::SafeBool<Solvable>::operator bool_type() const;
178         bool boolTest() const { return get(); }
179       private:
180         detail::SolvableIdType _id;
181     };
182     ///////////////////////////////////////////////////////////////////
183
184     /** \relates Solvable Stream output */
185     std::ostream & operator<<( std::ostream & str, const Solvable & obj );
186
187     /** \relates Solvable More verbose stream output including dependencies */
188     std::ostream & dumpOn( std::ostream & str, const Solvable & obj );
189
190     /** \relates Solvable */
191     inline bool operator==( const Solvable & lhs, const Solvable & rhs )
192     { return lhs.get() == rhs.get(); }
193
194     /** \relates Solvable */
195     inline bool operator!=( const Solvable & lhs, const Solvable & rhs )
196     { return lhs.get() != rhs.get(); }
197
198     /** \relates Solvable */
199     inline bool operator<( const Solvable & lhs, const Solvable & rhs )
200     { return lhs.get() < rhs.get(); }
201
202     ///////////////////////////////////////////////////////////////////
203     namespace detail
204     { /////////////////////////////////////////////////////////////////
205       ///////////////////////////////////////////////////////////////////
206       //
207       //        CLASS NAME : SolvableIterator
208       //
209       /** */
210       class SolvableIterator : public boost::iterator_adaptor<
211           SolvableIterator                   // Derived
212           , ::_Solvable*                     // Base
213           , const Solvable                   // Value
214           , boost::forward_traversal_tag     // CategoryOrTraversal
215           , const Solvable                   // Reference
216           >
217       {
218         public:
219           SolvableIterator()
220           : SolvableIterator::iterator_adaptor_( 0 )
221           {}
222
223           explicit SolvableIterator( const Solvable & val_r )
224           : SolvableIterator::iterator_adaptor_( 0 )
225           { assignVal( val_r ); }
226
227           explicit SolvableIterator( SolvableIdType id_r )
228           : SolvableIterator::iterator_adaptor_( 0 )
229           { assignVal( Solvable( id_r ) ); }
230
231         private:
232           friend class boost::iterator_core_access;
233
234           Solvable dereference() const
235           { return _val; }
236
237           void increment()
238           { assignVal( _val.nextInPool() ); }
239
240         private:
241           void assignVal( const Solvable & val_r )
242           { _val = val_r; base_reference() = _val.get(); }
243
244           Solvable _val;
245       };
246       ///////////////////////////////////////////////////////////////////
247       /////////////////////////////////////////////////////////////////
248     } // namespace detail
249     ///////////////////////////////////////////////////////////////////
250
251    /////////////////////////////////////////////////////////////////
252   } // namespace sat
253   ///////////////////////////////////////////////////////////////////
254
255   /** \relates sat::Solvable Test whether a \ref sat::Solvable is of a certain Kind. */
256   template<class _Res>
257   inline bool isKind( const sat::Solvable & solvable_r )
258   { return solvable_r.isKind( ResTraits<_Res>::kind ); }
259
260   /////////////////////////////////////////////////////////////////
261 } // namespace zypp
262 ///////////////////////////////////////////////////////////////////
263 #endif // ZYPP_SAT_SOLVABLE_H