Remove obsolete ResStatus bits.
[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     /**
83      * Flag in the metadata indicating this should be
84      * installed unsing '-i' (not -U).
85      */
86     bool installOnly() const
87     { return sat::Solvable::installOnly(); }
88
89     /** \name Dependencies. */
90     //@{
91     /** Select by Dep. */
92     Capabilities dep( Dep which_r ) const
93     { return operator[]( which_r ); }
94
95     Capabilities operator[]( Dep which_r ) const
96     { return sat::Solvable::operator[]( which_r ); }
97
98     Capabilities provides()    const
99     { return sat::Solvable::provides(); }
100
101     Capabilities requires()    const
102     { return sat::Solvable::requires(); }
103
104     Capabilities conflicts()   const
105     { return sat::Solvable::conflicts(); }
106
107     Capabilities obsoletes()   const
108     { return sat::Solvable::obsoletes(); }
109
110     Capabilities recommends()  const
111     { return sat::Solvable::recommends(); }
112
113     Capabilities suggests()    const
114     { return sat::Solvable::suggests(); }
115
116     Capabilities enhances()    const
117     { return sat::Solvable::enhances(); }
118
119     Capabilities supplements() const
120     { return sat::Solvable::supplements(); }
121
122     Capabilities prerequires() const
123     { return sat::Solvable::prerequires(); }
124
125     CapabilitySet providesNamespace( const std::string & namespace_r ) const
126     { return sat::Solvable::providesNamespace( namespace_r ); }
127
128     CapabilitySet valuesOfNamespace( const std::string & namespace_r ) const
129     { return sat::Solvable::valuesOfNamespace( namespace_r ); }
130     //@}
131
132   public:
133     /** Access the corresponding \ref sat:::Solvable. */
134     const sat::Solvable & satSolvable() const { return *this; }
135
136     /** Access the corresponding \ref PoolItem. */
137     PoolItem poolItem() const;
138
139   protected:
140     /** Ctor */
141     Resolvable( const sat::Solvable & solvable_r );
142     /** Dtor */
143     virtual ~Resolvable();
144     /** Helper for stream output */
145     virtual std::ostream & dumpOn( std::ostream & str ) const;
146  };
147  ///////////////////////////////////////////////////////////////////
148
149  /** \relates Resolvable Stream output */
150  inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
151  { return obj.dumpOn( str ); }
152
153  /** \relates Resolvable More verbose stream output including dependencies */
154  inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
155  { return dumpOn( str, obj.satSolvable() ); }
156
157   /** Test whether a Resolvable::Ptr is of a certain Kind.
158    * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
159    * of the specified Kind.
160    * \relates Resolvable
161    * \code
162    * isKind<Package>(resPtr);
163    * \endcode
164   */
165   template<class _Res>
166     inline bool isKind( const Resolvable::constPtr & p )
167     { return p && p->kind() == ResTraits<_Res>::kind; }
168
169   // Specialization for Resolvable: Always true.
170   template<>
171     inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
172     { return p; }
173
174   // Specialization for ResObject: Always true.
175   template<>
176     inline bool isKind<ResObject>( const Resolvable::constPtr & p )
177     { return p; }
178
179
180   /** Convert Resolvable::Ptr into Ptr of a certain Kind.
181    * \return \c NULL iff \a p is \c NULL or points to a Resolvable
182    * not of the specified Kind.
183    * \relates Resolvable
184    * \code
185    * asKind<Package>(resPtr);
186    * \endcode
187   */
188   template<class _Res>
189     inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
190     { return dynamic_pointer_cast<_Res>(p); }
191
192   template<class _Res>
193     inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
194     { return dynamic_pointer_cast<const _Res>(p); }
195
196   ///////////////////////////////////////////////////////////////////
197
198   /** \relates Resolvable Compare Resolvable::constPtr according to
199    *  \a kind and \a name.
200   */
201   inline int compareByN( const Resolvable::constPtr & lhs,
202                          const Resolvable::constPtr & rhs )
203   {
204     if ( lhs == rhs )
205       return 0;
206     if ( ! (lhs && rhs) )
207       return lhs ? 1 : -1;
208     int res = 0;
209     if ( (res = lhs->kind().compare( rhs->kind() )) )
210       return res;
211     return lhs->name().compare( rhs->name() );
212   }
213
214   /** \relates Resolvable Compare Resolvable::constPtr according to
215    *  \a kind, \a name and \a edition(compare!).
216   */
217   inline int compareByNVR( const Resolvable::constPtr & lhs,
218                            const Resolvable::constPtr & rhs )
219   {
220     if ( lhs == rhs )
221       return 0;
222     if ( ! (lhs && rhs) )
223       return lhs ? 1 : -1;
224     int res = 0;
225     if ( (res = lhs->kind().compare( rhs->kind() )) )
226       return res;
227     if ( (res = lhs->name().compare( rhs->name() )) )
228       return res;
229     return lhs->edition().compare( rhs->edition() );
230   }
231
232   /** \relates Resolvable Compare Resolvable::constPtr according to
233    *  \a kind, \a name, \a edition(compare!) and \a arch.
234   */
235   inline int compareByNVRA( const Resolvable::constPtr & lhs,
236                             const Resolvable::constPtr & rhs )
237   {
238     if ( lhs == rhs )
239       return 0;
240     if ( ! (lhs && rhs) )
241       return lhs ? 1 : -1;
242     int res = 0;
243     if ( (res = lhs->kind().compare( rhs->kind() )) )
244       return res;
245     if ( (res = lhs->name().compare( rhs->name() )) )
246       return res;
247     if ( (res = lhs->edition().compare( rhs->edition() )) )
248       return res;
249     return lhs->arch().compare( rhs->arch() );
250   }
251
252   /////////////////////////////////////////////////////////////////
253 } // namespace zypp
254 ///////////////////////////////////////////////////////////////////
255 #endif // ZYPP_RESOLVABLE_H