ResObjectFactory.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_DETAIL_RESOBJECTFACTORY_H
00013 #define ZYPP_DETAIL_RESOBJECTFACTORY_H
00014 
00015 #include "zypp/detail/ResImplTraits.h"
00016 #include "zypp/NVRAD.h"
00017 
00019 namespace zypp
00020 { 
00021 
00022   class Edition;
00023   class Arch;
00024   struct NVRAD;
00025 
00027   namespace detail
00028   { 
00029 
00030     namespace _resobjectfactory_detail
00031     { 
00032 
00034       template<class _Res>
00035         class ResImplConnect : public _Res
00036         {
00037         public:
00038           typedef ResImplConnect                    Self;
00039           typedef typename _Res::Impl               Impl;
00040           typedef typename ResImplTraits<Impl>::Ptr Impl_Ptr;
00041         public:
00043           ResImplConnect( const NVRAD & nvrad_r,
00044                           Impl_Ptr impl_r )
00045           : _Res( nvrad_r )
00046           , _impl( impl_r )
00047           { _impl->_backRef = this; }
00048 
00049           virtual ~ResImplConnect()
00050           { _impl->_backRef = 0; }
00051 
00052         private:
00053           Impl_Ptr _impl;
00054           virtual Impl &       pimpl()       { return *_impl; }
00055           virtual const Impl & pimpl() const { return *_impl; }
00056         };
00057 
00059     } // namespace _resobjectfactory
00061 
00062     template<class _Impl>
00063       typename _Impl::ResType::Ptr
00064       makeResolvableAndImpl( const NVRAD & nvrad_r,
00065                              intrusive_ptr<_Impl> & impl_r )
00066       {
00067         impl_r = new _Impl;
00068         return new
00069                _resobjectfactory_detail::ResImplConnect<typename _Impl::ResType>
00070                ( nvrad_r, impl_r );
00071       }
00072 
00073     template<class _Impl>
00074       typename _Impl::ResType::Ptr
00075       makeResolvableFromImpl( const NVRAD & nvrad_r,
00076                               intrusive_ptr<_Impl> impl_r )
00077       {
00078         if ( ! impl_r )
00079           throw ( "makeResolvableFromImpl: NULL Impl " );
00080         if ( impl_r->hasBackRef() )
00081           throw ( "makeResolvableFromImpl: Impl already managed" );
00082         return new
00083                _resobjectfactory_detail::ResImplConnect<typename _Impl::ResType>
00084                ( nvrad_r, impl_r );
00085       }
00086 
00088   } // namespace detail
00091 } // namespace zypp
00093 #endif // ZYPP_DETAIL_RESOBJECTFACTORY_H

Generated on Thu Jul 6 00:07:20 2006 for zypp by  doxygen 1.4.6