Revision: 809
http://svn.sourceforge.net/pygccxml/?rev=809&view=rev
Author: roman_yakovenko
Date: 2006-12-20 22:27:28 -0800 (Wed, 20 Dec 2006)
Log Message:
-----------
adding doc
Modified Paths:
--------------
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/shared_ptr.rest
Added Paths:
-----------
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/pointer_holder.hpp.patch
pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/pointer_holder.hpp.patch.rest
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/pointer_holder.hpp.patch
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/pointer_holder.hpp.patch (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/pointer_holder.hpp.patch 2006-12-21 06:27:28 UTC (rev 809)
@@ -0,0 +1,99 @@
+*** pointer_holder.hpp.orig 2006-11-24 22:39:59.000000000 +0200
+--- pointer_holder.hpp 2006-12-08 20:05:58.000000000 +0200
+***************
+*** 35,40 ****
+--- 35,42 ----
+
+ # include <boost/detail/workaround.hpp>
+
++ # include <boost/type_traits/remove_const.hpp>
++
+ namespace boost { namespace python {
+
+ template <class T> class wrapper;
+***************
+*** 122,146 ****
+ template <class Pointer, class Value>
+ void* pointer_holder<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
+ {
+ if (dst_t == python::type_id<Pointer>()
+ && !(null_ptr_only && get_pointer(this->m_p))
+ )
+ return &this->m_p;
+!
+! Value* p = get_pointer(this->m_p);
+ if (p == 0)
+ return 0;
+
+ if (void* wrapped = holds_wrapped(dst_t, p, p))
+ return wrapped;
+
+! type_info src_t = python::type_id<Value>();
+ return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
+ }
+
+ template <class Pointer, class Value>
+ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
+ {
+ if (dst_t == python::type_id<Pointer>()
+ && !(null_ptr_only && get_pointer(this->m_p))
+ )
+--- 124,153 ----
+ template <class Pointer, class Value>
+ void* pointer_holder<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
+ {
++ typedef typename boost::remove_const< Value >::type NonConstValue;
++
+ if (dst_t == python::type_id<Pointer>()
+ && !(null_ptr_only && get_pointer(this->m_p))
+ )
+ return &this->m_p;
+!
+! Value* tmp = get_pointer(this->m_p);
+! NonConstValue* p = const_cast<NonConstValue*>( tmp );
+ if (p == 0)
+ return 0;
+
+ if (void* wrapped = holds_wrapped(dst_t, p, p))
+ return wrapped;
+
+! type_info src_t = python::type_id<NonConstValue>();
+ return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
+ }
+
+ template <class Pointer, class Value>
+ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
+ {
++ typedef typename boost::remove_const< Value >::type NonConstValue;
++
+ if (dst_t == python::type_id<Pointer>()
+ && !(null_ptr_only && get_pointer(this->m_p))
+ )
+***************
+*** 149,160 ****
+ if (!get_pointer(this->m_p))
+ return 0;
+
+! Value* p = get_pointer(m_p);
+
+ if (dst_t == python::type_id<held_type>())
+ return p;
+
+! type_info src_t = python::type_id<Value>();
+ return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
+ }
+
+--- 156,168 ----
+ if (!get_pointer(this->m_p))
+ return 0;
+
+! Value* tmp = get_pointer(this->m_p);
+! NonConstValue* p = const_cast<NonConstValue*>( tmp );
+
+ if (dst_t == python::type_id<held_type>())
+ return p;
+
+! type_info src_t = python::type_id<NonConstValue>();
+ return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
+ }
+
Added: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/pointer_holder.hpp.patch.rest
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/pointer_holder.hpp.patch.rest (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/pointer_holder.hpp.patch.rest 2006-12-21 06:27:28 UTC (rev 809)
@@ -0,0 +1,3 @@
+.. code-block::
+ :language: diff
+ :source-file: ./pointer_holder.hpp.patch
Modified: pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/shared_ptr.rest
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/shared_ptr.rest 2006-12-21 05:44:30 UTC (rev 808)
+++ pyplusplus_dev/docs/bpl_lessons_learned/shared_ptr/shared_ptr.rest 2006-12-21 06:27:28 UTC (rev 809)
@@ -10,46 +10,57 @@
.. include:: ./definition.rest
---------
-Solution
---------
+---------
+Solutions
+---------
-The solution is pretty simple:
+There are two possible solutions to the problem. The first one is to fix
+Boost.Python library: `pointer_holder.hpp.patch`_ . The patch was contributed
+to the library ( 8-December-2006 ) and some day it will be commited to the CVS.
+It is also possible to solve the problem, without changing Boost.Python library:
+
.. code-block:: C++
- namespace boost{ namespace python{
+ 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
- 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 utils{
-
- template< class T >
- register_shared_ptrs_to_python(){
- namespace bpl = boost::python;
- bpl::register_ptr_to_python< boost::shared_ptr< T > >();
- bpl::register_ptr_to_python< boost::shared_ptr< const T > >();
- bpl::implicitly_convertible< boost::shared_ptr< T >, boost::shared_ptr< const T > >();
- }
-
- }
-
- BOOST_PYTHON_MODULE(...){
- class_< YourClass >( "YourClass" )
- ...;
- utils::register_shared_ptrs_to_python< YourClass >();
- }
+ namespace utils{
+
+ template< class T >
+ register_shared_ptrs_to_python(){
+ namespace bpl = boost::python;
+ bpl::register_ptr_to_python< boost::shared_ptr< T > >();
+ bpl::register_ptr_to_python< boost::shared_ptr< const T > >();
+ bpl::implicitly_convertible< boost::shared_ptr< T >, boost::shared_ptr< const T > >();
+ }
+
+ }
+
+ BOOST_PYTHON_MODULE(...){
+ class_< YourClass >( "YourClass" )
+ ...;
+ utils::register_shared_ptrs_to_python< YourClass >();
+ }
+The second approach is a little bit "evil" because it redefines ``get_pointer``
+function for all shared pointer classes. So you should be careful.
+
Files
-----
@@ -62,11 +73,14 @@
* `test.py`_ file contains complete unit tests for the exposed classes
+* `pointer_holder.hpp.patch`_ file contains patch for the library
+
All files contain comments, which describe what and why was done.
-.. _`solution.cpp` : ./solution.hpp.html
+.. _`solution.cpp` : ./solution.cpp.html
.. _`sconstruct` : ./sconstruct.html
.. _`test.py` : ./test.py.html
+.. _`pointer_holder.hpp.patch` : ./pointer_holder.hpp.patch.html
--------
Download
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|