Author: mlandres Date: Mon May 7 10:11:25 2007 New Revision: 5507 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5507&view=rev Log: fixed smart pointer output operator (prints 'NULL' or the object it points to) Modified: trunk/libzypp/zypp/base/PtrTypes.h Modified: trunk/libzypp/zypp/base/PtrTypes.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/base/PtrTypes.h?rev=5507&r1=5506&r2=5507&view=diff ============================================================================== --- trunk/libzypp/zypp/base/PtrTypes.h (original) +++ trunk/libzypp/zypp/base/PtrTypes.h Mon May 7 10:11:25 2007 @@ -97,25 +97,46 @@ /** */ using boost::dynamic_pointer_cast; - /** \relates shared_ptr Stream output. */ - template<class _D> - inline std::ostream & - operator<<( std::ostream & str, const shared_ptr<_D> & obj ) - { - if ( obj ) - return str << *obj; - return str << std::string("NULL"); - } + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +namespace std +{ ///////////////////////////////////////////////////////////////// - /** \relates intrusive_ptr Stream output. */ - template<class _D> - inline std::ostream & - operator<<( std::ostream & str, const intrusive_ptr<_D> & obj ) - { - if ( obj ) - return str << *obj; - return str << std::string("NULL"); - } + // namespace sub { + // class Foo; + // typedef zypp::intrusive_ptr<Foo> Foo_Ptr; // see DEFINE_PTR_TYPE(NAME) macro below + // } + + // Defined in namespace std g++ finds the output operator (König-Lookup), + // even if we typedef the pointer in a different namespace than ::zypp. + // Otherwise we had to define an output operator always in the same namespace + // as the typedef (else g++ will just print the pointer value). + + /** \relates zypp::shared_ptr Stream output. */ + template<class _D> + inline std::ostream & operator<<( std::ostream & str, const zypp::shared_ptr<_D> & obj ) + { + if ( obj ) + return str << *obj; + return str << std::string("NULL"); + } + + /** \relates zypp::intrusive_ptr Stream output. */ + template<class _D> + inline std::ostream & operator<<( std::ostream & str, const zypp::intrusive_ptr<_D> & obj ) + { + if ( obj ) + return str << *obj; + return str << std::string("NULL"); + } + ///////////////////////////////////////////////////////////////// +} // namespace std +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// // @@ -405,7 +426,6 @@ /////////////////////////////////////////////////////////////////// /*@}*/ - ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org