Author: mlandres Date: Tue Sep 23 12:25:00 2008 New Revision: 11131 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11131&view=rev Log: add ResObject::as<Package>() Modified: trunk/libzypp/devel/devel.ma/NewPool.cc trunk/libzypp/zypp/ResObject.h trunk/libzypp/zypp/Resolvable.h trunk/libzypp/zypp/sat/Solvable.h Modified: trunk/libzypp/devel/devel.ma/NewPool.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/NewPool.cc?rev=11131&r1=11130&r2=11131&view=diff ============================================================================== --- trunk/libzypp/devel/devel.ma/NewPool.cc (original) +++ trunk/libzypp/devel/devel.ma/NewPool.cc Tue Sep 23 12:25:00 2008 @@ -430,7 +430,6 @@ #undef OUTS } - /****************************************************************** ** ** FUNCTION NAME : main @@ -444,16 +443,6 @@ INT << "===[START]==========================================" << endl; ZConfig::instance(); - Edition a("4.21.3-2"); - DBG << a << endl; - DBG << (a == a) << endl; - DBG << (a.match(a)) << endl; - /////////////////////////////////////////////////////////////////// - INT << "===[END]============================================" << endl << endl; - zypp::base::LogControl::instance().logNothing(); - return 0; - - #if 0 RepoManager repoManager( makeRepoManager( sysRoot ) ); @@ -625,7 +614,14 @@ } - ////////////////////////////////////////////////////////////////// + PoolItem pi ( getPi<Package>("amarok") ); + MIL << pi << endl; + MIL << pi->as<Package>() << endl; + MIL << pi->as<Product>() << endl; + if ( pi->isKind<Package>() ) + SEC << pi->as<Package>() << endl; + + ////////////////////////////////////////////////////////////////// INT << "===[END]============================================" << endl << endl; zypp::base::LogControl::instance().logNothing(); return 0; Modified: trunk/libzypp/zypp/ResObject.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ResObject.h?rev=11131&r1=11130&r2=11131&view=diff ============================================================================== --- trunk/libzypp/zypp/ResObject.h (original) +++ trunk/libzypp/zypp/ResObject.h Tue Sep 23 12:25:00 2008 @@ -50,9 +50,29 @@ typedef TraitsType::constPtrType constPtr; public: + + /** Convert \c this into a Ptr of a certain Kind. + * This is a convenience to access type specific + * attributes. + * \return \c NULL if \c this is not of the specified kind. + * \code + * PoolItem pi; + * Package::constPtr pkg = pi->as<Package>(); + * + * if ( pi->isKind<Package>() ) + * DBG << pi->as<Package>()->keywords() << endl; + * \endcode + */ + template<class _Res> + inline typename ResTraits<_Res>::constPtrType as() const; + + template<class _Res> + inline typename ResTraits<_Res>::PtrType as(); + + public: /** \name Locale support. * \see \ref sat::Solvable - */ + */ //@{ /** \see \ref sat::Solvable::supportsLocales */ bool supportsLocales() const @@ -240,6 +260,14 @@ inline typename ResTraits<_Res>::constPtrType asKind( const ResObject::constPtr & p ) { return dynamic_pointer_cast<const _Res>(p); } + template<class _Res> + inline typename ResTraits<_Res>::constPtrType ResObject::as() const + { return make<_Res>( *this ); } + + template<class _Res> + inline typename ResTraits<_Res>::PtrType ResObject::as() + { return make<_Res>( *this ); } + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// Modified: trunk/libzypp/zypp/Resolvable.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Resolvable.h?rev=11131&r1=11130&r2=11131&view=diff ============================================================================== --- trunk/libzypp/zypp/Resolvable.h (original) +++ trunk/libzypp/zypp/Resolvable.h Tue Sep 23 12:25:00 2008 @@ -66,6 +66,10 @@ bool isKind( const ResKind & kind_r ) const { return sat::Solvable::isKind( kind_r ); } + template<class _Res> + bool isKind() const + { return sat::Solvable::isKind<_Res>(); } + std::string name() const { return sat::Solvable::name(); } Modified: trunk/libzypp/zypp/sat/Solvable.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Solvable.h?rev=11131&r1=11130&r2=11131&view=diff ============================================================================== --- trunk/libzypp/zypp/sat/Solvable.h (original) +++ trunk/libzypp/zypp/sat/Solvable.h Tue Sep 23 12:25:00 2008 @@ -151,6 +151,10 @@ ResKind kind() const; /** Test whether a Solvable is of a certain \ref ResKind. */ bool isKind( const ResKind & kind_r ) const; + /** \overload */ + template<class _Res> + bool isKind() const + { return isKind( resKind<_Res>() ); } std::string name() const; Edition edition() const; -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org