Convert to unix fileformat
This commit is contained in:
parent
bd67f57921
commit
079165abe2
22 changed files with 2479 additions and 2479 deletions
|
|
@ -1,246 +1,246 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* li_std_map_runme.cs
|
||||
*
|
||||
* SWIG C# tester for std_map.i
|
||||
* This class tests all the functionality of the std_map.i wrapper.
|
||||
* Upon successful testing, the main function doesn't print out anything.
|
||||
* If any error is found - it will be printed on the screen.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using li_std_mapNamespace;
|
||||
|
||||
public class li_std_map_runme {
|
||||
|
||||
private static readonly int collectionSize = 20;
|
||||
private static readonly int midCollection = collectionSize / 2;
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
// Set up an int int map
|
||||
StringIntMap simap = new StringIntMap();
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
int val = i * 18;
|
||||
simap.Add(i.ToString(), val);
|
||||
}
|
||||
|
||||
// Count property test
|
||||
if (simap.Count != collectionSize)
|
||||
throw new Exception("Count test failed");
|
||||
|
||||
// IsReadOnly property test
|
||||
if (simap.IsReadOnly)
|
||||
throw new Exception("IsReadOnly test failed");
|
||||
|
||||
// Item indexing test
|
||||
simap["0"] = 200;
|
||||
if (simap["0"] != 200)
|
||||
throw new Exception("Item property test failed");
|
||||
simap["0"] = 0 * 18;
|
||||
|
||||
// ContainsKey() test
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
if (!simap.ContainsKey(i.ToString()))
|
||||
throw new Exception("ContainsKey test " + i + " failed");
|
||||
}
|
||||
|
||||
// ContainsKey() test
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
if (!simap.Contains(new KeyValuePair<string, int>(i.ToString(), i * 18)))
|
||||
throw new Exception("Contains test " + i + " failed");
|
||||
}
|
||||
|
||||
// TryGetValue() test
|
||||
int value;
|
||||
bool rc = simap.TryGetValue("3", out value);
|
||||
if (rc != true || value != (3 * 18))
|
||||
throw new Exception("TryGetValue test 1 failed");
|
||||
|
||||
rc = simap.TryGetValue("-1", out value);
|
||||
if (rc != false)
|
||||
throw new Exception("TryGetValue test 2 failed");
|
||||
|
||||
// Keys and Values test
|
||||
{
|
||||
IList<string> keys = new List<string>(simap.Keys);
|
||||
IList<int> values = new List<int>(simap.Values);
|
||||
Dictionary<string, int> check = new Dictionary<string, int>();
|
||||
if (keys.Count != collectionSize)
|
||||
throw new Exception("Keys count test failed");
|
||||
|
||||
if (values.Count != collectionSize)
|
||||
throw new Exception("Values count test failed");
|
||||
|
||||
for (int i = 0; i < keys.Count; i++)
|
||||
{
|
||||
if (simap[keys[i]] != values[i])
|
||||
throw new Exception("Keys and values test failed for index " + i);
|
||||
check.Add(keys[i], values[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
if (!check.ContainsKey(i.ToString()))
|
||||
throw new Exception("Keys and Values ContainsKey test " + i + " failed");
|
||||
}
|
||||
}
|
||||
|
||||
// Add and Remove test
|
||||
for (int i = 100; i < 103; i++)
|
||||
{
|
||||
simap.Add(i.ToString(), i * 18);
|
||||
if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
|
||||
throw new Exception("Add test failed for index " + i);
|
||||
|
||||
simap.Remove(i.ToString());
|
||||
if (simap.ContainsKey(i.ToString()))
|
||||
throw new Exception("Remove test failed for index " + i);
|
||||
}
|
||||
|
||||
for (int i = 200; i < 203; i++)
|
||||
{
|
||||
simap.Add(new KeyValuePair<string, int>(i.ToString(), i * 18));
|
||||
if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
|
||||
throw new Exception("Add explicit test failed for index " + i);
|
||||
|
||||
simap.Remove(new KeyValuePair<string, int>(i.ToString(), i * 18));
|
||||
if (simap.ContainsKey(i.ToString()))
|
||||
throw new Exception("Remove explicit test failed for index " + i);
|
||||
}
|
||||
|
||||
// Duplicate key test
|
||||
try
|
||||
{
|
||||
simap.Add("3", 0);
|
||||
throw new Exception("Adding duplicate key test failed");
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
}
|
||||
|
||||
// CopyTo() test
|
||||
{
|
||||
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[collectionSize];
|
||||
simap.CopyTo(outputarray);
|
||||
foreach (KeyValuePair<string, int> val in outputarray)
|
||||
{
|
||||
if (simap[val.Key] != val.Value)
|
||||
throw new Exception("CopyTo (1) test failed, index:" + val.Key);
|
||||
}
|
||||
}
|
||||
{
|
||||
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[midCollection + collectionSize];
|
||||
simap.CopyTo(outputarray, midCollection);
|
||||
for (int i = midCollection; i < midCollection + collectionSize; i++)
|
||||
{
|
||||
KeyValuePair<string, int> val = outputarray[i];
|
||||
if (simap[val.Key] != val.Value)
|
||||
throw new Exception("CopyTo (2) test failed, index:" + val.Key);
|
||||
}
|
||||
}
|
||||
{
|
||||
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[collectionSize - 1];
|
||||
try
|
||||
{
|
||||
simap.CopyTo(outputarray);
|
||||
throw new Exception("CopyTo (4) test failed");
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Clear test
|
||||
simap.Clear();
|
||||
if (simap.Count != 0)
|
||||
throw new Exception("Clear test failed");
|
||||
|
||||
// Test wrapped methods
|
||||
for (int i = 1; i <= 5; i++)
|
||||
{
|
||||
simap[i.ToString()] = i;
|
||||
}
|
||||
double avg = li_std_map.valueAverage(simap);
|
||||
if (avg != 3.0)
|
||||
throw new Exception("Wrapped method valueAverage test failed. Got " + avg);
|
||||
|
||||
string keyStringified = li_std_map.stringifyKeys(simap);
|
||||
if (keyStringified != " 1 2 3 4 5")
|
||||
throw new Exception("Wrapped method stringifyKeys test failed. Got " + keyStringified);
|
||||
|
||||
// Test a map with a new complex type (Struct)
|
||||
{
|
||||
IntStructMap ismap = new IntStructMap();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
ismap.Add(i, new Struct(i * 10.1));
|
||||
}
|
||||
|
||||
if (ismap.Count != 10)
|
||||
throw new Exception("Count test on complex type map failed");
|
||||
|
||||
foreach (KeyValuePair<int, Struct> p in ismap)
|
||||
{
|
||||
if ((p.Key * 10.1) != p.Value.num)
|
||||
throw new Exception("Iteration test on complex type map failed for index " + p.Key);
|
||||
}
|
||||
}
|
||||
|
||||
// Test a map of pointers
|
||||
{
|
||||
IntStructPtrMap ispmap = new IntStructPtrMap();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
ispmap.Add(i, new Struct(i * 10.1));
|
||||
}
|
||||
|
||||
if (ispmap.Count != 10)
|
||||
throw new Exception("Count test on complex type pointer map failed");
|
||||
|
||||
foreach (KeyValuePair<int, Struct> p in ispmap)
|
||||
{
|
||||
if ((p.Key * 10.1) != p.Value.num)
|
||||
throw new Exception("Iteration test on complex type pointer map failed for index " + p.Key);
|
||||
}
|
||||
}
|
||||
{
|
||||
IntStructConstPtrMap iscpmap = new IntStructConstPtrMap();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
iscpmap.Add(i, new Struct(i * 10.1));
|
||||
}
|
||||
|
||||
if (iscpmap.Count != 10)
|
||||
throw new Exception("Count test on complex type const pointer map failed");
|
||||
|
||||
foreach (KeyValuePair<int, Struct> p in iscpmap)
|
||||
{
|
||||
if ((p.Key * 10.1) != p.Value.num)
|
||||
throw new Exception("Iteration test on complex type const pointer map failed for index " + p.Key);
|
||||
}
|
||||
}
|
||||
|
||||
// Test complex type as key (Struct)
|
||||
{
|
||||
StructIntMap limap = new StructIntMap();
|
||||
Struct s7 = new Struct(7);
|
||||
Struct s8 = new Struct(8);
|
||||
limap[s7] = 8;
|
||||
if (limap[s7] != 8)
|
||||
throw new Exception("Assignment test on complex key map failed");
|
||||
|
||||
if (!limap.ContainsKey(s7))
|
||||
throw new Exception("Key test (1) on complex key map failed");
|
||||
|
||||
if (limap.ContainsKey(s8))
|
||||
throw new Exception("Key test (2) on complex key map failed");
|
||||
}
|
||||
|
||||
// All done
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* li_std_map_runme.cs
|
||||
*
|
||||
* SWIG C# tester for std_map.i
|
||||
* This class tests all the functionality of the std_map.i wrapper.
|
||||
* Upon successful testing, the main function doesn't print out anything.
|
||||
* If any error is found - it will be printed on the screen.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using li_std_mapNamespace;
|
||||
|
||||
public class li_std_map_runme {
|
||||
|
||||
private static readonly int collectionSize = 20;
|
||||
private static readonly int midCollection = collectionSize / 2;
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
// Set up an int int map
|
||||
StringIntMap simap = new StringIntMap();
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
int val = i * 18;
|
||||
simap.Add(i.ToString(), val);
|
||||
}
|
||||
|
||||
// Count property test
|
||||
if (simap.Count != collectionSize)
|
||||
throw new Exception("Count test failed");
|
||||
|
||||
// IsReadOnly property test
|
||||
if (simap.IsReadOnly)
|
||||
throw new Exception("IsReadOnly test failed");
|
||||
|
||||
// Item indexing test
|
||||
simap["0"] = 200;
|
||||
if (simap["0"] != 200)
|
||||
throw new Exception("Item property test failed");
|
||||
simap["0"] = 0 * 18;
|
||||
|
||||
// ContainsKey() test
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
if (!simap.ContainsKey(i.ToString()))
|
||||
throw new Exception("ContainsKey test " + i + " failed");
|
||||
}
|
||||
|
||||
// ContainsKey() test
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
if (!simap.Contains(new KeyValuePair<string, int>(i.ToString(), i * 18)))
|
||||
throw new Exception("Contains test " + i + " failed");
|
||||
}
|
||||
|
||||
// TryGetValue() test
|
||||
int value;
|
||||
bool rc = simap.TryGetValue("3", out value);
|
||||
if (rc != true || value != (3 * 18))
|
||||
throw new Exception("TryGetValue test 1 failed");
|
||||
|
||||
rc = simap.TryGetValue("-1", out value);
|
||||
if (rc != false)
|
||||
throw new Exception("TryGetValue test 2 failed");
|
||||
|
||||
// Keys and Values test
|
||||
{
|
||||
IList<string> keys = new List<string>(simap.Keys);
|
||||
IList<int> values = new List<int>(simap.Values);
|
||||
Dictionary<string, int> check = new Dictionary<string, int>();
|
||||
if (keys.Count != collectionSize)
|
||||
throw new Exception("Keys count test failed");
|
||||
|
||||
if (values.Count != collectionSize)
|
||||
throw new Exception("Values count test failed");
|
||||
|
||||
for (int i = 0; i < keys.Count; i++)
|
||||
{
|
||||
if (simap[keys[i]] != values[i])
|
||||
throw new Exception("Keys and values test failed for index " + i);
|
||||
check.Add(keys[i], values[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < collectionSize; i++)
|
||||
{
|
||||
if (!check.ContainsKey(i.ToString()))
|
||||
throw new Exception("Keys and Values ContainsKey test " + i + " failed");
|
||||
}
|
||||
}
|
||||
|
||||
// Add and Remove test
|
||||
for (int i = 100; i < 103; i++)
|
||||
{
|
||||
simap.Add(i.ToString(), i * 18);
|
||||
if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
|
||||
throw new Exception("Add test failed for index " + i);
|
||||
|
||||
simap.Remove(i.ToString());
|
||||
if (simap.ContainsKey(i.ToString()))
|
||||
throw new Exception("Remove test failed for index " + i);
|
||||
}
|
||||
|
||||
for (int i = 200; i < 203; i++)
|
||||
{
|
||||
simap.Add(new KeyValuePair<string, int>(i.ToString(), i * 18));
|
||||
if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
|
||||
throw new Exception("Add explicit test failed for index " + i);
|
||||
|
||||
simap.Remove(new KeyValuePair<string, int>(i.ToString(), i * 18));
|
||||
if (simap.ContainsKey(i.ToString()))
|
||||
throw new Exception("Remove explicit test failed for index " + i);
|
||||
}
|
||||
|
||||
// Duplicate key test
|
||||
try
|
||||
{
|
||||
simap.Add("3", 0);
|
||||
throw new Exception("Adding duplicate key test failed");
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
}
|
||||
|
||||
// CopyTo() test
|
||||
{
|
||||
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[collectionSize];
|
||||
simap.CopyTo(outputarray);
|
||||
foreach (KeyValuePair<string, int> val in outputarray)
|
||||
{
|
||||
if (simap[val.Key] != val.Value)
|
||||
throw new Exception("CopyTo (1) test failed, index:" + val.Key);
|
||||
}
|
||||
}
|
||||
{
|
||||
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[midCollection + collectionSize];
|
||||
simap.CopyTo(outputarray, midCollection);
|
||||
for (int i = midCollection; i < midCollection + collectionSize; i++)
|
||||
{
|
||||
KeyValuePair<string, int> val = outputarray[i];
|
||||
if (simap[val.Key] != val.Value)
|
||||
throw new Exception("CopyTo (2) test failed, index:" + val.Key);
|
||||
}
|
||||
}
|
||||
{
|
||||
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[collectionSize - 1];
|
||||
try
|
||||
{
|
||||
simap.CopyTo(outputarray);
|
||||
throw new Exception("CopyTo (4) test failed");
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// Clear test
|
||||
simap.Clear();
|
||||
if (simap.Count != 0)
|
||||
throw new Exception("Clear test failed");
|
||||
|
||||
// Test wrapped methods
|
||||
for (int i = 1; i <= 5; i++)
|
||||
{
|
||||
simap[i.ToString()] = i;
|
||||
}
|
||||
double avg = li_std_map.valueAverage(simap);
|
||||
if (avg != 3.0)
|
||||
throw new Exception("Wrapped method valueAverage test failed. Got " + avg);
|
||||
|
||||
string keyStringified = li_std_map.stringifyKeys(simap);
|
||||
if (keyStringified != " 1 2 3 4 5")
|
||||
throw new Exception("Wrapped method stringifyKeys test failed. Got " + keyStringified);
|
||||
|
||||
// Test a map with a new complex type (Struct)
|
||||
{
|
||||
IntStructMap ismap = new IntStructMap();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
ismap.Add(i, new Struct(i * 10.1));
|
||||
}
|
||||
|
||||
if (ismap.Count != 10)
|
||||
throw new Exception("Count test on complex type map failed");
|
||||
|
||||
foreach (KeyValuePair<int, Struct> p in ismap)
|
||||
{
|
||||
if ((p.Key * 10.1) != p.Value.num)
|
||||
throw new Exception("Iteration test on complex type map failed for index " + p.Key);
|
||||
}
|
||||
}
|
||||
|
||||
// Test a map of pointers
|
||||
{
|
||||
IntStructPtrMap ispmap = new IntStructPtrMap();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
ispmap.Add(i, new Struct(i * 10.1));
|
||||
}
|
||||
|
||||
if (ispmap.Count != 10)
|
||||
throw new Exception("Count test on complex type pointer map failed");
|
||||
|
||||
foreach (KeyValuePair<int, Struct> p in ispmap)
|
||||
{
|
||||
if ((p.Key * 10.1) != p.Value.num)
|
||||
throw new Exception("Iteration test on complex type pointer map failed for index " + p.Key);
|
||||
}
|
||||
}
|
||||
{
|
||||
IntStructConstPtrMap iscpmap = new IntStructConstPtrMap();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
iscpmap.Add(i, new Struct(i * 10.1));
|
||||
}
|
||||
|
||||
if (iscpmap.Count != 10)
|
||||
throw new Exception("Count test on complex type const pointer map failed");
|
||||
|
||||
foreach (KeyValuePair<int, Struct> p in iscpmap)
|
||||
{
|
||||
if ((p.Key * 10.1) != p.Value.num)
|
||||
throw new Exception("Iteration test on complex type const pointer map failed for index " + p.Key);
|
||||
}
|
||||
}
|
||||
|
||||
// Test complex type as key (Struct)
|
||||
{
|
||||
StructIntMap limap = new StructIntMap();
|
||||
Struct s7 = new Struct(7);
|
||||
Struct s8 = new Struct(8);
|
||||
limap[s7] = 8;
|
||||
if (limap[s7] != 8)
|
||||
throw new Exception("Assignment test on complex key map failed");
|
||||
|
||||
if (!limap.ContainsKey(s7))
|
||||
throw new Exception("Key test (1) on complex key map failed");
|
||||
|
||||
if (limap.ContainsKey(s8))
|
||||
throw new Exception("Key test (2) on complex key map failed");
|
||||
}
|
||||
|
||||
// All done
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,498 +1,498 @@
|
|||
// 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);
|
||||
%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerived;
|
||||
%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerivedDerived;
|
||||
|
||||
%inline %{
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#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
|
||||
# define SWIG_SHARED_PTR_NAMESPACE SwigBoost
|
||||
#endif
|
||||
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP)
|
||||
#define INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED
|
||||
#endif
|
||||
|
||||
#if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED)
|
||||
|
||||
%include <boost_intrusive_ptr.i>
|
||||
%intrusive_ptr(Space::Klass)
|
||||
%intrusive_ptr_no_wrap(Space::KlassWithoutRefCount)
|
||||
%intrusive_ptr(Space::KlassDerived)
|
||||
%intrusive_ptr(Space::KlassDerivedDerived)
|
||||
|
||||
//For the use_count shared_ptr functions
|
||||
#if defined(SWIGJAVA)
|
||||
%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)"
|
||||
|
||||
#elif defined(SWIGCSHARP)
|
||||
// TODO!
|
||||
#endif
|
||||
|
||||
#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 *const& pointerreftest(Klass *const& 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 *const&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
|
||||
%intrusive_ptr(Base<int, double>)
|
||||
%intrusive_ptr(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; }
|
||||
};
|
||||
%}
|
||||
|
||||
%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
|
||||
}
|
||||
%}
|
||||
|
||||
// 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);
|
||||
%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerived;
|
||||
%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerivedDerived;
|
||||
|
||||
%inline %{
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#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
|
||||
# define SWIG_SHARED_PTR_NAMESPACE SwigBoost
|
||||
#endif
|
||||
|
||||
#if defined(SWIGJAVA) || defined(SWIGCSHARP)
|
||||
#define INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED
|
||||
#endif
|
||||
|
||||
#if defined(INTRUSIVE_PTR_WRAPPERS_IMPLEMENTED)
|
||||
|
||||
%include <boost_intrusive_ptr.i>
|
||||
%intrusive_ptr(Space::Klass)
|
||||
%intrusive_ptr_no_wrap(Space::KlassWithoutRefCount)
|
||||
%intrusive_ptr(Space::KlassDerived)
|
||||
%intrusive_ptr(Space::KlassDerivedDerived)
|
||||
|
||||
//For the use_count shared_ptr functions
|
||||
#if defined(SWIGJAVA)
|
||||
%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)"
|
||||
|
||||
#elif defined(SWIGCSHARP)
|
||||
// TODO!
|
||||
#endif
|
||||
|
||||
#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 *const& pointerreftest(Klass *const& 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 *const&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
|
||||
%intrusive_ptr(Base<int, double>)
|
||||
%intrusive_ptr(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; }
|
||||
};
|
||||
%}
|
||||
|
||||
%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
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +1,42 @@
|
|||
require("import") -- the import fn
|
||||
import("li_typemaps") -- import code
|
||||
|
||||
-- catch "undefined" global variables
|
||||
local env = _ENV -- Lua 5.2
|
||||
if not env then env = getfenv () end -- Lua 5.1
|
||||
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||
|
||||
-- Check double INPUT typemaps
|
||||
assert(li_typemaps.in_double(22.22) == 22.22)
|
||||
assert(li_typemaps.inr_double(22.22) == 22.22)
|
||||
|
||||
-- Check double OUTPUT typemaps
|
||||
assert(li_typemaps.out_double(22.22) == 22.22)
|
||||
assert(li_typemaps.outr_double(22.22) == 22.22)
|
||||
|
||||
-- Check double INOUT typemaps
|
||||
assert(li_typemaps.inout_double(22.22) == 22.22)
|
||||
assert(li_typemaps.inoutr_double(22.22) == 22.22)
|
||||
|
||||
-- check long long
|
||||
assert(li_typemaps.in_ulonglong(20)==20)
|
||||
assert(li_typemaps.inr_ulonglong(20)==20)
|
||||
assert(li_typemaps.out_ulonglong(20)==20)
|
||||
assert(li_typemaps.outr_ulonglong(20)==20)
|
||||
assert(li_typemaps.inout_ulonglong(20)==20)
|
||||
assert(li_typemaps.inoutr_ulonglong(20)==20)
|
||||
|
||||
-- check bools
|
||||
assert(li_typemaps.in_bool(true)==true)
|
||||
assert(li_typemaps.inr_bool(false)==false)
|
||||
assert(li_typemaps.out_bool(true)==true)
|
||||
assert(li_typemaps.outr_bool(false)==false)
|
||||
assert(li_typemaps.inout_bool(true)==true)
|
||||
assert(li_typemaps.inoutr_bool(false)==false)
|
||||
|
||||
-- the others
|
||||
a,b=li_typemaps.inoutr_int2(1,2)
|
||||
assert(a==1 and b==2)
|
||||
|
||||
f,i=li_typemaps.out_foo(10)
|
||||
assert(f.a==10 and i==20)
|
||||
require("import") -- the import fn
|
||||
import("li_typemaps") -- import code
|
||||
|
||||
-- catch "undefined" global variables
|
||||
local env = _ENV -- Lua 5.2
|
||||
if not env then env = getfenv () end -- Lua 5.1
|
||||
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||
|
||||
-- Check double INPUT typemaps
|
||||
assert(li_typemaps.in_double(22.22) == 22.22)
|
||||
assert(li_typemaps.inr_double(22.22) == 22.22)
|
||||
|
||||
-- Check double OUTPUT typemaps
|
||||
assert(li_typemaps.out_double(22.22) == 22.22)
|
||||
assert(li_typemaps.outr_double(22.22) == 22.22)
|
||||
|
||||
-- Check double INOUT typemaps
|
||||
assert(li_typemaps.inout_double(22.22) == 22.22)
|
||||
assert(li_typemaps.inoutr_double(22.22) == 22.22)
|
||||
|
||||
-- check long long
|
||||
assert(li_typemaps.in_ulonglong(20)==20)
|
||||
assert(li_typemaps.inr_ulonglong(20)==20)
|
||||
assert(li_typemaps.out_ulonglong(20)==20)
|
||||
assert(li_typemaps.outr_ulonglong(20)==20)
|
||||
assert(li_typemaps.inout_ulonglong(20)==20)
|
||||
assert(li_typemaps.inoutr_ulonglong(20)==20)
|
||||
|
||||
-- check bools
|
||||
assert(li_typemaps.in_bool(true)==true)
|
||||
assert(li_typemaps.inr_bool(false)==false)
|
||||
assert(li_typemaps.out_bool(true)==true)
|
||||
assert(li_typemaps.outr_bool(false)==false)
|
||||
assert(li_typemaps.inout_bool(true)==true)
|
||||
assert(li_typemaps.inoutr_bool(false)==false)
|
||||
|
||||
-- the others
|
||||
a,b=li_typemaps.inoutr_int2(1,2)
|
||||
assert(a==1 and b==2)
|
||||
|
||||
f,i=li_typemaps.out_foo(10)
|
||||
assert(f.a==10 and i==20)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue