[pygccxml-commit] SF.net SVN: pygccxml: [821] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2006-12-29 19:07:42
|
Revision: 821
http://svn.sourceforge.net/pygccxml/?rev=821&view=rev
Author: roman_yakovenko
Date: 2006-12-29 11:07:42 -0800 (Fri, 29 Dec 2006)
Log Message:
-----------
adding new use case for smart_ptr
Modified Paths:
--------------
pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp
pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp
pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/test.py
pyplusplus_dev/examples/pyboost_dev/dev/rational/generate_code.py
Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp 2006-12-28 19:40:19 UTC (rev 820)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp 2006-12-29 19:07:42 UTC (rev 821)
@@ -3,20 +3,26 @@
namespace bp = boost::python;
-// "get_pointer" function returns pointer to the object managed by smart pointer
-// class instance
+//namespace boost{
+ // "get_pointer" function returns pointer to the object managed by smart pointer
+ // class instance
-template<class T>
-inline T * get_pointer(smart_ptr_t<T> const& p){
- return p.get();
-}
+ template<class T>
+ inline T * get_pointer(smart_ptr_t<T> const& p){
+ return p.get();
+ }
-inline derived_t * get_pointer(derived_ptr_t const& p){
- return p.get();
-}
-
+ inline derived_t * get_pointer(derived_ptr_t const& p){
+ return p.get();
+ }
+//}
+
+//using boost::get_pointer;
+
namespace boost{ namespace python{
+ using boost::get_pointer;
+
// "pointee" class tells Boost.Python the type of the object managed by smart
// pointer class.
// You can read more about "pointee" class here:
@@ -34,6 +40,7 @@
} }
+
// "get_pointer" and "pointee" are needed, in order to allow Boost.Python to
// work with user defined smart pointer
@@ -116,7 +123,14 @@
bp::def( "val_get_value", &::val_get_value );
bp::def( "create_derived", &::create_derived );
bp::def( "create_base", &::create_base );
-
+
+
+ bp::class_< numeric_t, smart_ptr_t< numeric_t > >( "numeric_t" )
+ .def_readwrite( "value", &numeric_t::value );
+
+ bp::def( "create_numeric", &::create_numeric );
+ bp::def( "get_numeric_value", &::get_numeric_value );
+
// Work around for the public member variable, where type of the variable
// is smart pointer problem
bp::class_< shared_data::buffer_t >( "buffer_t" )
Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp 2006-12-28 19:40:19 UTC (rev 820)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp 2006-12-29 19:07:42 UTC (rev 821)
@@ -13,7 +13,7 @@
derived_t(){}
virtual int get_value() const{ return 0xD; }
};
-
+
// Some smart pointer classes does not have reach interface as boost ones.
// In order to provide same level of convenience, users are forced to create
// classes, which derive from smart pointer class.
@@ -94,6 +94,32 @@
return a->get_value();
}
+
+struct numeric_t{
+ numeric_t()
+ : value(0)
+ {}
+
+ int value;
+};
+
+smart_ptr_t< numeric_t > create_numeric( int value ){
+ smart_ptr_t< numeric_t > num( new numeric_t() );
+ num->value = value;
+ return num;
+}
+
+int get_numeric_value( smart_ptr_t< numeric_t > n ){
+ if( n.get() ){
+ return n->value;
+ }
+ else{
+ return 0;
+ }
+}
+
+
+
namespace shared_data{
// Boost.Python has small problem with user defined smart pointers and public
Modified: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/test.py
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/test.py 2006-12-28 19:40:19 UTC (rev 820)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/test.py 2006-12-29 19:07:42 UTC (rev 821)
@@ -68,6 +68,14 @@
self.fail("TypeError exception was not raised.")
except TypeError:
pass
+
+ def test_numeric( self ):
+ numeric = custom_sptr.create_numeric(21)
+ self.failUnless( 21 == numeric.value )
+ self.failUnless( 21 == custom_sptr.get_numeric_value(numeric) )
+ numeric = custom_sptr.numeric_t()
+ self.failUnless( 0 == numeric.value )
+ self.failUnless( 0 == custom_sptr.get_numeric_value(numeric) )
def create_suite():
suite = unittest.TestSuite()
Modified: pyplusplus_dev/examples/pyboost_dev/dev/rational/generate_code.py
===================================================================
--- pyplusplus_dev/examples/pyboost_dev/dev/rational/generate_code.py 2006-12-28 19:40:19 UTC (rev 820)
+++ pyplusplus_dev/examples/pyboost_dev/dev/rational/generate_code.py 2006-12-29 19:07:42 UTC (rev 821)
@@ -58,8 +58,8 @@
bad_rational = self.__mb.class_('bad_rational' )
bad_rational.include()
- self.__mb.free_function( 'lcm<long>' ).include()
- self.__mb.free_function( 'gcd<long>' ).include()
+ self.__mb.namespace( 'boost' ).free_function( 'lcm<long>', recursive=False ).include()
+ self.__mb.namespace( 'boost' ).free_function( 'gcd<long>', recursive=False ).include()
self.__mb.free_function( 'rational_cast<double, long>' ).include()
self.__mb.free_function( 'rational_cast<double, long>' ).alias = 'to_double'
self.__mb.free_function( 'rational_cast<long, long>' ).include()
@@ -106,4 +106,4 @@
export()
print 'done'
-
\ No newline at end of file
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|