1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ResObject.h
12 #ifndef ZYPP_RESOBJECT_H
13 #define ZYPP_RESOBJECT_H
15 #include <zypp/APIConfig.h>
17 #include <zypp/Resolvable.h>
18 #include <zypp/Vendor.h>
20 #include <zypp/sat/LookupAttr.h>
22 ///////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
27 /// \brief Base for resolvable objects
29 /// \note \ref Resolvable is a SolvableType, which provides direct
30 /// access to many of the underlying sat::Solvables properties.
31 /// Don't add common properties here, but in \ref sat::Solvable
32 /// and extend \ref sat::SolvableType.
34 /// \see \ref makeResObject for how to construct ResObjects.
35 /// \todo Merge with Resolvable
36 ///////////////////////////////////////////////////////////////////
37 class ResObject : public Resolvable
40 typedef ResObject Self;
41 typedef ResTraits<Self> TraitsType;
42 typedef TraitsType::PtrType Ptr;
43 typedef TraitsType::constPtrType constPtr;
46 /** Convert \c this into a Ptr of a certain Kind.
47 * This is a convenience to access type specific
49 * \return \c NULL if \c this is not of the specified kind.
52 * Package::constPtr pkg = pi->asKind<Package>();
54 * if ( pi->isKind<Package>() )
55 * DBG << pi->asKind<Package>()->keywords() << endl;
59 inline typename ResTraits<TRes>::constPtrType asKind() const;
62 inline typename ResTraits<TRes>::PtrType asKind();
67 * \deprecated Though typedef'ed to std::string, Vendor is actually an \ref IdString.
70 { return Resolvable::vendor().asString(); }
73 friend ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
75 ResObject( const sat::Solvable & solvable_r );
78 /** Helper for stream output */
79 virtual std::ostream & dumpOn( std::ostream & str ) const;
80 /** This is a \ref sat::SolvableType (allow implicit conversion in derived classes). */
81 operator sat::Solvable() const
82 { return satSolvable(); }
84 ///////////////////////////////////////////////////////////////////
86 /** Create \ref ResObject from \ref sat::Solvable.
88 * This function creates the apropriate kind of ResObject
89 * depending on the sat::Solvables kind, and returns a smart
92 * If the sat::Solvables kind is not convertible, a NULL
93 * pointer is returned.
97 * ResObject::Ptr p( makeResObject( s ) );
98 * ResObject::Ptr q( make<ResObject>( s ) );
99 * Package::Ptr pkg( make<Package>( s ) );
102 ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
104 /** Directly create a certain kind of ResObject from \ref sat::Solvable.
106 * If the sat::Solvables kind is not appropriate, a NULL
107 * pointer is returned.
110 * ResObject::Ptr p( makeResObject( s ) );
111 * ResObject::Ptr q( make<ResObject>( s ) );
112 * Package::Ptr pkg( make<Package>( s ) );
114 * \todo make<> was a poor choice (AFAIR because gcc had some trouble with
115 * asKind<>(sat::Solvable)). Remove it in favour of asKind<>(sat::Solvable)
118 inline typename ResTraits<TRes>::PtrType make( const sat::Solvable & solvable_r )
119 { return( isKind<TRes>( solvable_r ) ? new TRes( solvable_r ) : 0 ); }
120 /** \overload Specialisation for ResObject autodetecting the kind of resolvable. */
122 inline ResObject::Ptr make<ResObject>( const sat::Solvable & solvable_r )
123 { return makeResObject( solvable_r ); }
125 /** Directly create a certain kind of ResObject from \ref sat::Solvable. */
127 inline typename ResTraits<TRes>::PtrType asKind( const sat::Solvable & solvable_r )
128 { return make<TRes>( solvable_r ); }
130 /** Convert ResObject::Ptr into Ptr of a certain Kind.
131 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
132 * not of the specified Kind.
135 * asKind<Package>(resPtr);
139 inline typename ResTraits<TRes>::PtrType asKind( const ResObject::Ptr & p )
140 { return dynamic_pointer_cast<TRes>(p); }
143 inline typename ResTraits<TRes>::constPtrType asKind( const ResObject::constPtr & p )
144 { return dynamic_pointer_cast<const TRes>(p); }
147 inline typename ResTraits<TRes>::constPtrType ResObject::asKind() const
148 { return dynamic_cast<const TRes *>( this ); }
151 inline typename ResTraits<TRes>::PtrType ResObject::asKind()
152 { return dynamic_cast<TRes *>( this ); }
155 ///////////////////////////////////////////////////////////////////
156 #endif // ZYPP_RESOBJECT_H