Parse zypp.conf multiversion option and make the setting available in pool and resolver.
[platform/upstream/libzypp.git] / zypp / Resolvable.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Resolvable.h
10  *
11 */
12 #ifndef ZYPP_RESOLVABLE_H
13 #define ZYPP_RESOLVABLE_H
14
15 #include <iosfwd>
16 #include <string>
17
18 #include "zypp/base/Deprecated.h"
19
20 #include "zypp/base/ReferenceCounted.h"
21 #include "zypp/base/NonCopyable.h"
22 #include "zypp/base/PtrTypes.h"
23
24 #include "zypp/sat/Solvable.h"
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29
30   class PoolItem;
31
32   ///////////////////////////////////////////////////////////////////
33   //
34   //    CLASS NAME : Resolvable
35   //
36   /** Interface base for resolvable objects (identification and dependencies).
37    * \todo Merge with ResObject
38   */
39   class Resolvable : protected sat::Solvable,
40                      public base::ReferenceCounted, private base::NonCopyable
41   {
42     friend std::ostream & operator<<( std::ostream & str, const Resolvable & obj );
43
44   public:
45     typedef Resolvable               Self;
46     typedef ResTraits<Self>          TraitsType;
47     typedef TraitsType::KindType     Kind;
48     typedef TraitsType::PtrType      Ptr;
49     typedef TraitsType::constPtrType constPtr;
50
51   public:
52 #ifndef SWIG // Swig treats it as syntax error
53     /** Whether this represents a valid- or no-solvable. */
54     using sat::Solvable::operator bool_type;
55 #endif
56     /** Whether this represents an installed solvable. */
57     bool isSystem() const
58     { return sat::Solvable::isSystem(); }
59
60     IdString ident() const
61     { return sat::Solvable::ident(); }
62
63     ResKind kind() const
64     { return sat::Solvable::kind(); }
65
66     bool isKind( const ResKind & kind_r ) const
67     { return sat::Solvable::isKind( kind_r ); }
68
69     template<class _Res>
70     bool isKind() const
71     { return sat::Solvable::isKind<_Res>(); }
72
73     std::string name() const
74     { return sat::Solvable::name(); }
75
76     Edition edition() const
77     { return sat::Solvable::edition(); }
78
79     Arch arch() const
80     { return sat::Solvable::arch(); }
81
82     /** Whether different versions of this package can be installed at the same time.
83      * Per default \c false. \see also \ref ZConfig::multiversion.
84      */
85     bool multiversionInstall() const
86     { return sat::Solvable::multiversionInstall(); }
87
88     /** \deprecated Use \ref multiversionInstall. */
89     bool installOnly() const
90     { return sat::Solvable::multiversionInstall(); }
91
92     /** \name Dependencies. */
93     //@{
94     /** Select by Dep. */
95     Capabilities dep( Dep which_r ) const
96     { return operator[]( which_r ); }
97
98     Capabilities operator[]( Dep which_r ) const
99     { return sat::Solvable::operator[]( which_r ); }
100
101     Capabilities provides()    const
102     { return sat::Solvable::provides(); }
103
104     Capabilities requires()    const
105     { return sat::Solvable::requires(); }
106
107     Capabilities conflicts()   const
108     { return sat::Solvable::conflicts(); }
109
110     Capabilities obsoletes()   const
111     { return sat::Solvable::obsoletes(); }
112
113     Capabilities recommends()  const
114     { return sat::Solvable::recommends(); }
115
116     Capabilities suggests()    const
117     { return sat::Solvable::suggests(); }
118
119     Capabilities enhances()    const
120     { return sat::Solvable::enhances(); }
121
122     Capabilities supplements() const
123     { return sat::Solvable::supplements(); }
124
125     Capabilities prerequires() const
126     { return sat::Solvable::prerequires(); }
127
128     CapabilitySet providesNamespace( const std::string & namespace_r ) const
129     { return sat::Solvable::providesNamespace( namespace_r ); }
130
131     CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const
132     { return sat::Solvable::valuesOfNamespace( namespace_r ); }
133     //@}
134
135   public:
136     /** Access the corresponding \ref sat:::Solvable. */
137     const sat::Solvable & satSolvable() const { return *this; }
138
139     /** Access the corresponding \ref PoolItem. */
140     PoolItem poolItem() const;
141
142   protected:
143     /** Ctor */
144     Resolvable( const sat::Solvable & solvable_r );
145     /** Dtor */
146     virtual ~Resolvable();
147     /** Helper for stream output */
148     virtual std::ostream & dumpOn( std::ostream & str ) const;
149  };
150  ///////////////////////////////////////////////////////////////////
151
152  /** \relates Resolvable Stream output */
153  inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
154  { return obj.dumpOn( str ); }
155
156  /** \relates Resolvable More verbose stream output including dependencies */
157  inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
158  { return dumpOn( str, obj.satSolvable() ); }
159
160   /** Test whether a Resolvable::Ptr is of a certain Kind.
161    * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
162    * of the specified Kind.
163    * \relates Resolvable
164    * \code
165    * isKind<Package>(resPtr);
166    * \endcode
167   */
168   template<class _Res>
169     inline bool isKind( const Resolvable::constPtr & p )
170     { return p && p->kind() == ResTraits<_Res>::kind; }
171
172   // Specialization for Resolvable: Always true.
173   template<>
174     inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
175     { return p; }
176
177   // Specialization for ResObject: Always true.
178   template<>
179     inline bool isKind<ResObject>( const Resolvable::constPtr & p )
180     { return p; }
181
182
183   /** Convert Resolvable::Ptr into Ptr of a certain Kind.
184    * \return \c NULL iff \a p is \c NULL or points to a Resolvable
185    * not of the specified Kind.
186    * \relates Resolvable
187    * \code
188    * asKind<Package>(resPtr);
189    * \endcode
190   */
191   template<class _Res>
192     inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
193     { return dynamic_pointer_cast<_Res>(p); }
194
195   template<class _Res>
196     inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
197     { return dynamic_pointer_cast<const _Res>(p); }
198
199   ///////////////////////////////////////////////////////////////////
200
201   /** \relates Resolvable Compare Resolvable::constPtr according to
202    *  \a kind and \a name.
203   */
204   inline int compareByN( const Resolvable::constPtr & lhs,
205                          const Resolvable::constPtr & rhs )
206   {
207     if ( lhs == rhs )
208       return 0;
209     if ( ! (lhs && rhs) )
210       return lhs ? 1 : -1;
211     int res = 0;
212     if ( (res = lhs->kind().compare( rhs->kind() )) )
213       return res;
214     return lhs->name().compare( rhs->name() );
215   }
216
217   /** \relates Resolvable Compare Resolvable::constPtr according to
218    *  \a kind, \a name and \a edition(compare!).
219   */
220   inline int compareByNVR( const Resolvable::constPtr & lhs,
221                            const Resolvable::constPtr & rhs )
222   {
223     if ( lhs == rhs )
224       return 0;
225     if ( ! (lhs && rhs) )
226       return lhs ? 1 : -1;
227     int res = 0;
228     if ( (res = lhs->kind().compare( rhs->kind() )) )
229       return res;
230     if ( (res = lhs->name().compare( rhs->name() )) )
231       return res;
232     return lhs->edition().compare( rhs->edition() );
233   }
234
235   /** \relates Resolvable Compare Resolvable::constPtr according to
236    *  \a kind, \a name, \a edition(compare!) and \a arch.
237   */
238   inline int compareByNVRA( const Resolvable::constPtr & lhs,
239                             const Resolvable::constPtr & rhs )
240   {
241     if ( lhs == rhs )
242       return 0;
243     if ( ! (lhs && rhs) )
244       return lhs ? 1 : -1;
245     int res = 0;
246     if ( (res = lhs->kind().compare( rhs->kind() )) )
247       return res;
248     if ( (res = lhs->name().compare( rhs->name() )) )
249       return res;
250     if ( (res = lhs->edition().compare( rhs->edition() )) )
251       return res;
252     return lhs->arch().compare( rhs->arch() );
253   }
254
255   /////////////////////////////////////////////////////////////////
256 } // namespace zypp
257 ///////////////////////////////////////////////////////////////////
258 #endif // ZYPP_RESOLVABLE_H