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"
21 #include "zypp/sat/SolvableSet.h"
23 ///////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 /// \brief Base for resolvable objects
30 /// \note \ref Resolvable is a SolvableType, which provides direct
31 /// access to many of the underlying sat::Solvables properties.
32 /// Don't add common properties here, but in \ref sat::Solvable
33 /// and extend \ref sat::SolvableType.
35 /// \see \ref makeResObject for how to construct ResObjects.
36 /// \todo Merge with Resolvable
37 ///////////////////////////////////////////////////////////////////
38 class ResObject : public Resolvable
41 typedef ResObject Self;
42 typedef ResTraits<Self> TraitsType;
43 typedef TraitsType::PtrType Ptr;
44 typedef TraitsType::constPtrType constPtr;
47 /** Convert \c this into a Ptr of a certain Kind.
48 * This is a convenience to access type specific
50 * \return \c NULL if \c this is not of the specified kind.
53 * Package::constPtr pkg = pi->asKind<Package>();
55 * if ( pi->isKind<Package>() )
56 * DBG << pi->asKind<Package>()->keywords() << endl;
60 inline typename ResTraits<_Res>::constPtrType asKind() const;
63 inline typename ResTraits<_Res>::PtrType asKind();
68 * \deprecated Though typedef'ed to std::string, Vendor is actually an \ref IdString.
71 { return Resolvable::vendor().asString(); }
74 friend ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
76 ResObject( const sat::Solvable & solvable_r );
79 /** Helper for stream output */
80 virtual std::ostream & dumpOn( std::ostream & str ) const;
81 /** This is a \ref sat::SolvableType (allow implicit conversion in derived classes). */
82 operator sat::Solvable() const
83 { return satSolvable(); }
85 ///////////////////////////////////////////////////////////////////
87 /** Create \ref ResObject from \ref sat::Solvable.
89 * This function creates the apropriate kind of ResObject
90 * depending on the sat::Solvables kind, and returns a smart
93 * If the sat::Solvables kind is not convertible, a NULL
94 * pointer is returned.
98 * ResObject::Ptr p( makeResObject( s ) );
99 * ResObject::Ptr q( make<ResObject>( s ) );
100 * Package::Ptr pkg( make<Package>( s ) );
103 ResObject::Ptr makeResObject( const sat::Solvable & solvable_r );
105 /** Directly create a certain kind of ResObject from \ref sat::Solvable.
107 * If the sat::Solvables kind is not appropriate, a NULL
108 * pointer is returned.
111 * ResObject::Ptr p( makeResObject( s ) );
112 * ResObject::Ptr q( make<ResObject>( s ) );
113 * Package::Ptr pkg( make<Package>( s ) );
115 * \todo make<> was a poor choice (AFAIR because gcc had some trouble with
116 * asKind<>(sat::Solvable)). Remove it in favour of asKind<>(sat::Solvable)
119 inline typename ResTraits<_Res>::PtrType make( const sat::Solvable & solvable_r )
120 { return( isKind<_Res>( solvable_r ) ? new _Res( solvable_r ) : 0 ); }
121 /** \overload Specialisation for ResObject autodetecting the kind of resolvable. */
123 inline ResObject::Ptr make<ResObject>( const sat::Solvable & solvable_r )
124 { return makeResObject( solvable_r ); }
126 /** Directly create a certain kind of ResObject from \ref sat::Solvable. */
128 inline typename ResTraits<_Res>::PtrType asKind( const sat::Solvable & solvable_r )
129 { return make<_Res>( solvable_r ); }
131 /** Convert ResObject::Ptr into Ptr of a certain Kind.
132 * \return \c NULL iff \a p is \c NULL or points to a Resolvable
133 * not of the specified Kind.
136 * asKind<Package>(resPtr);
140 inline typename ResTraits<_Res>::PtrType asKind( const ResObject::Ptr & p )
141 { return dynamic_pointer_cast<_Res>(p); }
144 inline typename ResTraits<_Res>::constPtrType asKind( const ResObject::constPtr & p )
145 { return dynamic_pointer_cast<const _Res>(p); }
148 inline typename ResTraits<_Res>::constPtrType ResObject::asKind() const
149 { return dynamic_cast<const _Res *>( this ); }
152 inline typename ResTraits<_Res>::PtrType ResObject::asKind()
153 { return dynamic_cast<_Res *>( this ); }
156 ///////////////////////////////////////////////////////////////////
157 #endif // ZYPP_RESOBJECT_H