From 1669994b722ec3f2dc4398125f0df2a888229c6f Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Tue, 23 Sep 2008 10:25:00 +0000 Subject: [PATCH] add ResObject::as() --- devel/devel.ma/NewPool.cc | 20 ++++++++------------ zypp/ResObject.h | 30 +++++++++++++++++++++++++++++- zypp/Resolvable.h | 4 ++++ zypp/sat/Solvable.h | 4 ++++ 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/devel/devel.ma/NewPool.cc b/devel/devel.ma/NewPool.cc index 34e5c42..239d133 100644 --- a/devel/devel.ma/NewPool.cc +++ b/devel/devel.ma/NewPool.cc @@ -430,7 +430,6 @@ void testCMP( const L & lhs, const R & rhs ) #undef OUTS } - /****************************************************************** ** ** FUNCTION NAME : main @@ -444,16 +443,6 @@ try { 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 @@ try { } - ////////////////////////////////////////////////////////////////// + PoolItem pi ( getPi("amarok") ); + MIL << pi << endl; + MIL << pi->as() << endl; + MIL << pi->as() << endl; + if ( pi->isKind() ) + SEC << pi->as() << endl; + + ////////////////////////////////////////////////////////////////// INT << "===[END]============================================" << endl << endl; zypp::base::LogControl::instance().logNothing(); return 0; diff --git a/zypp/ResObject.h b/zypp/ResObject.h index 0faa960..8a4e7da 100644 --- a/zypp/ResObject.h +++ b/zypp/ResObject.h @@ -50,9 +50,29 @@ namespace zypp 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(); + * + * if ( pi->isKind() ) + * DBG << pi->as()->keywords() << endl; + * \endcode + */ + template + inline typename ResTraits<_Res>::constPtrType as() const; + + template + 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 @@ namespace zypp inline typename ResTraits<_Res>::constPtrType asKind( const ResObject::constPtr & p ) { return dynamic_pointer_cast(p); } + template + inline typename ResTraits<_Res>::constPtrType ResObject::as() const + { return make<_Res>( *this ); } + + template + inline typename ResTraits<_Res>::PtrType ResObject::as() + { return make<_Res>( *this ); } + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/Resolvable.h b/zypp/Resolvable.h index 5984bbd..c697b8e 100644 --- a/zypp/Resolvable.h +++ b/zypp/Resolvable.h @@ -66,6 +66,10 @@ namespace zypp bool isKind( const ResKind & kind_r ) const { return sat::Solvable::isKind( kind_r ); } + template + bool isKind() const + { return sat::Solvable::isKind<_Res>(); } + std::string name() const { return sat::Solvable::name(); } diff --git a/zypp/sat/Solvable.h b/zypp/sat/Solvable.h index 937b392..1a0ca19 100644 --- a/zypp/sat/Solvable.h +++ b/zypp/sat/Solvable.h @@ -151,6 +151,10 @@ namespace zypp ResKind kind() const; /** Test whether a Solvable is of a certain \ref ResKind. */ bool isKind( const ResKind & kind_r ) const; + /** \overload */ + template + bool isKind() const + { return isKind( resKind<_Res>() ); } std::string name() const; Edition edition() const; -- 2.7.4