1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Resolvable.h
12 #ifndef ZYPP_RESOLVABLE_H
13 #define ZYPP_RESOLVABLE_H
18 #include "zypp/APIConfig.h"
20 #include "zypp/base/ReferenceCounted.h"
21 #include "zypp/base/NonCopyable.h"
22 #include "zypp/base/PtrTypes.h"
24 #include "zypp/sat/SolvableType.h"
26 ///////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
32 /// \brief Base for resolvable objects
34 /// \note \ref Resolvable is a SolvableType, which provides direct
35 /// access to many of the underlying sat::Solvables properties.
36 /// Don't add common properties here, but in \ref sat::Solvable
37 /// and extend \ref sat::SolvableType.
39 /// In most cases you want to retrieve the common properties directly
40 /// from a \ref PoolItem or \ref sat::Solvable. Construction from and
41 /// explicit conversion to sat::Solvable are supported. Next goal is
42 /// to get rid of the smart pointer hierarchy. A Resolvable is actually
43 /// an unsigned and derived classes contain no data, so it makes little
44 /// sense to wrap this into ReferenceCounted smart pointer.
46 /// \todo Merge with ResObject
47 /// \todo Get rid of refcout/smart_prt bloat, as this type is actually IdBased (i.e. sizeof(unsigned))
48 ///////////////////////////////////////////////////////////////////
49 class Resolvable : public sat::SolvableType<Resolvable>,
50 public base::ReferenceCounted, private base::NonCopyable
52 friend std::ostream & operator<<( std::ostream & str, const Resolvable & obj );
55 typedef Resolvable Self;
56 typedef ResTraits<Self> TraitsType;
57 typedef TraitsType::KindType Kind;
58 typedef TraitsType::PtrType Ptr;
59 typedef TraitsType::constPtrType constPtr;
62 /** This is a \ref sat::SolvableType. */
63 explicit operator sat::Solvable() const
66 /** Access the corresponding \ref PoolItem. */
67 PoolItem poolItem() const;
71 Resolvable( const sat::Solvable & solvable_r );
73 virtual ~Resolvable();
74 /** Helper for stream output */
75 virtual std::ostream & dumpOn( std::ostream & str ) const;
78 sat::Solvable _solvable;
80 ///////////////////////////////////////////////////////////////////
82 /** \relates Resolvable Stream output */
83 inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
84 { return obj.dumpOn( str ); }
86 /** \relates Resolvable More verbose stream output including dependencies */
87 inline std::ostream & dumpOn( std::ostream & str, const Resolvable & obj )
88 { return dumpOn( str, obj.satSolvable() ); }
90 /** Test whether a Resolvable::Ptr is of a certain Kind.
91 * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
92 * of the specified Kind.
95 * isKind<Package>(resPtr);
99 inline bool isKind( const Resolvable::constPtr & p )
100 { return p && p->isKind<TRes>(); }
102 // Specialization for Resolvable: Always true.
104 inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
107 // Specialization for ResObject: Always true.
109 inline bool isKind<ResObject>( const Resolvable::constPtr & p )
113 /** Convert Resolvable::Ptr into Ptr of a certain Kind.
114 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
115 * not of the specified Kind.
116 * \relates Resolvable
118 * asKind<Package>(resPtr);
122 inline typename ResTraits<TRes>::PtrType asKind( const Resolvable::Ptr & p )
123 { return dynamic_pointer_cast<TRes>(p); }
126 inline typename ResTraits<TRes>::constPtrType asKind( const Resolvable::constPtr & p )
127 { return dynamic_pointer_cast<const TRes>(p); }
129 ///////////////////////////////////////////////////////////////////
131 /** \relates Resolvable Compare Resolvable::constPtr according to \a kind and \a name.
132 * \deprecated Get rid of refcout/smart_prt bloat, use
134 inline int compareByN( const Resolvable::constPtr & lhs, const Resolvable::constPtr & rhs )
140 ret = compareByN( *lhs, *rhs );
147 /** \relates Resolvable Compare according to \a kind, \a name and \a edition. */
148 inline int compareByNVR( const Resolvable::constPtr & lhs, const Resolvable::constPtr & rhs )
154 ret = compareByNVR( *lhs, *rhs );
161 /** \relates Resolvable Compare Resolvable::constPtr according to \a kind, \a name, \a edition and \a arch. */
162 inline int compareByNVRA( const Resolvable::constPtr & lhs, const Resolvable::constPtr & rhs )
168 ret = compareByNVRA( *lhs, *rhs );
175 ///////////////////////////////////////////////////////////////////
176 #endif // ZYPP_RESOLVABLE_H