Revision: 737
http://svn.sourceforge.net/pygccxml/?rev=737&view=rev
Author: roman_yakovenko
Date: 2006-11-20 12:20:17 -0800 (Mon, 20 Nov 2006)
Log Message:
-----------
testing solution and making it work
Modified Paths:
--------------
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py
Modified: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct 2006-11-20 13:27:21 UTC (rev 736)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/sconstruct 2006-11-20 20:20:17 UTC (rev 737)
@@ -1,6 +1,6 @@
#scons build script
-SharedLibrary( target=r'custom_sptr'
- , source=[ r'bindings.cpp' ]
+SharedLibrary( target=r'shared_ptr'
+ , source=[ r'solution.cpp' ]
, LIBS=[ r"boost_python" ]
, LIBPATH=[ r"/home/roman/boost_cvs/bin",r"" ]
, CPPPATH=[ r"/home/roman/boost_cvs"
Modified: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp 2006-11-20 13:27:21 UTC (rev 736)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/solution.cpp 2006-11-20 20:20:17 UTC (rev 737)
@@ -1,9 +1,24 @@
#include "boost/python.hpp"
-#include "boost/shared_ptr.hpp"
#include <string>
-//Your code:
+namespace boost{
+
+ template<class T>
+ inline T* get_pointer( boost::shared_ptr<const T> const& p ){
+ return const_cast< T* >( p.get() );
+ }
+}
+
+namespace boost{ namespace python{
+
+ template<class T>
+ struct pointee< boost::shared_ptr<T const> >{
+ typedef T type;
+ };
+
+} } //boost::python
+
struct info_t{
//class info_t records in what function it was created information
info_t( const std::string& n )
@@ -17,11 +32,11 @@
typedef boost::shared_ptr< const info_t > const_ptr_t;
ptr_t create_ptr(){
- return ptr_t( new fruit( "ptr" ) );
+ return ptr_t( new info_t( "ptr" ) );
}
const_ptr_t create_const_ptr(){
- return const_ptr_t( new fruit( "const ptr" ) );
+ return const_ptr_t( new info_t( "const ptr" ) );
}
std::string read_ptr( ptr_t x ){
@@ -36,27 +51,12 @@
return x->text;
}
-
-namespace boost{ namespace python{
-
- template<class T>
- inline T* get_pointer( boost::shared_ptr<const T> const& p ){
- return const_cast<T*>(p.get());
- }
-
- template<class T>
- struct pointee< boost::shared_ptr<const T> >{
- typedef T type;
- };
-
-} } //boost::python
-
namespace bpl = boost::python;
namespace utils{
template< class T >
- register_shared_ptrs_to_python(){
+ void register_shared_ptrs_to_python(){
//small helper function, which will register shared_ptr conversions
bpl::register_ptr_to_python< boost::shared_ptr< T > >();
bpl::register_ptr_to_python< boost::shared_ptr< const T > >();
@@ -66,8 +66,9 @@
}
BOOST_PYTHON_MODULE( shared_ptr ){
- bpl::class_< fruit >( "fruit", bp::init< std::string >() );
- utils::register_shared_ptrs_to_python< fruit >();
+ bpl::class_< info_t >( "info_t", bpl::init< std::string >() )
+ .add_property( "text", &info_t::text );
+ utils::register_shared_ptrs_to_python< info_t >();
bpl::def( "create_ptr", &create_ptr );
bpl::def( "create_const_ptr", &create_const_ptr );
Modified: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py 2006-11-20 13:27:21 UTC (rev 736)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/test.py 2006-11-20 20:20:17 UTC (rev 737)
@@ -8,13 +8,14 @@
def test( self ):
ptr = shared_ptr.create_ptr()
- self.failUnless( ptr.name == "ptr" )
+ self.failUnless( ptr.text == "ptr" )
self.failUnless( shared_ptr.read_ptr( ptr ) == "ptr" )
const_ptr = shared_ptr.create_const_ptr()
- self.failUnless( const_ptr.name == "const ptr" )
+ self.failUnless( const_ptr.text == "const ptr" )
self.failUnless( shared_ptr.read_const_ptr( const_ptr ) == "const ptr" )
+ #testing conversion functionality
self.failUnless( shared_ptr.read_const_ptr( ptr ) == "ptr" )
def create_suite():
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|