libzypp  17.5.0
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/SolvableType.h"
25 
27 namespace zypp
28 {
29  class PoolItem;
49  class Resolvable : public sat::SolvableType<Resolvable>,
51  {
52  friend std::ostream & operator<<( std::ostream & str, const Resolvable & obj );
53 
54  public:
55  typedef Resolvable Self;
60 
61  public:
63  explicit operator sat::Solvable() const
64  { return _solvable; }
65 
67  PoolItem poolItem() const;
68 
69  protected:
71  Resolvable( const sat::Solvable & solvable_r );
73  virtual ~Resolvable();
75  virtual std::ostream & dumpOn( std::ostream & str ) const;
76 
77  private:
79  };
81 
83  inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
84  { return obj.dumpOn( str ); }
85 
87  inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
88  { return dumpOn( str, obj.satSolvable() ); }
89 
98  template<class TRes>
99  inline bool isKind( const Resolvable::constPtr & p )
100  { return p && p->isKind<TRes>(); }
101 
102  // Specialization for Resolvable: Always true.
103  template<>
104  inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
105  { return !!p; }
106 
107  // Specialization for ResObject: Always true.
108  template<>
109  inline bool isKind<ResObject>( const Resolvable::constPtr & p )
110  { return !!p; }
111 
112 
121  template<class TRes>
122  inline typename ResTraits<TRes>::PtrType asKind( const Resolvable::Ptr & p )
123  { return dynamic_pointer_cast<TRes>(p); }
124 
125  template<class TRes>
126  inline typename ResTraits<TRes>::constPtrType asKind( const Resolvable::constPtr & p )
127  { return dynamic_pointer_cast<const TRes>(p); }
128 
130 
134  inline int compareByN( const Resolvable::constPtr & lhs, const Resolvable::constPtr & rhs )
135  {
136  int ret = 0;
137  if ( lhs != rhs )
138  {
139  if ( lhs && rhs )
140  ret = compareByN( *lhs, *rhs );
141  else
142  ret = lhs ? 1 : -1;
143  }
144  return ret;
145  }
146 
148  inline int compareByNVR( const Resolvable::constPtr & lhs, const Resolvable::constPtr & rhs )
149  {
150  int ret = 0;
151  if ( lhs != rhs )
152  {
153  if ( lhs && rhs )
154  ret = compareByNVR( *lhs, *rhs );
155  else
156  ret = lhs ? 1 : -1;
157  }
158  return ret;
159  }
160 
162  inline int compareByNVRA( const Resolvable::constPtr & lhs, const Resolvable::constPtr & rhs )
163  {
164  int ret = 0;
165  if ( lhs != rhs )
166  {
167  if ( lhs && rhs )
168  ret = compareByNVRA( *lhs, *rhs );
169  else
170  ret = lhs ? 1 : -1;
171  }
172  return ret;
173  }
174 } // namespace zypp
176 #endif // ZYPP_RESOLVABLE_H
A Solvable object within the sat Pool.
Definition: Solvable.h:53
intrusive_ptr< const TRes > constPtrType
Definition: ResTraits.h:83
bool compareByNVRA(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:268
TraitsType::KindType Kind
Definition: Resolvable.h:57
ResTraits< Self > TraitsType
Definition: Resolvable.h:56
int compareByNVRA(const Resolvable::constPtr &lhs, const Resolvable::constPtr &rhs)
Definition: Resolvable.h:162
ResTraits< TRes >::PtrType asKind(const sat::Solvable &solvable_r)
Directly create a certain kind of ResObject from sat::Solvable.
Definition: ResObject.h:128
sat::Solvable _solvable
Definition: Resolvable.h:78
String related utilities and Regular expression matching.
Base for resolvable objects.
Definition: Resolvable.h:49
ResTraits.
Definition: ResTraits.h:79
bool compareByN(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:241
Resolvable(const sat::Solvable &solvable_r)
Ctor.
Definition: Resolvable.cc:21
ResTraits< TRes >::PtrType asKind(const Resolvable::Ptr &p)
Convert Resolvable::Ptr into Ptr of a certain Kind.
Definition: Resolvable.h:122
bool isKind(const Resolvable::constPtr &p)
Test whether a Resolvable::Ptr is of a certain Kind.
Definition: Resolvable.h:99
bool isKind< Resolvable >(const Resolvable::constPtr &p)
Definition: Resolvable.h:104
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
std::ostream & dumpOn(std::ostream &str, const Resolvable &obj)
Definition: Resolvable.h:87
Provides API related macros.
TraitsType::PtrType Ptr
Definition: Resolvable.h:58
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:444
Base class for reference counted objects.
virtual std::ostream & dumpOn(std::ostream &str) const
Helper for stream output.
Definition: Resolvable.cc:31
intrusive_ptr< TRes > PtrType
Definition: ResTraits.h:82
bool compareByNVR(const SolvableType< Derived > &lhs, const Solvable &rhs)
Definition: SolvableType.h:255
TraitsType::constPtrType constPtr
Definition: Resolvable.h:59
friend std::ostream & operator<<(std::ostream &str, const Resolvable &obj)
std::ostream & operator<<(std::ostream &str, const Resolvable &obj)
Definition: Resolvable.h:83
int compareByN(const Resolvable::constPtr &lhs, const Resolvable::constPtr &rhs)
Definition: Resolvable.h:134
virtual ~Resolvable()
Dtor.
Definition: Resolvable.cc:25
bool isKind< ResObject >(const Resolvable::constPtr &p)
Definition: Resolvable.h:109
Resolvable Self
Definition: Resolvable.h:55
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
Base class for creating Solvable based types.
Definition: SolvableType.h:54
Resolvable kinds.
Definition: ResKind.h:32
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
int compareByNVR(const Resolvable::constPtr &lhs, const Resolvable::constPtr &rhs)
Definition: Resolvable.h:148
PoolItem poolItem() const
Access the corresponding PoolItem.
Definition: Resolvable.cc:28