1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Resolvable.h
12 #ifndef ZYPP_RESOLVABLE_H
13 #define ZYPP_RESOLVABLE_H
18 #include "zypp/base/ReferenceCounted.h"
19 #include "zypp/base/NonCopyable.h"
20 #include "zypp/base/PtrTypes.h"
21 #include "zypp/ResTraits.h"
23 #include "zypp/Edition.h"
24 #include "zypp/Arch.h"
25 #include "zypp/Dependencies.h"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////
33 // CLASS NAME : Resolvable
35 /** Interface base for resolvable objects (identification and dependencies).
37 class Resolvable : public base::ReferenceCounted, private base::NonCopyable
40 typedef Resolvable Self;
41 typedef ResTraits<Self> TraitsType;
42 typedef TraitsType::KindType Kind;
43 typedef TraitsType::PtrType Ptr;
44 typedef TraitsType::constPtrType constPtr;
45 friend std::ostream & operator<<( std::ostream & str, const Resolvable & obj );
49 const Kind & kind() const;
51 const std::string & name() const;
53 const Edition & edition() const;
55 const Arch & arch() const;
57 const Dependencies & deps() const;
59 void setDeps( const Dependencies & val_r );
63 Resolvable( const Kind & kind_r,
64 const std::string & name_r,
65 const Edition & edition_r,
66 const Arch & arch_r );
68 virtual ~Resolvable();
69 /** Helper for stream output */
70 virtual std::ostream & dumpOn( std::ostream & str ) const;
75 /** Pointer to implementation */
76 RW_pointer<Impl> _pimpl;
78 ///////////////////////////////////////////////////////////////////
80 /** Test whether a Resolvable::Ptr is of a certain Kind.
81 * \return \c Ture iff \a p is not \c NULL and points to a Resolvable
82 * of the specified Kind.
85 * isKind<Package>(resPtr);
89 inline bool isKind( const Resolvable::constPtr & p )
90 { return p && p->kind() == ResTraits<_Res>::kind; }
92 // Specialization for Resolvable: Always true.
94 inline bool isKind<Resolvable>( const Resolvable::constPtr & p )
97 // Specialization for ResObject: Always true.
99 inline bool isKind<ResObject>( const Resolvable::constPtr & p )
103 /** Convert Resolvable::Ptr into Ptr of a certain Kind.
104 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
105 * not of the specified Kind.
106 * \relates Resolvable
108 * asKind<Package>(resPtr);
112 inline typename ResTraits<_Res>::PtrType asKind( const Resolvable::Ptr & p )
113 { return dynamic_pointer_cast<_Res>(p); }
116 inline typename ResTraits<_Res>::constPtrType asKind( const Resolvable::constPtr & p )
117 { return dynamic_pointer_cast<const _Res>(p); }
119 ///////////////////////////////////////////////////////////////////
121 /** Required by intrusive_ptr to add a reference. */
122 inline void intrusive_ptr_add_ref( const Resolvable * ptr_r )
123 { base::ReferenceCounted::add_ref( ptr_r ); }
125 /** Required by intrusive_ptr to release a reference. */
126 inline void intrusive_ptr_release( const Resolvable * ptr_r )
127 { base::ReferenceCounted::release( ptr_r ); }
129 /** \relates Resolvable Stream output via Resolvable::dumpOn */
130 inline std::ostream & operator<<( std::ostream & str, const Resolvable & obj )
131 { return obj.dumpOn( str ); }
133 /////////////////////////////////////////////////////////////////
135 ///////////////////////////////////////////////////////////////////
136 #endif // ZYPP_RESOLVABLE_H