[pygccxml-commit] SF.net SVN: pygccxml: [560] pyplusplus_dev/unittests/smart_ptrs
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-09-20 06:03:02
|
Revision: 560 http://svn.sourceforge.net/pygccxml/?rev=560&view=rev Author: roman_yakovenko Date: 2006-09-19 23:02:54 -0700 (Tue, 19 Sep 2006) Log Message: ----------- adding new use case for smart ptr Modified Paths: -------------- pyplusplus_dev/unittests/smart_ptrs/bindings.cpp pyplusplus_dev/unittests/smart_ptrs/classes.hpp pyplusplus_dev/unittests/smart_ptrs/test.py Modified: pyplusplus_dev/unittests/smart_ptrs/bindings.cpp =================================================================== --- pyplusplus_dev/unittests/smart_ptrs/bindings.cpp 2006-09-19 20:42:37 UTC (rev 559) +++ pyplusplus_dev/unittests/smart_ptrs/bindings.cpp 2006-09-20 06:02:54 UTC (rev 560) @@ -22,6 +22,16 @@ typedef T type; }; + + inline derived_t * get_pointer(derived_ptr_t const& p){ + return p.get(); + } + + template<> + struct pointee< derived_ptr_t >{ + typedef derived_t type; + }; + } } @@ -65,7 +75,6 @@ }; - BOOST_PYTHON_MODULE( custom_sptr ){ bp::class_< base_wrapper_t, boost::noncopyable, smart_ptr_t< base_wrapper_t > >( "base_i" ) .def( "get_value", bp::pure_virtual( &base_i::get_value ) ); @@ -77,9 +86,11 @@ bp::implicitly_convertible< smart_ptr_t< derived_wrapper_t >, smart_ptr_t< derived_t > >(); bp::implicitly_convertible< smart_ptr_t< derived_t >, smart_ptr_t< base_i > >(); + bp::implicitly_convertible< derived_ptr_t, smart_ptr_t< derived_t > >(); + boost::python::register_ptr_to_python< derived_ptr_t >(); bp::def( "const_ref_get_value", &::const_ref_get_value ); bp::def( "ref_get_value", &::ref_get_value ); bp::def( "val_get_value", &::val_get_value ); - + bp::def( "create_derived", &::create_derived ); } Modified: pyplusplus_dev/unittests/smart_ptrs/classes.hpp =================================================================== --- pyplusplus_dev/unittests/smart_ptrs/classes.hpp 2006-09-19 20:42:37 UTC (rev 559) +++ pyplusplus_dev/unittests/smart_ptrs/classes.hpp 2006-09-20 06:02:54 UTC (rev 560) @@ -16,6 +16,51 @@ } }; +struct derived_ptr_t : public smart_ptr_t< derived_t >{ + + derived_ptr_t() + : smart_ptr_t< derived_t >() + {} + + explicit derived_ptr_t(derived_t* rep) + : smart_ptr_t<derived_t>(rep) + {} + + derived_ptr_t(const derived_ptr_t& r) + : smart_ptr_t<derived_t>(r) {} + + derived_ptr_t( const smart_ptr_t< base_i >& r) + : smart_ptr_t<derived_t>() + { + pRep = static_cast<derived_t*>(r.getPointer()); + pUseCount = r.useCountPointer(); + if (pUseCount) + { + ++(*pUseCount); + } + } + + derived_ptr_t& operator=(const smart_ptr_t< base_i >& r) + { + if (pRep == static_cast<derived_t*>(r.getPointer())) + return *this; + release(); + pRep = static_cast<derived_t*>(r.getPointer()); + pUseCount = r.useCountPointer(); + if (pUseCount) + { + ++(*pUseCount); + } + + return *this; + } +}; + + +derived_ptr_t create_derived(){ + return derived_ptr_t( new derived_t() ); +} + //Next function could be exposed, but it could not be solved //This is the explanation David Abrahams gave: //Naturally; there is no instance of smart_ptr_t<base_i> anywhere in the Modified: pyplusplus_dev/unittests/smart_ptrs/test.py =================================================================== --- pyplusplus_dev/unittests/smart_ptrs/test.py 2006-09-19 20:42:37 UTC (rev 559) +++ pyplusplus_dev/unittests/smart_ptrs/test.py 2006-09-20 06:02:54 UTC (rev 560) @@ -43,9 +43,11 @@ def test_py_derived( self ): self.__test_impl( py_derived_t(), 28 ) - def test_py_double_derived_t( self ): + def test_py_double_derived( self ): self.__test_impl( py_double_derived_t(), 31 ) + def test_created_derived( self ): + self.__test_impl( custom_sptr.create_derived(), 11 ) def create_suite(): suite = unittest.TestSuite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |