diff --git a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs index 27bc4628f..6ded989b5 100644 --- a/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs +++ b/Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs @@ -345,6 +345,16 @@ public class runme verifyCount(1, kret); } + // 3rd derived class + { + Klass k = new Klass3rdDerived("me oh my"); + String val = k.getValue(); + verifyValue("me oh my-3rdDerived", val); + verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values + val = li_boost_shared_ptr.test3rdupcast(k); + verifyValue("me oh my-3rdDerived", val); + verifyCount(3, k); + } ////////////////////////////////// Member variables //////////////////////////////////////// // smart pointer by value diff --git a/Examples/test-suite/java/li_boost_shared_ptr_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_runme.java index a699222e5..02d6d6502 100644 --- a/Examples/test-suite/java/li_boost_shared_ptr_runme.java +++ b/Examples/test-suite/java/li_boost_shared_ptr_runme.java @@ -357,6 +357,16 @@ public class li_boost_shared_ptr_runme { verifyCount(1, kret); } + // 3rd derived class + { + Klass k = new Klass3rdDerived("me oh my"); + String val = k.getValue(); + verifyValue("me oh my-3rdDerived", val); + verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values + val = li_boost_shared_ptr.test3rdupcast(k); + verifyValue("me oh my-3rdDerived", val); + verifyCount(3, k); + } ////////////////////////////////// Member variables //////////////////////////////////////// // smart pointer by value diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index a6225410b..f992a3c08 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -43,6 +43,14 @@ %include 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); +} #endif @@ -101,7 +109,13 @@ private: }; SwigExamples::CriticalSection Space::Klass::critical_section; -struct IgnoredMultipleInheritBase { virtual ~IgnoredMultipleInheritBase() {} double d; double e;}; +struct IgnoredMultipleInheritBase { + IgnoredMultipleInheritBase() : d(0.0), e(0.0) {} + virtual ~IgnoredMultipleInheritBase() {} + double d; + double e; + virtual void AVirtualMethod() {} +}; // For most compilers, this use of multiple inheritance results in different derived and base class // pointer values ... for some more challenging tests :) @@ -142,7 +156,21 @@ SwigBoost::shared_ptr*& derivedsmartptrpointerreftest(SwigBoost::s return kd; } +// 3 classes in inheritance chain test +struct Klass2ndDerived : Klass { + Klass2ndDerived() : Klass() {} + Klass2ndDerived(const std::string &val) : Klass(val) {} +}; +struct Klass3rdDerived : IgnoredMultipleInheritBase, Klass2ndDerived { + Klass3rdDerived() : Klass2ndDerived() {} + Klass3rdDerived(const std::string &val) : Klass2ndDerived(val) {} + virtual ~Klass3rdDerived() {} + virtual std::string getValue() const { return Klass2ndDerived::getValue() + "-3rdDerived"; } +}; +std::string test3rdupcast( SwigBoost::shared_ptr< Klass > k) { + return k->getValue(); +} @@ -217,8 +245,14 @@ SwigBoost::shared_ptr* smartpointerpointerownertest() { return new SwigBoost::shared_ptr(new Klass("smartpointerpointerownertest")); } -// Provide overloads for Klass and KlassDerived as some language modules, eg Python, create an extra reference in +// Provide overloads for Klass and derived classes as some language modules, eg Python, create an extra reference in // the marshalling if an upcast to a base class is required. +long use_count(const SwigBoost::shared_ptr& sptr) { + return sptr.use_count(); +} +long use_count(const SwigBoost::shared_ptr& sptr) { + return sptr.use_count(); +} long use_count(const SwigBoost::shared_ptr& sptr) { return sptr.use_count(); } diff --git a/Examples/test-suite/python/li_boost_shared_ptr_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_runme.py index 5f6cbd211..f967def14 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_runme.py @@ -304,6 +304,15 @@ class li_boost_shared_ptr_runme: self.verifyValue(li_boost_shared_ptr.overload_smartbyptr(k), "smartbyptr") self.verifyValue(li_boost_shared_ptr.overload_smartbyptrref(k), "smartbyptrref") + # 3rd derived class + k = li_boost_shared_ptr.Klass3rdDerived("me oh my") + val = k.getValue() + self.verifyValue("me oh my-3rdDerived", val) + self.verifyCount(1, k) + val = li_boost_shared_ptr.test3rdupcast(k) + self.verifyValue("me oh my-3rdDerived", val) + self.verifyCount(1, k) + # //////////////////////////////// Member variables //////////////////////////////////////// # smart pointer by value m = li_boost_shared_ptr.MemberVariables()