libzypp  11.13.5
Resolvable.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_RESOLVABLE_H
13 #define ZYPP_RESOLVABLE_H
14 
15 #include <iosfwd>
16 #include <string>
17 
18 #include "zypp/APIConfig.h"
19 
21 #include "zypp/base/NonCopyable.h"
22 #include "zypp/base/PtrTypes.h"
23 
24 #include "zypp/sat/Solvable.h"
25 
27 namespace zypp
28 {
29 
30  class PoolItem;
31 
33  //
34  // CLASS NAME : Resolvable
35  //
39  class Resolvable : protected zypp::sat::Solvable, // Note: gcc bug #52841 prohibits using just sat::Solvable
41  {
42  friend std::ostream & operator<<( std::ostream & str, const Resolvable & obj );
43 
44  public:
45  typedef Resolvable Self;
50 
51  public:
52 #ifndef SWIG // Swig treats it as syntax error
53 
54  using zypp::sat::Solvable::operator bool_type; // Note: gcc bug #52841 prohibits using just sat::Solvable
55 #endif
56 
57  bool isSystem() const
58  { return sat::Solvable::isSystem(); }
59 
61  bool onSystemByUser() const
62  { return sat::Solvable::onSystemByUser(); }
63 
64  IdString ident() const
65  { return sat::Solvable::ident(); }
66 
67  ResKind kind() const
68  { return sat::Solvable::kind(); }
69 
70  bool isKind( const ResKind & kind_r ) const
71  { return sat::Solvable::isKind( kind_r ); }
72 
73  template<class _Res>
74  bool isKind() const
75  { return sat::Solvable::isKind<_Res>(); }
76 
77  std::string name() const
78  { return sat::Solvable::name(); }
79 
80  Edition edition() const
81  { return sat::Solvable::edition(); }
82 
83  Arch arch() const
84  { return sat::Solvable::arch(); }
85 
89  bool multiversionInstall() const
91 
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 
102  { return sat::Solvable::provides(); }
103 
105  { return sat::Solvable::requires(); }
106 
108  { return sat::Solvable::conflicts(); }
109 
111  { return sat::Solvable::obsoletes(); }
112 
114  { return sat::Solvable::recommends(); }
115 
117  { return sat::Solvable::suggests(); }
118 
120  { return sat::Solvable::enhances(); }
121 
123  { return sat::Solvable::supplements(); }
124 
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 ); }
134 
135  public:
137  const sat::Solvable & satSolvable() const { return *this; }
138 
140  PoolItem poolItem() const;
141 
142  protected:
144  Resolvable( const sat::Solvable & solvable_r );
146  virtual ~Resolvable();
148  virtual std::ostream & dumpOn( std::ostream & str ) const;
149  };
151 
153  inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
154  { return obj.dumpOn( str ); }
155 
157  inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
158  { return dumpOn( str, obj.satSolvable() ); }
159 
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 
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 
200 
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 
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 
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 
256 } // namespace zypp
258 #endif // ZYPP_RESOLVABLE_H