From df79ac81ff87149dbe30aa879ffbdc75923d75a5 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Thu, 17 Nov 2005 10:01:26 +0000 Subject: [PATCH] Enabled use of ResTraits. Currently they define the Resolvables ResKind() value. --- test/devel.ma/Main.cc | 88 ++++++++++++++++++++++++++++++++-------- test/devel.ma/Makefile.am | 5 +-- zypp/Capability.cc | 4 +- zypp/Capability.h | 6 +-- zypp/Message.cc | 2 +- zypp/Package.cc | 2 +- zypp/Patch.cc | 2 +- zypp/Product.cc | 2 +- zypp/Resolvable.h | 8 +++- zypp/ResolvableFwd.h | 31 -------------- zypp/Script.cc | 2 +- zypp/Selection.cc | 2 +- zypp/capability/CapabilityImpl.h | 4 +- zypp/capability/NamedCap.h | 2 +- zypp/detail/ResObjectImplIf.h | 2 + 15 files changed, 97 insertions(+), 65 deletions(-) delete mode 100644 zypp/ResolvableFwd.h diff --git a/test/devel.ma/Main.cc b/test/devel.ma/Main.cc index a22e5b1..7cfdece 100644 --- a/test/devel.ma/Main.cc +++ b/test/devel.ma/Main.cc @@ -3,15 +3,14 @@ #include #include #include -#include -#include "main.h" -//#include "main2.h" +#include +#include #define TAG INT << __PRETTY_FUNCTION__ << std::endl using namespace std; -inline void OUT( Resolvable::constPtr p ) +inline void OUT( zypp::Resolvable::constPtr p ) { if ( p ) MIL << *p << endl; @@ -19,23 +18,73 @@ inline void OUT( Resolvable::constPtr p ) MIL << "NULL" << endl; } -inline void OUT( Package::constPtr p ) + +namespace zypp { - if ( p ) { - MIL << *p << ' ' << p->packagedata() << endl; + namespace detail { + ResObjectImplIf::~ResObjectImplIf() + {} } - else - MIL << "NULL" << endl; -} -inline void OUT( Package::Ptr p ) -{ - OUT( Package::constPtr( p ) ); -} -struct PI : public PackageImpl +// connect resolvables interface and implementation. +template + class ResImplConnect : public _Res + { + public: + typedef ResImplConnect Self; + typedef typename _Res::Impl Impl; + typedef base::shared_ptr ImplPtr; + typedef base::intrusive_ptr Ptr; + typedef base::intrusive_ptr constPtr; + public: + /** \todo protect against NULL Impl. */ + ResImplConnect( const std::string & name_r, + const Edition & edition_r, + const Arch & arch_r, + ImplPtr impl_r ) + : _Res( name_r, edition_r, arch_r ) + , _impl( impl_r ) + { _impl->_backRef = this; } + virtual ~ResImplConnect() {} + private: + ImplPtr _impl; + virtual Impl & pimpl() { return *_impl; } + virtual const Impl & pimpl() const { return *_impl; } + }; + + +template + typename _Impl::ResType::Ptr + makeResolvable( const std::string & name_r, + const Edition & edition_r, + const Arch & arch_r, + base::shared_ptr<_Impl> & impl_r ) + { + impl_r.reset( new _Impl ); + return new ResImplConnect( name_r, + edition_r, + arch_r, + impl_r ); + } +template + typename _Impl::ResType::Ptr + makeResolvable( base::shared_ptr<_Impl> & impl_r ) + { + impl_r.reset( new _Impl ); + return new ResImplConnect( "n", + Edition("v","r"), + Arch(), + impl_r ); + } + +}//ns + +struct PI : public zypp::detail::MessageImplIf { - virtual string packagedata() const { return "PI::packagedata"; } + virtual std::string text() const { return "message text"; } + virtual std::string type() const { return "message type"; } + virtual ~PI(){} }; @@ -51,6 +100,12 @@ int main( int argc, char * argv[] ) { INT << "===[START]==========================================" << endl; + zypp::base::shared_ptr pi; + OUT( zypp::makeResolvable( pi ) ); + + + +#if 0 /* NVRA */ zypp::base::shared_ptr pi; Package::Ptr p( makeResolvable( /*NVRA*/ pi ) ); @@ -58,6 +113,7 @@ int main( int argc, char * argv[] ) p = makeResolvable( /*NVRA*/ pi ); OUT( p ); +#endif INT << "===[END]============================================" << endl; return 0; diff --git a/test/devel.ma/Makefile.am b/test/devel.ma/Makefile.am index d4291f8..45abf23 100644 --- a/test/devel.ma/Makefile.am +++ b/test/devel.ma/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## ################################################## -noinst_PROGRAMS = Main Main.debug PtrTest Main2 +noinst_PROGRAMS = Main Main.debug PtrTest ## ################################################## @@ -15,8 +15,7 @@ LDADD = $(top_srcdir)/zypp/lib@PACKAGE@.la ## ################################################## -Main_SOURCES = Main.cc main.cc -Main2_SOURCES = main.cc Main.cc +Main_SOURCES = Main.cc Main_debug_SOURCES = $(Main_SOURCES) Main_debug_LDFLAGS = -static diff --git a/zypp/Capability.cc b/zypp/Capability.cc index ccf554f..2813488 100644 --- a/zypp/Capability.cc +++ b/zypp/Capability.cc @@ -53,11 +53,11 @@ namespace zypp std::string Capability::asString() const { return _pimpl->asString(); } - bool Capability::matches( constResolvablePtr resolvable_r, + bool Capability::matches( Resolvable::constPtr resolvable_r, const SolverContext & solverContext_r ) const { return _pimpl->matches( resolvable_r, solverContext_r ); } - bool Capability::matches( constResolvablePtr resolvable_r ) const + bool Capability::matches( Resolvable::constPtr resolvable_r ) const { return _pimpl->matches( resolvable_r, SolverContext() ); } /****************************************************************** diff --git a/zypp/Capability.h b/zypp/Capability.h index b6d2f49..8d1f92e 100644 --- a/zypp/Capability.h +++ b/zypp/Capability.h @@ -17,7 +17,7 @@ #include "zypp/base/PtrTypes.h" -#include "zypp/ResolvableFwd.h" +#include "zypp/Resolvable.h" #include "zypp/SolverContextFwd.h" /////////////////////////////////////////////////////////////////// @@ -66,10 +66,10 @@ namespace zypp /** */ std::string asString() const; /** */ - bool matches( constResolvablePtr resolvable_r, + bool matches( Resolvable::constPtr resolvable_r, const SolverContext & colverContext_r ) const; /** */ - bool matches( constResolvablePtr resolvable_r ) const; + bool matches( Resolvable::constPtr resolvable_r ) const; private: /** Pointer to implementation */ diff --git a/zypp/Message.cc b/zypp/Message.cc index b35468d..c9aec36 100644 --- a/zypp/Message.cc +++ b/zypp/Message.cc @@ -25,7 +25,7 @@ namespace zypp Message::Message( const std::string & name_r, const Edition & edition_r, const Arch & arch_r ) - : ResObject( ResKind("Message"), name_r, edition_r, arch_r ) + : ResObject( ResTraits::_kind, name_r, edition_r, arch_r ) {} /////////////////////////////////////////////////////////////////// diff --git a/zypp/Package.cc b/zypp/Package.cc index bcf77b9..1d298db 100644 --- a/zypp/Package.cc +++ b/zypp/Package.cc @@ -25,7 +25,7 @@ namespace zypp Package::Package( const std::string & name_r, const Edition & edition_r, const Arch & arch_r ) - : ResObject( ResKind("Package"), name_r, edition_r, arch_r ) + : ResObject( ResTraits::_kind, name_r, edition_r, arch_r ) {} /////////////////////////////////////////////////////////////////// diff --git a/zypp/Patch.cc b/zypp/Patch.cc index a5561bb..71cc2e2 100644 --- a/zypp/Patch.cc +++ b/zypp/Patch.cc @@ -25,7 +25,7 @@ namespace zypp Patch::Patch( const std::string & name_r, const Edition & edition_r, const Arch & arch_r ) - : ResObject( ResKind("Patch"), name_r, edition_r, arch_r ) + : ResObject( ResTraits::_kind, name_r, edition_r, arch_r ) {} /////////////////////////////////////////////////////////////////// diff --git a/zypp/Product.cc b/zypp/Product.cc index 5eb0997..8cb18d2 100644 --- a/zypp/Product.cc +++ b/zypp/Product.cc @@ -27,7 +27,7 @@ namespace zypp Product::Product( const std::string & name_r, const Edition & edition_r, const Arch & arch_r ) - : ResObject( ResKind("Product"), name_r, edition_r, arch_r ) + : ResObject( ResTraits::_kind, name_r, edition_r, arch_r ) {} /////////////////////////////////////////////////////////////////// diff --git a/zypp/Resolvable.h b/zypp/Resolvable.h index 615ef73..39feb80 100644 --- a/zypp/Resolvable.h +++ b/zypp/Resolvable.h @@ -17,7 +17,8 @@ #include "zypp/base/ReferenceCounted.h" #include "zypp/base/NonCopyable.h" -#include +#include "zypp/base/PtrTypes.h" +#include "zypp/ResTraits.h" #include "zypp/ResKind.h" #include "zypp/Edition.h" @@ -76,6 +77,11 @@ namespace zypp }; /////////////////////////////////////////////////////////////////// + + + + /////////////////////////////////////////////////////////////////// + /** Required by base::intrusive_ptr to add a reference. */ inline void intrusive_ptr_add_ref( const Resolvable * ptr_r ) { base::ReferenceCounted::add_ref( ptr_r ); } diff --git a/zypp/ResolvableFwd.h b/zypp/ResolvableFwd.h deleted file mode 100644 index e8cbbf4..0000000 --- a/zypp/ResolvableFwd.h +++ /dev/null @@ -1,31 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/ResolvableFwd.h - * -*/ -#ifndef ZYPP_RESOLVABLEFWD_H -#define ZYPP_RESOLVABLEFWD_H - -#include "zypp/base/PtrTypes.h" - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - - class ResKind; - class Edition; - class Arch; - class Dependencies; - - DEFINE_PTR_TYPE(Resolvable) - - ///////////////////////////////////////////////////////////////// -} // namespace zypp -/////////////////////////////////////////////////////////////////// -#endif // ZYPP_RESOLVABLEFWD_H diff --git a/zypp/Script.cc b/zypp/Script.cc index 432f802..d8ead2c 100644 --- a/zypp/Script.cc +++ b/zypp/Script.cc @@ -25,7 +25,7 @@ namespace zypp Script::Script( const std::string & name_r, const Edition & edition_r, const Arch & arch_r ) - : ResObject( ResKind("Script"), name_r, edition_r, arch_r ) + : ResObject( ResTraits::_kind, name_r, edition_r, arch_r ) {} /////////////////////////////////////////////////////////////////// diff --git a/zypp/Selection.cc b/zypp/Selection.cc index 431e165..fb95c98 100644 --- a/zypp/Selection.cc +++ b/zypp/Selection.cc @@ -27,7 +27,7 @@ namespace zypp Selection::Selection( const std::string & name_r, const Edition & edition_r, const Arch & arch_r ) - : ResObject( ResKind("Selection"), name_r, edition_r, arch_r ) + : ResObject( ResTraits::_kind, name_r, edition_r, arch_r ) {} /////////////////////////////////////////////////////////////////// diff --git a/zypp/capability/CapabilityImpl.h b/zypp/capability/CapabilityImpl.h index 933944b..c9d3471 100644 --- a/zypp/capability/CapabilityImpl.h +++ b/zypp/capability/CapabilityImpl.h @@ -15,7 +15,7 @@ #include "zypp/base/ReferenceCounted.h" #include "zypp/base/NonCopyable.h" -#include "zypp/ResolvableFwd.h" +#include "zypp/Resolvable.h" #include "zypp/SolverContextFwd.h" #include "zypp/ResKind.h" @@ -50,7 +50,7 @@ namespace zypp /** */ virtual std::string asString() const = 0; /** */ - virtual bool matches( constResolvablePtr resolvable_r, + virtual bool matches( Resolvable::constPtr resolvable_r, const SolverContext & colverContext_r ) const = 0; private: diff --git a/zypp/capability/NamedCap.h b/zypp/capability/NamedCap.h index 14f92f7..72c7c17 100644 --- a/zypp/capability/NamedCap.h +++ b/zypp/capability/NamedCap.h @@ -42,7 +42,7 @@ namespace zypp virtual std::string asString() const { return _name; } /** */ - virtual bool matches( constResolvablePtr resolvable_r, + virtual bool matches( Resolvable::constPtr resolvable_r, const SolverContext & colverContext_r ) const { return false; } private: diff --git a/zypp/detail/ResObjectImplIf.h b/zypp/detail/ResObjectImplIf.h index f2fd97c..a55b713 100644 --- a/zypp/detail/ResObjectImplIf.h +++ b/zypp/detail/ResObjectImplIf.h @@ -20,6 +20,8 @@ namespace zypp { ///////////////////////////////////////////////////////////////// class Resolvable; + template + class ResImplConnect; typedef std::string line; typedef std::list text; -- 2.7.4