Add boost::intrusive_ptr wrappers from Mike Rowbotham
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11008 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e4c4dedc82
commit
62472ba466
4 changed files with 1746 additions and 0 deletions
701
Examples/test-suite/java/li_boost_intrusive_ptr_runme.java
Normal file
701
Examples/test-suite/java/li_boost_intrusive_ptr_runme.java
Normal file
|
|
@ -0,0 +1,701 @@
|
|||
import li_boost_intrusive_ptr.*;
|
||||
|
||||
public class li_boost_intrusive_ptr_runme {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("li_boost_intrusive_ptr");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Debugging flag
|
||||
public final static boolean debug = false;
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
if (debug)
|
||||
System.out.println("Started");
|
||||
|
||||
li_boost_intrusive_ptr.setDebug_shared(debug);
|
||||
|
||||
// Change loop count to run for a long time to monitor memory
|
||||
final int loopCount = 5000; //5000;
|
||||
for (int i=0; i<loopCount; i++) {
|
||||
new li_boost_intrusive_ptr_runme().runtest();
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
if (i%100 == 0) {
|
||||
java.lang.Thread.sleep(1); // give some time to the lower priority finalizer thread
|
||||
}
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (debug)
|
||||
System.out.println("Nearly finished");
|
||||
|
||||
int countdown = 50;
|
||||
while (true) {
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
java.lang.Thread.sleep(100);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
}
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == 1 && KlassWithoutRefCount.getTotal_count() == 0 &&
|
||||
li_boost_intrusive_ptr.getTotal_IgnoredRefCountingBase_count() == 0 &&
|
||||
KlassDerived.getTotal_count() == 0 && KlassDerivedDerived.getTotal_count() == 1)
|
||||
// Expect 1 Klass instance - the one global variable (GlobalValue)
|
||||
break;
|
||||
};
|
||||
if (Klass.getTotal_count() != 1)
|
||||
throw new RuntimeException("Klass.total_count=" + Klass.getTotal_count());
|
||||
if (KlassWithoutRefCount.getTotal_count() != 0)
|
||||
throw new RuntimeException("KlassWithoutRefCount.total_count=" + KlassWithoutRefCount.getTotal_count());
|
||||
if (li_boost_intrusive_ptr.getTotal_IgnoredRefCountingBase_count() != 0)
|
||||
throw new RuntimeException("IgnoredRefCountingBase.total_count=" + li_boost_intrusive_ptr.getTotal_IgnoredRefCountingBase_count());
|
||||
if (KlassDerived.getTotal_count() != 0)
|
||||
throw new RuntimeException("KlassDerived.total_count=" + KlassDerived.getTotal_count());
|
||||
if (KlassDerivedDerived.getTotal_count() != 0)
|
||||
throw new RuntimeException("KlassDerivedDerived.total_count=" + KlassDerivedDerived.getTotal_count());
|
||||
|
||||
int wrapper_count = li_boost_intrusive_ptr.intrusive_ptr_wrapper_count();
|
||||
if (wrapper_count != li_boost_intrusive_ptr.getNOT_COUNTING())
|
||||
if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue)
|
||||
throw new RuntimeException("shared_ptr wrapper count=" + wrapper_count);
|
||||
|
||||
if (debug)
|
||||
System.out.println("Finished");
|
||||
}
|
||||
|
||||
private void runtest() {
|
||||
// simple shared_ptr usage - created in C++
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
String val = k.getValue();
|
||||
verifyValue("me oh my", val);
|
||||
verifyCount(1, k);
|
||||
}
|
||||
|
||||
// simple shared_ptr usage - not created in C++
|
||||
{
|
||||
Klass k = li_boost_intrusive_ptr.factorycreate();
|
||||
String val = k.getValue();
|
||||
verifyValue("factorycreate", val);
|
||||
verifyCount(1, k);
|
||||
}
|
||||
|
||||
// pass by shared_ptr
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.smartpointertest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my smartpointertest", val);
|
||||
verifyCount(1, k);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, kret);
|
||||
verifyIntrusiveCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by shared_ptr pointer
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.smartpointerpointertest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my smartpointerpointertest", val);
|
||||
verifyCount(1, k);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, kret);
|
||||
verifyIntrusiveCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by shared_ptr reference
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.smartpointerreftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my smartpointerreftest", val);
|
||||
verifyCount(1, k);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, kret);
|
||||
verifyIntrusiveCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by shared_ptr pointer reference
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.smartpointerpointerreftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my smartpointerpointerreftest", val);
|
||||
verifyCount(1, k);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, kret);
|
||||
verifyIntrusiveCount(2, kret);
|
||||
}
|
||||
|
||||
// const pass by shared_ptr
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.constsmartpointertest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my", val);
|
||||
verifyCount(1, k);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, kret);
|
||||
verifyIntrusiveCount(2, kret);
|
||||
}
|
||||
|
||||
// const pass by shared_ptr pointer
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.constsmartpointerpointertest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my", val);
|
||||
verifyCount(1, k);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, kret);
|
||||
verifyIntrusiveCount(2, kret);
|
||||
}
|
||||
|
||||
// const pass by shared_ptr reference
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.constsmartpointerreftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my", val);
|
||||
verifyCount(1, k);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, kret);
|
||||
verifyIntrusiveCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by value
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.valuetest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my valuetest", val);
|
||||
verifyCount(1, k);
|
||||
verifyCount(1, kret);
|
||||
}
|
||||
|
||||
// pass by pointer
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.pointertest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my pointertest", val);
|
||||
verifyCount(1, k);
|
||||
verifyCount(1, kret);
|
||||
}
|
||||
|
||||
// pass by reference
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.reftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my reftest", val);
|
||||
verifyCount(1, k);
|
||||
verifyCount(1, kret);
|
||||
}
|
||||
|
||||
// pass by pointer reference
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
Klass kret = li_boost_intrusive_ptr.pointerreftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my pointerreftest", val);
|
||||
verifyCount(1, k);
|
||||
verifyCount(1, kret);
|
||||
}
|
||||
|
||||
// null tests
|
||||
{
|
||||
Klass k = null;
|
||||
|
||||
if (li_boost_intrusive_ptr.smartpointertest(k) != null)
|
||||
throw new RuntimeException("return was not null");
|
||||
|
||||
if (li_boost_intrusive_ptr.smartpointerpointertest(k) != null)
|
||||
throw new RuntimeException("return was not null");
|
||||
|
||||
if (li_boost_intrusive_ptr.smartpointerreftest(k) != null)
|
||||
throw new RuntimeException("return was not null");
|
||||
|
||||
if (li_boost_intrusive_ptr.smartpointerpointerreftest(k) != null)
|
||||
throw new RuntimeException("return was not null");
|
||||
|
||||
if (!li_boost_intrusive_ptr.nullsmartpointerpointertest(null).equals("null pointer"))
|
||||
throw new RuntimeException("not null smartpointer pointer");
|
||||
|
||||
try { li_boost_intrusive_ptr.valuetest(k); throw new RuntimeException("Failed to catch null pointer"); } catch (NullPointerException e) {}
|
||||
|
||||
if (li_boost_intrusive_ptr.pointertest(k) != null)
|
||||
throw new RuntimeException("return was not null");
|
||||
|
||||
try { li_boost_intrusive_ptr.reftest(k); throw new RuntimeException("Failed to catch null pointer"); } catch (NullPointerException e) {}
|
||||
}
|
||||
|
||||
// $owner
|
||||
{
|
||||
Klass k = li_boost_intrusive_ptr.pointerownertest();
|
||||
String val = k.getValue();
|
||||
verifyValue("pointerownertest", val);
|
||||
verifyCount(1, k);
|
||||
}
|
||||
{
|
||||
Klass k = li_boost_intrusive_ptr.smartpointerpointerownertest();
|
||||
String val = k.getValue();
|
||||
verifyValue("smartpointerpointerownertest", val);
|
||||
verifyCount(1, k);
|
||||
}
|
||||
|
||||
////////////////////////////////// Derived classes ////////////////////////////////////////
|
||||
// derived access to base class which cannot be wrapped in an intrusive_ptr
|
||||
{
|
||||
KlassWithoutRefCount k = new KlassDerived("me oh my");
|
||||
verifyValue("this class cannot be wrapped by intrusive_ptrs but we can still use it", k.getSpecialValueFromUnwrappableClass());
|
||||
}
|
||||
// derived pass by shared_ptr
|
||||
{
|
||||
KlassDerived k = new KlassDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedsmartptrtest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedsmartptrtest-Derived", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(2, k); // includes extra reference for upcast
|
||||
verifyIntrusiveCount(2, kret);
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
|
||||
// derived pass by shared_ptr pointer
|
||||
{
|
||||
KlassDerived k = new KlassDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedsmartptrpointertest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedsmartptrpointertest-Derived", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(2, k); // includes extra reference for upcast
|
||||
verifyIntrusiveCount(2, kret);
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
// derived pass by shared_ptr ref
|
||||
{
|
||||
KlassDerived k = new KlassDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedsmartptrreftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedsmartptrreftest-Derived", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(2, k); // includes extra reference for upcast
|
||||
verifyIntrusiveCount(2, kret);
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
// derived pass by shared_ptr pointer ref
|
||||
{
|
||||
KlassDerived k = new KlassDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedsmartptrpointerreftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(2, k); // includes extra reference for upcast
|
||||
verifyIntrusiveCount(2, kret);
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
// derived pass by pointer
|
||||
{
|
||||
KlassDerived k = new KlassDerived("me oh my");
|
||||
verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedpointertest(k);
|
||||
verifyCount(2, kret);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedpointertest-Derived", val);
|
||||
verifyIntrusiveCount(1, k); //one shared_ptr has a null deleter
|
||||
verifyCount(2, k); // includes extra reference for upcast
|
||||
verifyIntrusiveCount(1, kret); //one shared_ptr has a null deleter
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
// derived pass by ref
|
||||
{
|
||||
KlassDerived k = new KlassDerived("me oh my");
|
||||
verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedreftest(k);
|
||||
verifyCount(2, kret);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedreftest-Derived", val);
|
||||
verifyIntrusiveCount(1, k); //one shared_ptr has a null deleter
|
||||
verifyCount(2, k); // includes extra reference for upcast
|
||||
verifyIntrusiveCount(1, kret); //one shared_ptr has a null deleter
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
|
||||
////////////////////////////////// Derived and base class mixed ////////////////////////////////////////
|
||||
// pass by shared_ptr (mixed)
|
||||
{
|
||||
KlassDerived k = new KlassDerivedDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedsmartptrtest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedsmartptrtest-DerivedDerived", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(3, k); // an extra reference for the upcast in the proxy class
|
||||
verifyIntrusiveCount(2, kret);
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by shared_ptr pointer (mixed)
|
||||
{
|
||||
KlassDerived k = new KlassDerivedDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedsmartptrpointertest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedsmartptrpointertest-DerivedDerived", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(3, k); // an extra reference for the upcast in the proxy class
|
||||
verifyIntrusiveCount(2, kret);
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by shared_ptr reference (mixed)
|
||||
{
|
||||
KlassDerived k = new KlassDerivedDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedsmartptrreftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedsmartptrreftest-DerivedDerived", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(3, k); // an extra reference for the upcast in the proxy class
|
||||
verifyIntrusiveCount(2, kret);
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by shared_ptr pointer reference (mixed)
|
||||
{
|
||||
KlassDerived k = new KlassDerivedDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedsmartptrpointerreftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedsmartptrpointerreftest-DerivedDerived", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(3, k); // an extra reference for the upcast in the proxy class
|
||||
verifyIntrusiveCount(2, kret);
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by value (mixed)
|
||||
{
|
||||
KlassDerived k = new KlassDerivedDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedvaluetest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedvaluetest-Derived", val); // note slicing
|
||||
verifyIntrusiveCount(1, k);
|
||||
verifyCount(3, k); // an extra reference for the upcast in the proxy class
|
||||
verifyIntrusiveCount(1, kret);
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by pointer (mixed)
|
||||
{
|
||||
KlassDerived k = new KlassDerivedDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedpointertest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedpointertest-DerivedDerived", val);
|
||||
verifyIntrusiveCount(1, k); //one shared_ptr has a null deleter
|
||||
verifyCount(3, k); // an extra reference for the upcast in the proxy class
|
||||
verifyIntrusiveCount(1, kret); //one shared_ptr has a null deleter
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
|
||||
// pass by ref (mixed)
|
||||
{
|
||||
KlassDerived k = new KlassDerivedDerived("me oh my");
|
||||
KlassDerived kret = li_boost_intrusive_ptr.derivedreftest(k);
|
||||
String val = kret.getValue();
|
||||
verifyValue("me oh my derivedreftest-DerivedDerived", val);
|
||||
verifyIntrusiveCount(1, k); //one shared_ptr has a null deleter
|
||||
verifyCount(3, k); // an extra reference for the upcast in the proxy class
|
||||
verifyIntrusiveCount(1, kret); //one shared_ptr has a null deleter
|
||||
verifyCount(2, kret);
|
||||
}
|
||||
|
||||
////////////////////////////////// Member variables ////////////////////////////////////////
|
||||
// smart pointer by value
|
||||
{
|
||||
MemberVariables m = new MemberVariables();
|
||||
Klass k = new Klass("smart member value");
|
||||
m.setSmartMemberValue(k);
|
||||
String val = k.getValue();
|
||||
verifyValue("smart member value", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, k);
|
||||
|
||||
Klass kmember = m.getSmartMemberValue();
|
||||
val = kmember.getValue();
|
||||
verifyValue("smart member value", val);
|
||||
verifyIntrusiveCount(3, kmember);
|
||||
verifyIntrusiveCount(3, k);
|
||||
verifyCount(1, k);
|
||||
verifyCount(1, kmember);
|
||||
|
||||
m.delete();
|
||||
verifyIntrusiveCount(2, kmember);
|
||||
verifyIntrusiveCount(2, k);
|
||||
}
|
||||
|
||||
// smart pointer by pointer
|
||||
{
|
||||
MemberVariables m = new MemberVariables();
|
||||
Klass k = new Klass("smart member pointer");
|
||||
m.setSmartMemberPointer(k);
|
||||
String val = k.getValue();
|
||||
verifyValue("smart member pointer", val);
|
||||
verifyCount(1, k);
|
||||
verifyIntrusiveCount(2, k);
|
||||
|
||||
Klass kmember = m.getSmartMemberPointer();
|
||||
val = kmember.getValue();
|
||||
verifyValue("smart member pointer", val);
|
||||
verifyIntrusiveCount(3, kmember);
|
||||
verifyCount(1, kmember);
|
||||
verifyIntrusiveCount(3, k);
|
||||
verifyCount(1, k);
|
||||
|
||||
m.delete();
|
||||
verifyIntrusiveCount(2, kmember);
|
||||
verifyCount(1, kmember);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, k);
|
||||
}
|
||||
// smart pointer by reference
|
||||
{
|
||||
MemberVariables m = new MemberVariables();
|
||||
Klass k = new Klass("smart member reference");
|
||||
m.setSmartMemberReference(k);
|
||||
String val = k.getValue();
|
||||
verifyValue("smart member reference", val);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, k);
|
||||
|
||||
Klass kmember = m.getSmartMemberReference();
|
||||
val = kmember.getValue();
|
||||
verifyValue("smart member reference", val);
|
||||
verifyIntrusiveCount(3, kmember);
|
||||
verifyCount(1, kmember);
|
||||
verifyIntrusiveCount(3, k);
|
||||
verifyCount(1, k);
|
||||
|
||||
// The C++ reference refers to SmartMemberValue...
|
||||
m.setSmartMemberValue(k);
|
||||
Klass kmemberVal = m.getSmartMemberValue();
|
||||
val = kmember.getValue();
|
||||
verifyValue("smart member reference", val);
|
||||
verifyIntrusiveCount(5, kmemberVal);
|
||||
verifyCount(1, kmemberVal);
|
||||
verifyIntrusiveCount(5, kmember);
|
||||
verifyCount(1, kmember);
|
||||
verifyIntrusiveCount(5, k);
|
||||
verifyCount(1, k);
|
||||
|
||||
m.delete();
|
||||
verifyIntrusiveCount(3, kmemberVal);
|
||||
verifyCount(1, kmemberVal);
|
||||
verifyIntrusiveCount(3, kmember);
|
||||
verifyCount(1, kmember);
|
||||
verifyIntrusiveCount(3, k);
|
||||
verifyCount(1, k);
|
||||
}
|
||||
|
||||
//plain by value
|
||||
{
|
||||
MemberVariables m = new MemberVariables();
|
||||
Klass k = new Klass("plain member value");
|
||||
m.setMemberValue(k);
|
||||
String val = k.getValue();
|
||||
verifyValue("plain member value", val);
|
||||
verifyCount(1, k);
|
||||
|
||||
Klass kmember = m.getMemberValue();
|
||||
val = kmember.getValue();
|
||||
verifyValue("plain member value", val);
|
||||
verifyCount(1, kmember);
|
||||
verifyCount(1, k);
|
||||
|
||||
m.delete();
|
||||
verifyCount(1, kmember);
|
||||
verifyCount(1, k);
|
||||
}
|
||||
//plain by pointer
|
||||
{
|
||||
MemberVariables m = new MemberVariables();
|
||||
Klass k = new Klass("plain member pointer");
|
||||
m.setMemberPointer(k);
|
||||
String val = k.getValue();
|
||||
verifyValue("plain member pointer", val);
|
||||
verifyCount(1, k);
|
||||
|
||||
Klass kmember = m.getMemberPointer();
|
||||
val = kmember.getValue();
|
||||
verifyValue("plain member pointer", val);
|
||||
verifyCount(1, kmember);
|
||||
verifyCount(1, k);
|
||||
|
||||
m.delete();
|
||||
verifyCount(1, kmember);
|
||||
verifyCount(1, k);
|
||||
}
|
||||
//plain by reference
|
||||
{
|
||||
MemberVariables m = new MemberVariables();
|
||||
Klass k = new Klass("plain member reference");
|
||||
m.setMemberReference(k);
|
||||
String val = k.getValue();
|
||||
verifyValue("plain member reference", val);
|
||||
verifyCount(1, k);
|
||||
|
||||
Klass kmember = m.getMemberReference();
|
||||
val = kmember.getValue();
|
||||
verifyValue("plain member reference", val);
|
||||
verifyCount(1, kmember);
|
||||
verifyCount(1, k);
|
||||
|
||||
m.delete();
|
||||
verifyCount(1, kmember);
|
||||
verifyCount(1, k);
|
||||
}
|
||||
//null member variables
|
||||
{
|
||||
MemberVariables m = new MemberVariables();
|
||||
|
||||
// shared_ptr by value
|
||||
Klass k = m.getSmartMemberValue();
|
||||
if (k != null)
|
||||
throw new RuntimeException("expected null");
|
||||
m.setSmartMemberValue(null);
|
||||
k = m.getSmartMemberValue();
|
||||
if (k != null)
|
||||
throw new RuntimeException("expected null");
|
||||
verifyCount(0, k);
|
||||
|
||||
// plain by value
|
||||
try { m.setMemberValue(null); throw new RuntimeException("Failed to catch null pointer"); } catch (NullPointerException e) {}
|
||||
}
|
||||
}
|
||||
private void toIgnore() {
|
||||
////////////////////////////////// Global variables ////////////////////////////////////////
|
||||
// smart pointer
|
||||
{
|
||||
Klass kglobal = li_boost_intrusive_ptr.getGlobalSmartValue();
|
||||
if (kglobal != null)
|
||||
throw new RuntimeException("expected null");
|
||||
|
||||
Klass k = new Klass("smart global value");
|
||||
li_boost_intrusive_ptr.setGlobalSmartValue(k);
|
||||
verifyIntrusiveCount(2, k);
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_intrusive_ptr.getGlobalSmartValue();
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("smart global value", val);
|
||||
verifyIntrusiveCount(3, kglobal);
|
||||
verifyCount(1, kglobal);
|
||||
verifyIntrusiveCount(3, k);
|
||||
verifyCount(1, k);
|
||||
verifyValue("smart global value", li_boost_intrusive_ptr.getGlobalSmartValue().getValue());
|
||||
li_boost_intrusive_ptr.setGlobalSmartValue(null);
|
||||
}
|
||||
// plain value
|
||||
{
|
||||
Klass kglobal;
|
||||
|
||||
Klass k = new Klass("global value");
|
||||
li_boost_intrusive_ptr.setGlobalValue(k);
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_intrusive_ptr.getGlobalValue();
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("global value", val);
|
||||
verifyCount(1, kglobal);
|
||||
verifyCount(1, k);
|
||||
verifyValue("global value", li_boost_intrusive_ptr.getGlobalValue().getValue());
|
||||
|
||||
try { li_boost_intrusive_ptr.setGlobalValue(null); throw new RuntimeException("Failed to catch null pointer"); } catch (NullPointerException e) {}
|
||||
}
|
||||
//plain pointer
|
||||
{
|
||||
Klass kglobal = li_boost_intrusive_ptr.getGlobalPointer();
|
||||
if (kglobal != null)
|
||||
throw new RuntimeException("expected null");
|
||||
|
||||
Klass k = new Klass("global pointer");
|
||||
li_boost_intrusive_ptr.setGlobalPointer(k);
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_intrusive_ptr.getGlobalPointer();
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("global pointer", val);
|
||||
verifyCount(1, kglobal);
|
||||
verifyCount(1, k);
|
||||
li_boost_intrusive_ptr.setGlobalPointer(null);
|
||||
}
|
||||
|
||||
// plain reference
|
||||
{
|
||||
Klass kglobal;
|
||||
|
||||
Klass k = new Klass("global reference");
|
||||
li_boost_intrusive_ptr.setGlobalReference(k);
|
||||
verifyCount(1, k);
|
||||
|
||||
kglobal = li_boost_intrusive_ptr.getGlobalReference();
|
||||
String val = kglobal.getValue();
|
||||
verifyValue("global reference", val);
|
||||
verifyCount(1, kglobal);
|
||||
verifyCount(1, k);
|
||||
|
||||
try { li_boost_intrusive_ptr.setGlobalReference(null); throw new RuntimeException("Failed to catch null pointer"); } catch (NullPointerException e) {}
|
||||
}
|
||||
|
||||
////////////////////////////////// Templates ////////////////////////////////////////
|
||||
{
|
||||
PairIntDouble pid = new PairIntDouble(10, 20.2);
|
||||
if (pid.getBaseVal1() != 20 || pid.getBaseVal2() != 40.4)
|
||||
throw new RuntimeException("Base values wrong");
|
||||
if (pid.getVal1() != 10 || pid.getVal2() != 20.2)
|
||||
throw new RuntimeException("Derived Values wrong");
|
||||
}
|
||||
}
|
||||
private void verifyValue(String expected, String got) {
|
||||
if (!expected.equals(got))
|
||||
throw new RuntimeException("verify value failed. Expected: " + expected + " Got: " + got);
|
||||
}
|
||||
private void verifyCount(int expected, Klass k) {
|
||||
int got = li_boost_intrusive_ptr.use_count(k);
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
}
|
||||
private void verifyCount(int expected, KlassDerived kd) {
|
||||
int got = li_boost_intrusive_ptr.use_count(kd);
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
}
|
||||
private void verifyCount(int expected, KlassDerivedDerived kdd) {
|
||||
int got = li_boost_intrusive_ptr.use_count(kdd);
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
}
|
||||
private void verifyIntrusiveCount(int expected, Klass k) {
|
||||
int got = k.use_count();
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
}
|
||||
private void verifyIntrusiveCount(int expected, KlassDerived kd) {
|
||||
int got = kd.use_count();
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
}
|
||||
private void verifyIntrusiveCount(int expected, KlassDerivedDerived kdd) {
|
||||
int got = kdd.use_count();
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
}
|
||||
}
|
||||
492
Examples/test-suite/li_boost_intrusive_ptr.i
Normal file
492
Examples/test-suite/li_boost_intrusive_ptr.i
Normal file
|
|
@ -0,0 +1,492 @@
|
|||
// This tests intrusive_ptr is working okay. It also checks that there are no memory leaks in the
|
||||
// class that intrusive_ptr is pointing via a counting mechanism in the constructors and destructor of Klass.
|
||||
// In order to test that there are no leaks of the intrusive_ptr class itself (as it is created on the heap)
|
||||
// the runtime tests can be run for a long time to monitor memory leaks using memory monitor tools
|
||||
// like 'top'. There is a wrapper for intrusive_ptr in intrusive_ptr_wrapper.h which enables one to
|
||||
// count the instances of intrusive_ptr. Uncomment the INTRUSIVE_PTR_WRAPPER macro to turn this on.
|
||||
//
|
||||
// Also note the debug_shared flag which can be set from the target language.
|
||||
|
||||
%module li_boost_intrusive_ptr
|
||||
|
||||
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK);
|
||||
|
||||
%inline %{
|
||||
#include "boost/intrusive_ptr.hpp"
|
||||
#include <boost/detail/atomic_count.hpp>
|
||||
|
||||
// Uncomment macro below to turn on intrusive_ptr memory leak checking as described above
|
||||
//#define INTRUSIVE_PTR_WRAPPER
|
||||
|
||||
#ifdef INTRUSIVE_PTR_WRAPPER
|
||||
# include "intrusive_ptr_wrapper.h"
|
||||
# include "shared_ptr_wrapper.h"
|
||||
#endif
|
||||
%}
|
||||
|
||||
%{
|
||||
#ifndef INTRUSIVE_PTR_WRAPPER
|
||||
# define SwigBoost boost
|
||||
#endif
|
||||
%}
|
||||
|
||||
%include "std_string.i"
|
||||
#ifndef INTRUSIVE_PTR_WRAPPER
|
||||
# define SWIG_INTRUSIVE_PTR_NAMESPACE SwigBoost
|
||||
#endif
|
||||
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON)
|
||||
#define INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED
|
||||
#endif
|
||||
|
||||
#if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED)
|
||||
|
||||
%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)
|
||||
|
||||
//For the use_count shared_ptr functions
|
||||
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & ($*1_ltype tempnull) %{
|
||||
$1 = $input ? *($&1_ltype)&$input : &tempnull;
|
||||
%}
|
||||
%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "jlong"
|
||||
%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "long"
|
||||
%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "Klass"
|
||||
%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::Klass > & "Klass.getCPtr($javainput)"
|
||||
|
||||
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & ($*1_ltype tempnull) %{
|
||||
$1 = $input ? *($&1_ltype)&$input : &tempnull;
|
||||
%}
|
||||
%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "jlong"
|
||||
%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "long"
|
||||
%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "KlassDerived"
|
||||
%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerived > & "KlassDerived.getCPtr($javainput)"
|
||||
|
||||
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & ($*1_ltype tempnull) %{
|
||||
$1 = $input ? *($&1_ltype)&$input : &tempnull;
|
||||
%}
|
||||
%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "jlong"
|
||||
%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "long"
|
||||
%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "KlassDerivedDerived"
|
||||
%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< Space::KlassDerivedDerived > & "KlassDerivedDerived.getCPtr($javainput)"
|
||||
|
||||
#endif
|
||||
|
||||
// TODO:
|
||||
// const intrusive_ptr
|
||||
// std::vector
|
||||
// Add in generic %extend for the Upcast function for derived classes
|
||||
// Remove proxy upcast method - implement %feature("shadow") ??? which replaces the proxy method
|
||||
|
||||
%exception {
|
||||
if (debug_shared) {
|
||||
cout << "++++++" << endl << flush;
|
||||
cout << "calling $name" << endl << flush;
|
||||
}
|
||||
$action
|
||||
if (debug_shared) {
|
||||
cout << "------" << endl << flush;
|
||||
}
|
||||
}
|
||||
|
||||
%ignore IgnoredRefCountingBase;
|
||||
%ignore *::operator=;
|
||||
%ignore intrusive_ptr_add_ref;
|
||||
%ignore intrusive_ptr_release;
|
||||
%newobject pointerownertest();
|
||||
%newobject smartpointerpointerownertest();
|
||||
|
||||
%inline %{
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
static bool debug_shared = false;
|
||||
|
||||
namespace Space {
|
||||
|
||||
struct Klass {
|
||||
Klass() : value("EMPTY"), count(0) { if (debug_shared) cout << "Klass() [" << value << "]" << endl << flush; increment(); }
|
||||
|
||||
Klass(const std::string &val) : value(val), count(0) { if (debug_shared) cout << "Klass(string) [" << value << "]" << endl << flush; increment(); }
|
||||
|
||||
virtual ~Klass() { if (debug_shared) cout << "~Klass() [" << value << "]" << endl << flush; decrement(); }
|
||||
virtual std::string getValue() const { return value; }
|
||||
void append(const std::string &s) { value += s; }
|
||||
Klass(const Klass &other) : value(other.value), count(0) { if (debug_shared) cout << "Klass(const Klass&) [" << value << "]" << endl << flush; increment(); }
|
||||
|
||||
Klass &operator=(const Klass &other) { value = other.value; return *this; }
|
||||
|
||||
void addref(void) const { ++count; }
|
||||
void release(void) const { if (--count == 0) delete this; }
|
||||
int use_count(void) const { return count; }
|
||||
static long getTotal_count() { return total_count; }
|
||||
|
||||
private:
|
||||
static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx Klass::increment tot: " << total_count << endl;}
|
||||
static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx Klass::decrement tot: " << total_count << endl;}
|
||||
static boost::detail::atomic_count total_count;
|
||||
std::string value;
|
||||
int array[1024];
|
||||
mutable boost::detail::atomic_count count;
|
||||
};
|
||||
|
||||
struct KlassWithoutRefCount {
|
||||
KlassWithoutRefCount() : value("EMPTY") { if (debug_shared) cout << "KlassWithoutRefCount() [" << value << "]" << endl << flush; increment(); }
|
||||
|
||||
KlassWithoutRefCount(const std::string &val) : value(val) { if (debug_shared) cout << "KlassWithoutRefCount(string) [" << value << "]" << endl << flush; increment(); }
|
||||
|
||||
virtual ~KlassWithoutRefCount() { if (debug_shared) cout << "~KlassWithoutRefCount() [" << value << "]" << endl << flush; decrement(); }
|
||||
virtual std::string getValue() const { return value; }
|
||||
void append(const std::string &s) { value += s; }
|
||||
KlassWithoutRefCount(const KlassWithoutRefCount &other) : value(other.value) { if (debug_shared) cout << "KlassWithoutRefCount(const KlassWithoutRefCount&) [" << value << "]" << endl << flush; increment(); }
|
||||
std::string getSpecialValueFromUnwrappableClass() { return "this class cannot be wrapped by intrusive_ptrs but we can still use it"; }
|
||||
KlassWithoutRefCount &operator=(const KlassWithoutRefCount &other) { value = other.value; return *this; }
|
||||
static long getTotal_count() { return total_count; }
|
||||
|
||||
private:
|
||||
static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx KlassWithoutRefCount::increment tot: " << total_count << endl;}
|
||||
static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx KlassWithoutRefCount::decrement tot: " << total_count << endl;}
|
||||
static boost::detail::atomic_count total_count;
|
||||
std::string value;
|
||||
int array[1024];
|
||||
};
|
||||
|
||||
struct IgnoredRefCountingBase {
|
||||
IgnoredRefCountingBase() : count(0) { if (debug_shared) cout << "IgnoredRefCountingBase()" << endl << flush; increment(); }
|
||||
|
||||
IgnoredRefCountingBase(const IgnoredRefCountingBase &other) : count(0) { if (debug_shared) cout << "IgnoredRefCountingBase(const IgnoredRefCountingBase&)" << endl << flush; increment(); }
|
||||
|
||||
IgnoredRefCountingBase &operator=(const IgnoredRefCountingBase& other) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~IgnoredRefCountingBase() { if (debug_shared) cout << "~IgnoredRefCountingBase()" << endl << flush; decrement(); }
|
||||
|
||||
void addref(void) const { ++count; }
|
||||
void release(void) const { if (--count == 0) delete this; }
|
||||
int use_count(void) const { return count; }
|
||||
static long getTotal_count() { return total_count; }
|
||||
|
||||
private:
|
||||
static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx IgnoredRefCountingBase::increment tot: " << total_count << endl;}
|
||||
static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx IgnoredRefCountingBase::decrement tot: " << total_count << endl;}
|
||||
static boost::detail::atomic_count total_count;
|
||||
double d;
|
||||
double e;
|
||||
mutable boost::detail::atomic_count count;
|
||||
};
|
||||
|
||||
long getTotal_IgnoredRefCountingBase_count() {
|
||||
return IgnoredRefCountingBase::getTotal_count();
|
||||
}
|
||||
|
||||
// For most compilers, this use of multiple inheritance results in different derived and base class
|
||||
// pointer values ... for some more challenging tests :)
|
||||
struct KlassDerived : IgnoredRefCountingBase, KlassWithoutRefCount {
|
||||
KlassDerived() : KlassWithoutRefCount() { if (debug_shared) cout << "KlassDerived()" << endl << flush; increment(); }
|
||||
KlassDerived(const std::string &val) : KlassWithoutRefCount(val) { if (debug_shared) cout << "KlassDerived(string) [" << val << "]" << endl << flush; increment(); }
|
||||
KlassDerived(const KlassDerived &other) : KlassWithoutRefCount(other) { if (debug_shared) cout << "KlassDerived(const KlassDerived&))" << endl << flush; increment(); }
|
||||
virtual ~KlassDerived() { if (debug_shared) cout << "~KlassDerived()" << endl << flush; decrement(); }
|
||||
virtual std::string getValue() const { return KlassWithoutRefCount::getValue() + "-Derived"; }
|
||||
int use_count(void) const { return IgnoredRefCountingBase::use_count(); }
|
||||
static long getTotal_count() { return total_count; }
|
||||
|
||||
private:
|
||||
static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx KlassDerived::increment tot: " << total_count << endl;}
|
||||
static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx KlassDerived::decrement tot: " << total_count << endl;}
|
||||
static boost::detail::atomic_count total_count;
|
||||
};
|
||||
struct KlassDerivedDerived : KlassDerived {
|
||||
KlassDerivedDerived() : KlassDerived() { if (debug_shared) cout << "KlassDerivedDerived()" << endl << flush; increment(); }
|
||||
KlassDerivedDerived(const std::string &val) : KlassDerived(val) { if (debug_shared) cout << "KlassDerivedDerived(string) [" << val << "]" << endl << flush; increment(); }
|
||||
KlassDerivedDerived(const KlassDerived &other) : KlassDerived(other) { if (debug_shared) cout << "KlassDerivedDerived(const KlassDerivedDerived&))" << endl << flush; increment(); }
|
||||
virtual ~KlassDerivedDerived() { if (debug_shared) cout << "~KlassDerivedDerived()" << endl << flush; decrement(); }
|
||||
virtual std::string getValue() const { return KlassWithoutRefCount::getValue() + "-DerivedDerived"; }
|
||||
static long getTotal_count() { return total_count; }
|
||||
|
||||
private:
|
||||
static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx KlassDerivedDerived::increment tot: " << total_count << endl;}
|
||||
static void decrement() { --total_count; if (debug_shared) cout << " --xxxxx KlassDerivedDerived::decrement tot: " << total_count << endl;}
|
||||
static boost::detail::atomic_count total_count;
|
||||
};
|
||||
KlassDerived* derivedpointertest(KlassDerived* kd) {
|
||||
if (kd)
|
||||
kd->append(" derivedpointertest");
|
||||
return kd;
|
||||
}
|
||||
KlassDerived derivedvaluetest(KlassDerived kd) {
|
||||
kd.append(" derivedvaluetest");
|
||||
return kd;
|
||||
}
|
||||
KlassDerived& derivedreftest(KlassDerived& kd) {
|
||||
kd.append(" derivedreftest");
|
||||
return kd;
|
||||
}
|
||||
SwigBoost::intrusive_ptr<KlassDerived> derivedsmartptrtest(SwigBoost::intrusive_ptr<KlassDerived> kd) {
|
||||
if (kd)
|
||||
kd->append(" derivedsmartptrtest");
|
||||
return kd;
|
||||
}
|
||||
SwigBoost::intrusive_ptr<KlassDerived>* derivedsmartptrpointertest(SwigBoost::intrusive_ptr<KlassDerived>* kd) {
|
||||
if (kd && *kd)
|
||||
(*kd)->append(" derivedsmartptrpointertest");
|
||||
return kd;
|
||||
}
|
||||
SwigBoost::intrusive_ptr<KlassDerived>* derivedsmartptrreftest(SwigBoost::intrusive_ptr<KlassDerived>* kd) {
|
||||
if (kd && *kd)
|
||||
(*kd)->append(" derivedsmartptrreftest");
|
||||
return kd;
|
||||
}
|
||||
SwigBoost::intrusive_ptr<KlassDerived>*& derivedsmartptrpointerreftest(SwigBoost::intrusive_ptr<KlassDerived>*& kd) {
|
||||
if (kd && *kd)
|
||||
(*kd)->append(" derivedsmartptrpointerreftest");
|
||||
return kd;
|
||||
}
|
||||
|
||||
SwigBoost::intrusive_ptr<Klass> factorycreate() {
|
||||
return SwigBoost::intrusive_ptr<Klass>(new Klass("factorycreate"));
|
||||
}
|
||||
// smart pointer
|
||||
SwigBoost::intrusive_ptr<Klass> smartpointertest(SwigBoost::intrusive_ptr<Klass> k) {
|
||||
if (k)
|
||||
k->append(" smartpointertest");
|
||||
return SwigBoost::intrusive_ptr<Klass>(k);
|
||||
}
|
||||
SwigBoost::intrusive_ptr<Klass>* smartpointerpointertest(SwigBoost::intrusive_ptr<Klass>* k) {
|
||||
if (k && *k)
|
||||
(*k)->append(" smartpointerpointertest");
|
||||
return k;
|
||||
}
|
||||
SwigBoost::intrusive_ptr<Klass>& smartpointerreftest(SwigBoost::intrusive_ptr<Klass>& k) {
|
||||
if (k)
|
||||
k->append(" smartpointerreftest");
|
||||
return k;
|
||||
}
|
||||
SwigBoost::intrusive_ptr<Klass>*& smartpointerpointerreftest(SwigBoost::intrusive_ptr<Klass>*& k) {
|
||||
if (k && *k)
|
||||
(*k)->append(" smartpointerpointerreftest");
|
||||
return k;
|
||||
}
|
||||
// const
|
||||
SwigBoost::intrusive_ptr<const Klass> constsmartpointertest(SwigBoost::intrusive_ptr<const Klass> k) {
|
||||
return SwigBoost::intrusive_ptr<const Klass>(k);
|
||||
}
|
||||
SwigBoost::intrusive_ptr<const Klass>* constsmartpointerpointertest(SwigBoost::intrusive_ptr<const Klass>* k) {
|
||||
return k;
|
||||
}
|
||||
SwigBoost::intrusive_ptr<const Klass>& constsmartpointerreftest(SwigBoost::intrusive_ptr<const Klass>& k) {
|
||||
return k;
|
||||
}
|
||||
// plain pointer
|
||||
Klass valuetest(Klass k) {
|
||||
k.append(" valuetest");
|
||||
return k;
|
||||
}
|
||||
Klass *pointertest(Klass *k) {
|
||||
if (k)
|
||||
k->append(" pointertest");
|
||||
return k;
|
||||
}
|
||||
Klass& reftest(Klass& k) {
|
||||
k.append(" reftest");
|
||||
return k;
|
||||
}
|
||||
Klass*& pointerreftest(Klass*& k) {
|
||||
k->append(" pointerreftest");
|
||||
return k;
|
||||
}
|
||||
// null
|
||||
std::string nullsmartpointerpointertest(SwigBoost::intrusive_ptr<Klass>* k) {
|
||||
if (k && *k)
|
||||
return "not null";
|
||||
else if (!k)
|
||||
return "null smartpointer pointer";
|
||||
else if (!*k)
|
||||
return "null pointer";
|
||||
else
|
||||
return "also not null";
|
||||
}
|
||||
// $owner
|
||||
Klass *pointerownertest() {
|
||||
return new Klass("pointerownertest");
|
||||
}
|
||||
SwigBoost::intrusive_ptr<Klass>* smartpointerpointerownertest() {
|
||||
return new SwigBoost::intrusive_ptr<Klass>(new Klass("smartpointerpointerownertest"));
|
||||
}
|
||||
|
||||
const SwigBoost::intrusive_ptr<Klass>& ref_1() {
|
||||
static SwigBoost::intrusive_ptr<Klass> sptr;
|
||||
return sptr;
|
||||
}
|
||||
|
||||
// overloading tests
|
||||
std::string overload_rawbyval(int i) { return "int"; }
|
||||
std::string overload_rawbyval(Klass k) { return "rawbyval"; }
|
||||
|
||||
std::string overload_rawbyref(int i) { return "int"; }
|
||||
std::string overload_rawbyref(Klass &k) { return "rawbyref"; }
|
||||
|
||||
std::string overload_rawbyptr(int i) { return "int"; }
|
||||
std::string overload_rawbyptr(Klass *k) { return "rawbyptr"; }
|
||||
|
||||
std::string overload_rawbyptrref(int i) { return "int"; }
|
||||
std::string overload_rawbyptrref(Klass *&k) { return "rawbyptrref"; }
|
||||
|
||||
|
||||
|
||||
std::string overload_smartbyval(int i) { return "int"; }
|
||||
std::string overload_smartbyval(SwigBoost::intrusive_ptr<Klass> k) { return "smartbyval"; }
|
||||
|
||||
std::string overload_smartbyref(int i) { return "int"; }
|
||||
std::string overload_smartbyref(SwigBoost::intrusive_ptr<Klass> &k) { return "smartbyref"; }
|
||||
|
||||
std::string overload_smartbyptr(int i) { return "int"; }
|
||||
std::string overload_smartbyptr(SwigBoost::intrusive_ptr<Klass> *k) { return "smartbyptr"; }
|
||||
|
||||
std::string overload_smartbyptrref(int i) { return "int"; }
|
||||
std::string overload_smartbyptrref(SwigBoost::intrusive_ptr<Klass> *&k) { return "smartbyptrref"; }
|
||||
|
||||
} // namespace Space
|
||||
|
||||
%}
|
||||
%{
|
||||
boost::detail::atomic_count Space::Klass::total_count(0);
|
||||
boost::detail::atomic_count Space::KlassWithoutRefCount::total_count(0);
|
||||
boost::detail::atomic_count Space::IgnoredRefCountingBase::total_count(0);
|
||||
boost::detail::atomic_count Space::KlassDerived::total_count(0);
|
||||
boost::detail::atomic_count Space::KlassDerivedDerived::total_count(0);
|
||||
%}
|
||||
|
||||
// Member variables
|
||||
|
||||
%inline %{
|
||||
struct MemberVariables {
|
||||
MemberVariables() : SmartMemberPointer(new SwigBoost::intrusive_ptr<Space::Klass>()), SmartMemberReference(*(new SwigBoost::intrusive_ptr<Space::Klass>())), MemberPointer(0), MemberReference(MemberValue) {}
|
||||
virtual ~MemberVariables() {
|
||||
delete SmartMemberPointer;
|
||||
delete &SmartMemberReference;
|
||||
}
|
||||
SwigBoost::intrusive_ptr<Space::Klass> SmartMemberValue;
|
||||
SwigBoost::intrusive_ptr<Space::Klass> * SmartMemberPointer;
|
||||
SwigBoost::intrusive_ptr<Space::Klass> & SmartMemberReference;
|
||||
Space::Klass MemberValue;
|
||||
Space::Klass * MemberPointer;
|
||||
Space::Klass & MemberReference;
|
||||
};
|
||||
|
||||
// Global variables
|
||||
SwigBoost::intrusive_ptr<Space::Klass> GlobalSmartValue;
|
||||
Space::Klass GlobalValue;
|
||||
Space::Klass * GlobalPointer = 0;
|
||||
Space::Klass & GlobalReference = GlobalValue;
|
||||
|
||||
%}
|
||||
|
||||
#if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED)
|
||||
|
||||
// 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>)
|
||||
|
||||
#endif
|
||||
|
||||
// Templates
|
||||
%inline %{
|
||||
template <class T1, class T2> struct Base {
|
||||
Space::Klass klassBase;
|
||||
T1 baseVal1;
|
||||
T2 baseVal2;
|
||||
Base(T1 t1, T2 t2) : baseVal1(t1*2), baseVal2(t2*2) {}
|
||||
virtual std::string getValue() const { return "Base<>"; };
|
||||
mutable int count;
|
||||
void addref(void) const { count++; }
|
||||
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>;
|
||||
|
||||
%inline %{
|
||||
template <class T1, class T2> struct Pair : Base<T1, T2> {
|
||||
Space::Klass klassPair;
|
||||
T1 val1;
|
||||
T2 val2;
|
||||
Pair(T1 t1, T2 t2) : Base<T1, T2>(t1, t2), val1(t1), val2(t2) {}
|
||||
virtual std::string getValue() const { return "Pair<>"; };
|
||||
};
|
||||
|
||||
Pair<int, double> pair_id2(Pair<int, double> p) { return p; }
|
||||
SwigBoost::intrusive_ptr< Pair<int, double> > pair_id1(SwigBoost::intrusive_ptr< Pair<int, double> > p) { return p; }
|
||||
|
||||
template<typename T> void intrusive_ptr_add_ref(const T* r) { r->addref(); }
|
||||
|
||||
template<typename T> void intrusive_ptr_release(const T* r) { r->release(); }
|
||||
|
||||
long use_count(const SwigBoost::shared_ptr<Space::Klass>& sptr) {
|
||||
return sptr.use_count();
|
||||
}
|
||||
long use_count(const SwigBoost::shared_ptr<Space::KlassDerived>& sptr) {
|
||||
return sptr.use_count();
|
||||
}
|
||||
long use_count(const SwigBoost::shared_ptr<Space::KlassDerivedDerived>& sptr) {
|
||||
return sptr.use_count();
|
||||
}
|
||||
%}
|
||||
|
||||
%template(PairIntDouble) Pair<int, double>;
|
||||
|
||||
// For counting the instances of intrusive_ptr (all of which are created on the heap)
|
||||
// intrusive_ptr_wrapper_count() gives overall count
|
||||
%inline %{
|
||||
namespace SwigBoost {
|
||||
const int NOT_COUNTING = -123456;
|
||||
int intrusive_ptr_wrapper_count() {
|
||||
#ifdef INTRUSIVE_PTR_WRAPPER
|
||||
return SwigBoost::IntrusivePtrWrapper::getTotalCount();
|
||||
#else
|
||||
return NOT_COUNTING;
|
||||
#endif
|
||||
}
|
||||
#ifdef INTRUSIVE_PTR_WRAPPER
|
||||
template<> std::string show_message(boost::intrusive_ptr<Space::Klass >*t) {
|
||||
if (!t)
|
||||
return "null intrusive_ptr!!!";
|
||||
if (*t)
|
||||
return "Klass: " + (*t)->getValue();
|
||||
else
|
||||
return "Klass: NULL";
|
||||
}
|
||||
template<> std::string show_message(boost::intrusive_ptr<const Space::Klass >*t) {
|
||||
if (!t)
|
||||
return "null intrusive_ptr!!!";
|
||||
if (*t)
|
||||
return "Klass: " + (*t)->getValue();
|
||||
else
|
||||
return "Klass: NULL";
|
||||
}
|
||||
template<> std::string show_message(boost::intrusive_ptr<Space::KlassDerived >*t) {
|
||||
if (!t)
|
||||
return "null intrusive_ptr!!!";
|
||||
if (*t)
|
||||
return "KlassDerived: " + (*t)->getValue();
|
||||
else
|
||||
return "KlassDerived: NULL";
|
||||
}
|
||||
template<> std::string show_message(boost::intrusive_ptr<const Space::KlassDerived >*t) {
|
||||
if (!t)
|
||||
return "null intrusive_ptr!!!";
|
||||
if (*t)
|
||||
return "KlassDerived: " + (*t)->getValue();
|
||||
else
|
||||
return "KlassDerived: NULL";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
%}
|
||||
|
||||
97
Lib/intrusive_ptr.i
Normal file
97
Lib/intrusive_ptr.i
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// intrusive_ptr namespaces could be boost or std or std::tr1
|
||||
#if !defined(SWIG_INTRUSIVE_PTR_NAMESPACE)
|
||||
# define SWIG_INTRUSIVE_PTR_NAMESPACE boost
|
||||
#endif
|
||||
|
||||
#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE)
|
||||
# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE::SWIG_INTRUSIVE_PTR_SUBNAMESPACE
|
||||
#else
|
||||
# define SWIG_INTRUSIVE_PTR_QNAMESPACE SWIG_INTRUSIVE_PTR_NAMESPACE
|
||||
#endif
|
||||
|
||||
namespace SWIG_INTRUSIVE_PTR_NAMESPACE {
|
||||
#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE)
|
||||
namespace SWIG_INTRUSIVE_PTR_SUBNAMESPACE {
|
||||
#endif
|
||||
template <class T> class shared_ptr {
|
||||
};
|
||||
|
||||
template <class T> class intrusive_ptr {
|
||||
};
|
||||
#if defined(SWIG_INTRUSIVE_PTR_SUBNAMESPACE)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
%inline %{
|
||||
#include "boost/shared_ptr.hpp"
|
||||
%}
|
||||
|
||||
%fragment("SWIG_intrusive_deleter", "header") {
|
||||
template<class T> struct SWIG_intrusive_deleter
|
||||
{
|
||||
void operator()(T * p)
|
||||
{
|
||||
if(p) intrusive_ptr_release(p);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
%fragment("SWIG_null_deleter", "header") {
|
||||
struct SWIG_null_deleter {
|
||||
void operator() (void const *) const {
|
||||
}
|
||||
};
|
||||
%#define SWIG_NO_NULL_DELETER_0 , SWIG_null_deleter()
|
||||
%#define SWIG_NO_NULL_DELETER_1
|
||||
}
|
||||
|
||||
// Main user macro for defining intrusive_ptr typemaps for both const and non-const pointer types
|
||||
// For plain classes, do not use for derived classes
|
||||
%define SWIG_INTRUSIVE_PTR(PROXYCLASS, TYPE...)
|
||||
SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, , TYPE)
|
||||
SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
|
||||
%enddef
|
||||
|
||||
// Main user macro for defining intrusive_ptr typemaps for both const and non-const pointer types
|
||||
// For derived classes
|
||||
%define SWIG_INTRUSIVE_PTR_DERIVED(PROXYCLASS, BASECLASSTYPE, TYPE...)
|
||||
SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, , TYPE)
|
||||
SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, const, TYPE)
|
||||
%types(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< TYPE > = SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< BASECLASSTYPE >) %{
|
||||
*newmemory = SWIG_CAST_NEW_MEMORY;
|
||||
return (void *) new SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< BASECLASSTYPE >(*(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< TYPE > *)$from);
|
||||
%}
|
||||
%extend TYPE {
|
||||
static SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< BASECLASSTYPE > SWIGSharedPtrUpcast(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast) {
|
||||
return swigSharedPtrUpcast;
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
// Extra user macro for including classes in intrusive_ptr typemaps for both const and non-const pointer types
|
||||
// This caters for classes which cannot be wrapped by intrusive_ptrs but are still part of the class hierarchy
|
||||
// For plain classes, do not use for derived classes
|
||||
%define SWIG_INTRUSIVE_PTR_NO_WRAP(PROXYCLASS, TYPE...)
|
||||
SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, , TYPE)
|
||||
SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, const, TYPE)
|
||||
%enddef
|
||||
|
||||
// Extra user macro for including classes in intrusive_ptr typemaps for both const and non-const pointer types
|
||||
// This caters for classes which cannot be wrapped by intrusive_ptrs but are still part of the class hierarchy
|
||||
// For derived classes
|
||||
%define SWIG_INTRUSIVE_PTR_DERIVED_NO_WRAP(PROXYCLASS, BASECLASSTYPE, TYPE...)
|
||||
SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, , TYPE)
|
||||
SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, const, TYPE)
|
||||
%types(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< TYPE > = SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< BASECLASSTYPE >) %{
|
||||
*newmemory = SWIG_CAST_NEW_MEMORY;
|
||||
return (void *) new SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< BASECLASSTYPE >(*(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< TYPE > *)$from);
|
||||
%}
|
||||
%extend TYPE {
|
||||
static SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< BASECLASSTYPE > SWIGSharedPtrUpcast(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast) {
|
||||
return swigSharedPtrUpcast;
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
456
Lib/java/boost_intrusive_ptr.i
Normal file
456
Lib/java/boost_intrusive_ptr.i
Normal file
|
|
@ -0,0 +1,456 @@
|
|||
%include <intrusive_ptr.i>
|
||||
|
||||
%define SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
|
||||
|
||||
%naturalvar TYPE;
|
||||
%naturalvar SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >;
|
||||
|
||||
// destructor mods
|
||||
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
|
||||
|
||||
|
||||
%typemap(in) CONST TYPE ($&1_type argp = 0, SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
|
||||
// plain value
|
||||
argp = (*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0;
|
||||
if (!argp) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
|
||||
return $null;
|
||||
}
|
||||
$1 = *argp;
|
||||
%}
|
||||
%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{
|
||||
//plain value(out)
|
||||
$1_ltype* resultp = new $1_ltype(($1_ltype &)$1);
|
||||
intrusive_ptr_add_ref(resultp);
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(resultp, SWIG_intrusive_deleter< CONST TYPE >());
|
||||
%}
|
||||
|
||||
%typemap(in) CONST TYPE * (SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
|
||||
// plain pointer
|
||||
smartarg = *(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
|
||||
$1 = (TYPE *)(smartarg ? smartarg->get() : 0);
|
||||
%}
|
||||
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE * %{
|
||||
//plain pointer(out)
|
||||
#if ($owner)
|
||||
if ($1) {
|
||||
intrusive_ptr_add_ref($1);
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >());
|
||||
} else {
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
|
||||
}
|
||||
#else
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
|
||||
#endif
|
||||
%}
|
||||
|
||||
%typemap(in) CONST TYPE & (SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
|
||||
// plain reference
|
||||
$1 = ($1_ltype)((*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
|
||||
if(!$1) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
|
||||
return $null;
|
||||
}
|
||||
%}
|
||||
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE & %{
|
||||
//plain reference(out)
|
||||
#if ($owner)
|
||||
if ($1) {
|
||||
intrusive_ptr_add_ref($1);
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1, SWIG_intrusive_deleter< CONST TYPE >());
|
||||
} else {
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
|
||||
}
|
||||
#else
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
|
||||
#endif
|
||||
%}
|
||||
|
||||
%typemap(in) CONST TYPE *& ($*1_ltype temp = 0, SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
|
||||
// plain pointer by reference
|
||||
temp = ((*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
|
||||
$1 = &temp;
|
||||
%}
|
||||
%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE *& %{
|
||||
// plain pointer by reference(out)
|
||||
#if ($owner)
|
||||
if (*$1) {
|
||||
intrusive_ptr_add_ref(*$1);
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1, SWIG_intrusive_deleter< CONST TYPE >());
|
||||
} else {
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
|
||||
}
|
||||
#else
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_0);
|
||||
#endif
|
||||
%}
|
||||
|
||||
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > ($&1_type argp, SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
|
||||
// intrusive_ptr by value
|
||||
smartarg = *(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< CONST TYPE >**)&$input;
|
||||
if (smartarg) {
|
||||
$1 = SWIG_INTRUSIVE_PTR_NAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
|
||||
}
|
||||
%}
|
||||
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > %{
|
||||
if ($1) {
|
||||
intrusive_ptr_add_ref(result.get());
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(result.get(), SWIG_intrusive_deleter< CONST TYPE >());
|
||||
} else {
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{
|
||||
// shared_ptr by value
|
||||
smartarg = *($&1_ltype*)&$input;
|
||||
if (smartarg) $1 = *smartarg;
|
||||
%}
|
||||
%typemap(out) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{
|
||||
*($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0;
|
||||
%}
|
||||
|
||||
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & ($*1_ltype tempnull, $*1_ltype temp, SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
|
||||
// intrusive_ptr by reference
|
||||
if ( $input ) {
|
||||
smartarg = *(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< CONST TYPE >**)&$input;
|
||||
temp = SWIG_INTRUSIVE_PTR_NAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
|
||||
$1 = &temp;
|
||||
} else {
|
||||
$1 = &tempnull;
|
||||
}
|
||||
%}
|
||||
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{
|
||||
delete &($1);
|
||||
if ($self) {
|
||||
SWIG_INTRUSIVE_PTR_NAMESPACE::intrusive_ptr< CONST TYPE > * temp = new SWIG_INTRUSIVE_PTR_NAMESPACE::intrusive_ptr< CONST TYPE >(*$input);
|
||||
$1 = *temp;
|
||||
}
|
||||
%}
|
||||
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & %{
|
||||
if (*$1) {
|
||||
intrusive_ptr_add_ref($1->get());
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >());
|
||||
} else {
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * ($*1_ltype tempnull, $*1_ltype temp, SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
|
||||
// intrusive_ptr by pointer
|
||||
if ( $input ) {
|
||||
smartarg = *(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< CONST TYPE >**)&$input;
|
||||
temp = SWIG_INTRUSIVE_PTR_NAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
|
||||
$1 = &temp;
|
||||
} else {
|
||||
$1 = &tempnull;
|
||||
}
|
||||
%}
|
||||
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{
|
||||
delete $1;
|
||||
if ($self) $1 = new SWIG_INTRUSIVE_PTR_NAMESPACE::intrusive_ptr< CONST TYPE >(*$input);
|
||||
%}
|
||||
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * %{
|
||||
if ($1 && *$1) {
|
||||
intrusive_ptr_add_ref($1->get());
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1->get(), SWIG_intrusive_deleter< CONST TYPE >());
|
||||
} else {
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
|
||||
}
|
||||
if ($owner) delete $1;
|
||||
%}
|
||||
|
||||
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& (SWIG_INTRUSIVE_PTR_NAMESPACE::intrusive_ptr< CONST TYPE > temp, $*1_ltype tempp = 0, SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * smartarg) %{
|
||||
// intrusive_ptr by pointer reference
|
||||
smartarg = *(SWIG_INTRUSIVE_PTR_NAMESPACE::shared_ptr< CONST TYPE >**)&$input;
|
||||
if ($input) {
|
||||
temp = SWIG_INTRUSIVE_PTR_NAMESPACE::intrusive_ptr< CONST TYPE >(smartarg->get(), true);
|
||||
}
|
||||
tempp = &temp;
|
||||
$1 = &tempp;
|
||||
%}
|
||||
%typemap(memberin) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{
|
||||
if ($self) $1 = *$input;
|
||||
%}
|
||||
%typemap(out, fragment="SWIG_intrusive_deleter") SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& %{
|
||||
if (*$1 && **$1) {
|
||||
intrusive_ptr_add_ref((*$1)->get());
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >((*$1)->get(), SWIG_intrusive_deleter< CONST TYPE >());
|
||||
} else {
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = 0;
|
||||
}
|
||||
%}
|
||||
|
||||
// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
|
||||
%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
|
||||
#error "typemaps for $1_type not available"
|
||||
%}
|
||||
%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
|
||||
#error "typemaps for $1_type not available"
|
||||
%}
|
||||
|
||||
|
||||
%typemap (jni) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "jlong"
|
||||
%typemap (jtype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "long"
|
||||
%typemap (jstype) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "PROXYCLASS"
|
||||
%typemap(javain) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > &,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *,
|
||||
SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& "PROXYCLASS.getCPtr($javainput)"
|
||||
|
||||
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > & {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > * {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
%typemap(javaout) SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE > *& {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
|
||||
|
||||
%typemap(javaout) CONST TYPE {
|
||||
return new PROXYCLASS($jnicall, true);
|
||||
}
|
||||
%typemap(javaout) CONST TYPE & {
|
||||
return new PROXYCLASS($jnicall, true);
|
||||
}
|
||||
%typemap(javaout) CONST TYPE * {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
%typemap(javaout) CONST TYPE *& {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
|
||||
// Base proxy classes
|
||||
%typemap(javabody) TYPE %{
|
||||
private long swigCPtr;
|
||||
private boolean swigCMemOwnBase;
|
||||
|
||||
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
|
||||
swigCMemOwnBase = cMemoryOwn;
|
||||
swigCPtr = cPtr;
|
||||
}
|
||||
|
||||
protected static long getCPtr($javaclassname obj) {
|
||||
return (obj == null) ? 0 : obj.swigCPtr;
|
||||
}
|
||||
%}
|
||||
|
||||
// Derived proxy classes
|
||||
%typemap(javabody_derived) TYPE %{
|
||||
private long swigCPtr;
|
||||
private boolean swigCMemOwnDerived;
|
||||
|
||||
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
|
||||
super($imclassname.$javaclassname_SWIGSharedPtrUpcast(cPtr), true);
|
||||
swigCMemOwnDerived = cMemoryOwn;
|
||||
swigCPtr = cPtr;
|
||||
}
|
||||
|
||||
protected static long getCPtr($javaclassname obj) {
|
||||
return (obj == null) ? 0 : obj.swigCPtr;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE {
|
||||
if(swigCPtr != 0 && swigCMemOwnBase) {
|
||||
swigCMemOwnBase = false;
|
||||
$jnicall;
|
||||
}
|
||||
swigCPtr = 0;
|
||||
}
|
||||
|
||||
%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE {
|
||||
if(swigCPtr != 0 && swigCMemOwnDerived) {
|
||||
swigCMemOwnDerived = false;
|
||||
$jnicall;
|
||||
}
|
||||
swigCPtr = 0;
|
||||
super.delete();
|
||||
}
|
||||
|
||||
// CONST version needed ???? also for C#
|
||||
%typemap(jtype, nopgcpp="1") SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "long"
|
||||
%typemap(jtype, nopgcpp="1") SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "long"
|
||||
|
||||
|
||||
%template() SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
|
||||
%template() SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >;
|
||||
%enddef
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
%include <shared_ptr.i>
|
||||
|
||||
%define SWIG_INTRUSIVE_PTR_TYPEMAPS_NO_WRAP(PROXYCLASS, CONST, TYPE...)
|
||||
|
||||
%naturalvar TYPE;
|
||||
%naturalvar SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
|
||||
|
||||
// destructor mods
|
||||
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
|
||||
|
||||
|
||||
// plain value
|
||||
%typemap(in) CONST TYPE ($&1_type argp = 0) %{
|
||||
argp = (*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0;
|
||||
if (!argp) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
|
||||
return $null;
|
||||
}
|
||||
$1 = *argp; %}
|
||||
%typemap(out) CONST TYPE
|
||||
%{ *(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
|
||||
|
||||
// plain pointer
|
||||
%typemap(in) CONST TYPE * (SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
|
||||
smartarg = *(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input;
|
||||
$1 = (TYPE *)(smartarg ? smartarg->get() : 0); %}
|
||||
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
|
||||
*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = $1 ? new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
|
||||
%}
|
||||
|
||||
// plain reference
|
||||
%typemap(in) CONST TYPE & %{
|
||||
$1 = ($1_ltype)((*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
|
||||
if(!$1) {
|
||||
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
|
||||
return $null;
|
||||
} %}
|
||||
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
|
||||
%{ *(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
|
||||
|
||||
// plain pointer by reference
|
||||
%typemap(in) CONST TYPE *& ($*1_ltype temp = 0)
|
||||
%{ temp = ((*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
|
||||
$1 = &temp; %}
|
||||
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *&
|
||||
%{ *(SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
|
||||
|
||||
%typemap(in) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{
|
||||
// shared_ptr by value
|
||||
smartarg = *($&1_ltype*)&$input;
|
||||
if (smartarg) $1 = *smartarg;
|
||||
%}
|
||||
%typemap(out) SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > ANY_TYPE_SWIGSharedPtrUpcast %{
|
||||
*($&1_ltype*)&$result = $1 ? new $1_ltype($1) : 0;
|
||||
%}
|
||||
|
||||
// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
|
||||
%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
|
||||
#error "typemaps for $1_type not available"
|
||||
%}
|
||||
%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
|
||||
#error "typemaps for $1_type not available"
|
||||
%}
|
||||
|
||||
|
||||
%typemap (jni) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "jlong"
|
||||
%typemap (jtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "long"
|
||||
%typemap (jstype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "PROXYCLASS"
|
||||
%typemap (javain) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > "PROXYCLASS.getCPtr($javainput)"
|
||||
%typemap(javaout) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
|
||||
%typemap(javaout) CONST TYPE {
|
||||
return new PROXYCLASS($jnicall, true);
|
||||
}
|
||||
%typemap(javaout) CONST TYPE & {
|
||||
return new PROXYCLASS($jnicall, true);
|
||||
}
|
||||
%typemap(javaout) CONST TYPE * {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
%typemap(javaout) CONST TYPE *& {
|
||||
long cPtr = $jnicall;
|
||||
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
|
||||
}
|
||||
|
||||
// Base proxy classes
|
||||
%typemap(javabody) TYPE %{
|
||||
private long swigCPtr;
|
||||
private boolean swigCMemOwnBase;
|
||||
|
||||
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
|
||||
swigCMemOwnBase = cMemoryOwn;
|
||||
swigCPtr = cPtr;
|
||||
}
|
||||
|
||||
protected static long getCPtr($javaclassname obj) {
|
||||
return (obj == null) ? 0 : obj.swigCPtr;
|
||||
}
|
||||
%}
|
||||
|
||||
// Derived proxy classes
|
||||
%typemap(javabody_derived) TYPE %{
|
||||
private long swigCPtr;
|
||||
private boolean swigCMemOwnDerived;
|
||||
|
||||
protected $javaclassname(long cPtr, boolean cMemoryOwn) {
|
||||
super($imclassname.$javaclassname_SWIGSharedPtrUpcast(cPtr), true);
|
||||
swigCMemOwnDerived = cMemoryOwn;
|
||||
swigCPtr = cPtr;
|
||||
}
|
||||
|
||||
protected static long getCPtr($javaclassname obj) {
|
||||
return (obj == null) ? 0 : obj.swigCPtr;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") TYPE {
|
||||
if(swigCPtr != 0 && swigCMemOwnBase) {
|
||||
swigCMemOwnBase = false;
|
||||
$jnicall;
|
||||
}
|
||||
swigCPtr = 0;
|
||||
}
|
||||
|
||||
%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") TYPE {
|
||||
if(swigCPtr != 0 && swigCMemOwnDerived) {
|
||||
swigCMemOwnDerived = false;
|
||||
$jnicall;
|
||||
}
|
||||
swigCPtr = 0;
|
||||
super.delete();
|
||||
}
|
||||
|
||||
// CONST version needed ???? also for C#
|
||||
%typemap(jtype, nopgcpp="1") SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< TYPE > swigSharedPtrUpcast "long"
|
||||
%typemap(jtype, nopgcpp="1") SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast "long"
|
||||
|
||||
|
||||
%template() SWIG_INTRUSIVE_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
|
||||
%enddef
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue