[pygccxml-commit] SF.net SVN: pygccxml: [490] pyplusplus_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-08-29 13:27:24
|
Revision: 490 Author: roman_yakovenko Date: 2006-08-29 06:27:12 -0700 (Tue, 29 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=490&view=rev Log Message: ----------- updating custom smart ptr testers Modified Paths: -------------- pyplusplus_dev/unittests/custom_smart_ptr_classes_tester.py pyplusplus_dev/unittests/data/custom_smart_ptr.h Modified: pyplusplus_dev/unittests/custom_smart_ptr_classes_tester.py =================================================================== --- pyplusplus_dev/unittests/custom_smart_ptr_classes_tester.py 2006-08-29 11:28:51 UTC (rev 489) +++ pyplusplus_dev/unittests/custom_smart_ptr_classes_tester.py 2006-08-29 13:27:12 UTC (rev 490) @@ -8,6 +8,46 @@ import unittest import fundamental_tester_base + +MODULE_SPTR_DECL_CODE = \ +""" +namespace boost{ namespace python{ + + using namespace controllers; + + controller_i* get_pointer( my_smart_ptr_t< controller_i > const& p ){ + return p.get(); + } + + template <> + struct pointee< my_smart_ptr_t< controller_i > >{ + typedef controller_i type; + }; + + + add_x_t* get_pointer( my_smart_ptr_t< add_x_t > const& p ){ + return p.get(); + } + + template <> + struct pointee< my_smart_ptr_t< add_x_t > >{ + typedef add_x_t type; + }; + + +}}// namespace boost::python converter +""" + +MODULE_SPTR_REG_CODE = \ +""" + bp::register_ptr_to_python< my_smart_ptr_t< controllers::controller_i > >(); + + bp::register_ptr_to_python< my_smart_ptr_t< controllers::add_x_t > >(); + + bp::implicitly_convertible< my_smart_ptr_t< controllers::add_x_t >, my_smart_ptr_t< controllers::controller_i > >(); + +""" + class tester_t(fundamental_tester_base.fundamental_tester_base_t): EXTENSION_NAME = 'custom_smart_ptr_classes' @@ -19,9 +59,8 @@ def customize( self, mb ): mb.classes( lambda cls: 'ptr' in cls.name).exclude() - return - cls = mb.class_( 'value_plus_x_t' ) - cls.add_registration_code( 'bp::register_ptr_to_python< boost::shared_ptr< no_init_ns::value_plus_x_t > >();', False ) + mb.add_declaration_code( MODULE_SPTR_DECL_CODE ) + mb.add_registration_code( MODULE_SPTR_REG_CODE ) def create_identity_value( self, module, v ): class identity_value_t( module.value_i ): Modified: pyplusplus_dev/unittests/data/custom_smart_ptr.h =================================================================== --- pyplusplus_dev/unittests/data/custom_smart_ptr.h 2006-08-29 11:28:51 UTC (rev 489) +++ pyplusplus_dev/unittests/data/custom_smart_ptr.h 2006-08-29 13:27:12 UTC (rev 490) @@ -18,25 +18,27 @@ : pRep(rep), pUseCount( new unsigned int(1) ) {} - my_smart_ptr_t(const my_smart_ptr_t<T>& r) + template<class Y> + my_smart_ptr_t(const my_smart_ptr_t<Y>& r) : pRep(0), pUseCount(0) { - pRep = r.pRep; - pUseCount = r.pUseCount; + pRep = r.get(); + pUseCount = r.useCountPointer(); if(pUseCount){ ++(*pUseCount); } } - my_smart_ptr_t& operator=(const my_smart_ptr_t<T>& r){ + template< class Y> + my_smart_ptr_t& operator=(const my_smart_ptr_t<Y>& r){ if( pRep == r.pRep ){ return *this; } release(); - pRep = r.pRep; - pUseCount = r.pUseCount; + pRep = r.get(); + pUseCount = r.useCountPointer(); if(pUseCount){ ++(*pUseCount); } @@ -59,16 +61,6 @@ return pRep; } - inline bool unique() const { - assert(pUseCount); - return *pUseCount == 1; - } - - inline unsigned int useCount() const { - assert(pUseCount); - return *pUseCount; - } - inline unsigned int* useCountPointer() const { return pUseCount; } @@ -77,18 +69,6 @@ return pRep; } - inline bool isNull(void) const { - return pRep == 0; - } - - inline void setNull(void) { - if (pRep){ - release(); - pRep = 0; - pUseCount = 0; - } - } - protected: inline void release(void){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |