Revision: 639
http://svn.sourceforge.net/pygccxml/?rev=639&view=rev
Author: roman_yakovenko
Date: 2006-10-10 06:26:42 -0700 (Tue, 10 Oct 2006)
Log Message:
-----------
moving smart_ptrs from unittests directory to documentation
Modified Paths:
--------------
pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest
Added Paths:
-----------
pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/
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/smart_ptr.h
Removed 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/smart_ptr.h
Modified: pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest 2006-10-10 13:18:29 UTC (rev 638)
+++ pyplusplus_dev/docs/bpl_lessons_learned/lessons_learned.rest 2006-10-10 13:26:42 UTC (rev 639)
@@ -21,7 +21,7 @@
solution contains source code and comprehensive unit test for the problem.
-.. _`Custom smart pointer class` : ./smart_ptr/smart_ptr.html
+.. _`Custom smart pointer class` : ./smart_ptrs/smart_ptrs.html
.. _`Py++` : ./../pyplusplus.html
Copied: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs (from rev 635, pyplusplus_dev/unittests/smart_ptrs)
Deleted: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp
===================================================================
--- pyplusplus_dev/unittests/smart_ptrs/bindings.cpp 2006-10-09 21:44:47 UTC (rev 635)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp 2006-10-10 13:26:42 UTC (rev 639)
@@ -1,98 +0,0 @@
-// This file has been generated by Py++.
-
-// Copyright 2004 Roman Yakovenko.
-// Distributed under the Boost Software License, Version 1.0. (See
-// accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-
-#include "boost/python.hpp"
-#include "classes.hpp"
-
-namespace bp = boost::python;
-
-namespace boost{ namespace python{
-
- template<class T>
- inline T * get_pointer(smart_ptr_t<T> const& p){
- return p.get();
- }
-
- template <class T>
- struct pointee< smart_ptr_t<T> >{
- 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;
- };
-
-} }
-
-
-struct base_wrapper_t : base_i, bp::wrapper< base_i > {
-
- base_wrapper_t()
- : base_i(), bp::wrapper< base_i >()
- {}
-
- virtual int get_value( ) const {
- bp::override func_get_value = this->get_override( "get_value" );
- return func_get_value( );
- }
-
-};
-
-struct derived_wrapper_t : derived_t, bp::wrapper< derived_t > {
-
- derived_wrapper_t()
- : derived_t(), bp::wrapper< derived_t >()
- {}
-
- derived_wrapper_t(const derived_t& d)
- : derived_t(d), bp::wrapper< derived_t >()
- {}
-
- derived_wrapper_t(const derived_wrapper_t&)
- : derived_t(), bp::wrapper< derived_t >()
- {}
-
- virtual int get_value() const {
- if( bp::override func_get_value = this->get_override( "get_value" ) )
- return func_get_value( );
- else
- return derived_t::get_value( );
- }
-
- int default_get_value() const {
- return derived_t::get_value( );
- }
-
-};
-
-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 ) );
-
- bp::implicitly_convertible< smart_ptr_t< base_wrapper_t >, smart_ptr_t< base_i > >();
- bp::register_ptr_to_python< smart_ptr_t< base_i > >();
-
- bp::class_< derived_wrapper_t, bp::bases< base_i >, smart_ptr_t<derived_wrapper_t> >( "derived_t" )
- .def( "get_value", &derived_t::get_value, &derived_wrapper_t::default_get_value );
-
- 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 > >();
- bp::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 );
- bp::def( "create_base", &::create_base );
-}
Copied: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp (from rev 637, pyplusplus_dev/unittests/smart_ptrs/bindings.cpp)
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/bindings.cpp 2006-10-10 13:26:42 UTC (rev 639)
@@ -0,0 +1,96 @@
+// Copyright 2004 Roman Yakovenko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "boost/python.hpp"
+#include "classes.hpp"
+
+namespace bp = boost::python;
+
+namespace boost{ namespace python{
+
+ template<class T>
+ inline T * get_pointer(smart_ptr_t<T> const& p){
+ return p.get();
+ }
+
+ template <class T>
+ struct pointee< smart_ptr_t<T> >{
+ 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;
+ };
+
+} }
+
+
+struct base_wrapper_t : base_i, bp::wrapper< base_i > {
+
+ base_wrapper_t()
+ : base_i(), bp::wrapper< base_i >()
+ {}
+
+ virtual int get_value( ) const {
+ bp::override func_get_value = this->get_override( "get_value" );
+ return func_get_value( );
+ }
+
+};
+
+struct derived_wrapper_t : derived_t, bp::wrapper< derived_t > {
+
+ derived_wrapper_t()
+ : derived_t(), bp::wrapper< derived_t >()
+ {}
+
+ derived_wrapper_t(const derived_t& d)
+ : derived_t(d), bp::wrapper< derived_t >()
+ {}
+
+ derived_wrapper_t(const derived_wrapper_t&)
+ : derived_t(), bp::wrapper< derived_t >()
+ {}
+
+ virtual int get_value() const {
+ if( bp::override func_get_value = this->get_override( "get_value" ) )
+ return func_get_value( );
+ else
+ return derived_t::get_value( );
+ }
+
+ int default_get_value() const {
+ return derived_t::get_value( );
+ }
+
+};
+
+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 ) );
+
+ bp::implicitly_convertible< smart_ptr_t< base_wrapper_t >, smart_ptr_t< base_i > >();
+ bp::register_ptr_to_python< smart_ptr_t< base_i > >();
+
+ bp::class_< derived_wrapper_t, bp::bases< base_i >, smart_ptr_t<derived_wrapper_t> >( "derived_t" )
+ .def( "get_value", &derived_t::get_value, &derived_wrapper_t::default_get_value );
+
+ 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 > >();
+ bp::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 );
+ bp::def( "create_base", &::create_base );
+}
Deleted: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp
===================================================================
--- pyplusplus_dev/unittests/smart_ptrs/classes.hpp 2006-10-09 21:44:47 UTC (rev 635)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp 2006-10-10 13:26:42 UTC (rev 639)
@@ -1,91 +0,0 @@
-#include "smart_ptr.h"
-
-struct base_i{
-public:
- virtual ~base_i() { }
- virtual int get_value() const = 0;
-};
-
-
-struct derived_t : base_i{
- derived_t()
- {}
-
- virtual int get_value() const{
- return 11;
- }
-};
-
-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() );
-}
-
-smart_ptr_t< base_i > create_base(){
- return smart_ptr_t< base_i >( 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
-//Python object for the reference to bind to. The rules are the same as in C++:
-//
-// int f(smart_ptr_t<base_i>& x) { return 0; }
-// smart_ptr_t<base_wrapper_t> y;
-// int z = f(y); // fails to compile
-
-inline int
-ref_get_value( smart_ptr_t< base_i >& a ){
- return a->get_value();
-}
-
-inline int
-val_get_value( smart_ptr_t< base_i > a ){
- return a->get_value();
-}
-
-inline int
-const_ref_get_value( const smart_ptr_t< base_i >& a ){
- return a->get_value();
-}
Copied: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp (from rev 637, pyplusplus_dev/unittests/smart_ptrs/classes.hpp)
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/classes.hpp 2006-10-10 13:26:42 UTC (rev 639)
@@ -0,0 +1,91 @@
+#include "smart_ptr.h"
+
+struct base_i{
+public:
+ virtual ~base_i() { }
+ virtual int get_value() const = 0;
+};
+
+
+struct derived_t : base_i{
+ derived_t()
+ {}
+
+ virtual int get_value() const{
+ return 11;
+ }
+};
+
+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() );
+}
+
+smart_ptr_t< base_i > create_base(){
+ return smart_ptr_t< base_i >( 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
+//Python object for the reference to bind to. The rules are the same as in C++:
+//
+// int f(smart_ptr_t<base_i>& x) { return 0; }
+// smart_ptr_t<base_wrapper_t> y;
+// int z = f(y); // fails to compile
+
+inline int
+ref_get_value( smart_ptr_t< base_i >& a ){
+ return a->get_value();
+}
+
+inline int
+val_get_value( smart_ptr_t< base_i > a ){
+ return a->get_value();
+}
+
+inline int
+const_ref_get_value( const smart_ptr_t< base_i >& a ){
+ return a->get_value();
+}
Deleted: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptr.h
===================================================================
--- pyplusplus_dev/unittests/smart_ptrs/smart_ptr.h 2006-10-09 21:44:47 UTC (rev 635)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptr.h 2006-10-10 13:26:42 UTC (rev 639)
@@ -1,121 +0,0 @@
-#ifndef smart_ptr_t_19_09_2006
-#define smart_ptr_t_19_09_2006
-
-#include <assert.h>
-
-template<class T> class smart_ptr_t {
-protected:
- T* pRep;
- unsigned int* pUseCount;
-public:
-
- smart_ptr_t()
- : pRep(0), pUseCount(0)
- {}
-
- //What will happen if rep is NULL? -> bug
- explicit smart_ptr_t(T* rep)
- : pRep(rep), pUseCount( new unsigned int(1) )
- {}
-
- smart_ptr_t(const smart_ptr_t& r)
- : pRep(0), pUseCount(0)
- {
- pRep = r.get();
- pUseCount = r.useCountPointer();
- if(pUseCount){
- ++(*pUseCount);
- }
- }
-
- smart_ptr_t& operator=(const smart_ptr_t& r){
- if( pRep == r.pRep ){
- return *this;
- }
-
- release();
-
- pRep = r.get();
- pUseCount = r.useCountPointer();
- if(pUseCount){
- ++(*pUseCount);
- }
- return *this;
- }
-
-
- template<class Y>
- smart_ptr_t(const smart_ptr_t<Y>& r)
- : pRep(0), pUseCount(0)
- {
- pRep = r.get();
- pUseCount = r.useCountPointer();
- if(pUseCount){
- ++(*pUseCount);
- }
- }
-
- template< class Y>
- smart_ptr_t& operator=(const smart_ptr_t<Y>& r){
- if( pRep == r.pRep ){
- return *this;
- }
-
- release();
-
- pRep = r.get();
- pUseCount = r.useCountPointer();
- if(pUseCount){
- ++(*pUseCount);
- }
- return *this;
- }
-
- virtual ~smart_ptr_t() {
- release();
- }
-
- inline T& operator*() const {
- assert(pRep); return *pRep;
- }
-
- inline T* operator->() const {
- assert(pRep); return pRep;
- }
-
- inline T* get() const {
- return pRep;
- }
-
- inline unsigned int* useCountPointer() const {
- return pUseCount;
- }
-
- inline T* getPointer() const {
- return pRep;
- }
-
-protected:
-
- inline void release(void){
- bool destroyThis = false;
-
- if( pUseCount ){
- if( --(*pUseCount) == 0){
- destroyThis = true;
- }
- }
- if (destroyThis){
- destroy();
- }
- }
-
- virtual void destroy(void){
- delete pRep;
- delete pUseCount;
- }
-};
-
-
-#endif //smart_ptr_t_19_09_2006
-
Copied: pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptr.h (from rev 637, pyplusplus_dev/unittests/smart_ptrs/smart_ptr.h)
===================================================================
--- pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptr.h (rev 0)
+++ pyplusplus_dev/docs/bpl_lessons_learned/smart_ptrs/smart_ptr.h 2006-10-10 13:26:42 UTC (rev 639)
@@ -0,0 +1,121 @@
+#ifndef smart_ptr_t_19_09_2006
+#define smart_ptr_t_19_09_2006
+
+#include <assert.h>
+
+template<class T> class smart_ptr_t {
+protected:
+ T* pRep;
+ unsigned int* pUseCount;
+public:
+
+ smart_ptr_t()
+ : pRep(0), pUseCount(0)
+ {}
+
+ //What will happen if rep is NULL? -> bug
+ explicit smart_ptr_t(T* rep)
+ : pRep(rep), pUseCount( new unsigned int(1) )
+ {}
+
+ smart_ptr_t(const smart_ptr_t& r)
+ : pRep(0), pUseCount(0)
+ {
+ pRep = r.get();
+ pUseCount = r.useCountPointer();
+ if(pUseCount){
+ ++(*pUseCount);
+ }
+ }
+
+ smart_ptr_t& operator=(const smart_ptr_t& r){
+ if( pRep == r.pRep ){
+ return *this;
+ }
+
+ release();
+
+ pRep = r.get();
+ pUseCount = r.useCountPointer();
+ if(pUseCount){
+ ++(*pUseCount);
+ }
+ return *this;
+ }
+
+
+ template<class Y>
+ smart_ptr_t(const smart_ptr_t<Y>& r)
+ : pRep(0), pUseCount(0)
+ {
+ pRep = r.get();
+ pUseCount = r.useCountPointer();
+ if(pUseCount){
+ ++(*pUseCount);
+ }
+ }
+
+ template< class Y>
+ smart_ptr_t& operator=(const smart_ptr_t<Y>& r){
+ if( pRep == r.pRep ){
+ return *this;
+ }
+
+ release();
+
+ pRep = r.get();
+ pUseCount = r.useCountPointer();
+ if(pUseCount){
+ ++(*pUseCount);
+ }
+ return *this;
+ }
+
+ virtual ~smart_ptr_t() {
+ release();
+ }
+
+ inline T& operator*() const {
+ assert(pRep); return *pRep;
+ }
+
+ inline T* operator->() const {
+ assert(pRep); return pRep;
+ }
+
+ inline T* get() const {
+ return pRep;
+ }
+
+ inline unsigned int* useCountPointer() const {
+ return pUseCount;
+ }
+
+ inline T* getPointer() const {
+ return pRep;
+ }
+
+protected:
+
+ inline void release(void){
+ bool destroyThis = false;
+
+ if( pUseCount ){
+ if( --(*pUseCount) == 0){
+ destroyThis = true;
+ }
+ }
+ if (destroyThis){
+ destroy();
+ }
+ }
+
+ virtual void destroy(void){
+ delete pRep;
+ delete pUseCount;
+ }
+};
+
+
+#endif //smart_ptr_t_19_09_2006
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|