Fix #2408232. Improve shared_ptr and intrusive_ptr wrappers for classes in an inheritance hierarchy. No special treatment is needed for derived classes, the SWIG_SHARED_PTR_DERIVED macro is deprecated.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12036 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-05-22 22:49:47 +00:00
commit 12cfc251e4
13 changed files with 124 additions and 104 deletions

View file

@ -46,8 +46,8 @@
%include <boost_intrusive_ptr.i>
SWIG_INTRUSIVE_PTR(Klass, Space::Klass)
SWIG_INTRUSIVE_PTR_NO_WRAP(KlassWithoutRefCount, Space::KlassWithoutRefCount)
SWIG_INTRUSIVE_PTR_DERIVED(KlassDerived, Space::KlassWithoutRefCount, Space::KlassDerived)
SWIG_INTRUSIVE_PTR_DERIVED(KlassDerivedDerived, Space::KlassDerived, Space::KlassDerivedDerived)
SWIG_INTRUSIVE_PTR(KlassDerived, Space::KlassDerived)
SWIG_INTRUSIVE_PTR(KlassDerivedDerived, Space::KlassDerivedDerived)
//For the use_count shared_ptr functions
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & ($*1_ltype tempnull) %{
@ -390,9 +390,7 @@ Space::Klass & GlobalReference = GlobalValue;
// Note: %template after the intrusive_ptr typemaps
SWIG_INTRUSIVE_PTR(BaseIntDouble, Base<int, double>)
// Note: cannot use Base<int, double> in the macro below because of the comma in the type,
// so we use a typedef instead. Alternatively use %arg(Base<int, double>). %arg is defined in swigmacros.swg.
SWIG_INTRUSIVE_PTR_DERIVED(PairIntDouble, BaseIntDouble_t, Pair<int, double>)
SWIG_INTRUSIVE_PTR(PairIntDouble, Pair<int, double>)
#endif
@ -409,7 +407,6 @@ template <class T1, class T2> struct Base {
void release(void) const { if (--count == 0) delete this; }
int use_count(void) const { return count; }
};
typedef Base<int, double> BaseIntDouble_t;
%}
%template(BaseIntDouble) Base<int, double>;

View file

@ -42,15 +42,9 @@
%include <boost_shared_ptr.i>
SWIG_SHARED_PTR(Klass, Space::Klass)
SWIG_SHARED_PTR_DERIVED(KlassDerived, Space::Klass, Space::KlassDerived)
SWIG_SHARED_PTR_DERIVED(Klass2ndDerived, Space::Klass, Space::Klass2ndDerived)
SWIG_SHARED_PTR_DERIVED(Klass3rdDerived, Space::Klass2ndDerived, Space::Klass3rdDerived)
// TEMP for python
%types(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< Space::Klass3rdDerived > = SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< Space::Klass >) {
*newmemory = SWIG_CAST_NEW_MEMORY;
return (void *) new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< Space::Klass >(*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< Space::Klass3rdDerived > *)$from);
}
SWIG_SHARED_PTR(KlassDerived, Space::KlassDerived)
SWIG_SHARED_PTR(Klass2ndDerived, Space::Klass2ndDerived)
SWIG_SHARED_PTR(Klass3rdDerived, Space::Klass3rdDerived)
#endif
@ -324,9 +318,7 @@ Space::Klass & GlobalReference = GlobalValue;
// Note: %template after the shared_ptr typemaps
SWIG_SHARED_PTR(BaseIntDouble, Base<int, double>)
// Note: cannot use Base<int, double> in the macro below because of the comma in the type,
// so we use a typedef instead. Alternatively use %arg(Base<int, double>). %arg is defined in swigmacros.swg.
SWIG_SHARED_PTR_DERIVED(PairIntDouble, BaseIntDouble_t, Pair<int, double>)
SWIG_SHARED_PTR(PairIntDouble, Pair<int, double>)
#endif
@ -339,7 +331,6 @@ template <class T1, class T2> struct Base {
Base(T1 t1, T2 t2) : baseVal1(t1*2), baseVal2(t2*2) {}
virtual std::string getValue() const { return "Base<>"; };
};
typedef Base<int, double> BaseIntDouble_t;
%}
%template(BaseIntDouble) Base<int, double>;