summaryrefslogtreecommitdiff
path: root/Examples/test-suite/reference_global_vars.i
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2009-08-18 20:56:02 +0000
committerLorry <lorry@roadtrain.codethink.co.uk>2012-09-25 16:59:08 +0000
commit9f8a09ed743cedd9547bf0661d518647966ab114 (patch)
tree9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/test-suite/reference_global_vars.i
downloadswig-tarball-master.tar.gz
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Examples/test-suite/reference_global_vars.i')
-rw-r--r--Examples/test-suite/reference_global_vars.i65
1 files changed, 65 insertions, 0 deletions
diff --git a/Examples/test-suite/reference_global_vars.i b/Examples/test-suite/reference_global_vars.i
new file mode 100644
index 0000000..8c80659
--- /dev/null
+++ b/Examples/test-suite/reference_global_vars.i
@@ -0,0 +1,65 @@
+// Tests global reference variables:
+// - all non const primitives
+// - const and non const class
+
+%module reference_global_vars
+
+%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK); /* memory leak when setting a ptr/ref variable */
+
+%inline %{
+class TestClass {
+public:
+ int num;
+ TestClass(int n = 0) : num(n) {}
+};
+%}
+
+// const class reference variable
+%{
+const TestClass& global_constTestClass = TestClass(33);
+%}
+%inline %{
+TestClass getconstTC() {
+ return global_constTestClass;
+}
+%}
+
+// Macro to help define similar functions
+%define ref(type,name)
+%{
+static type initial_value_##name;
+%}
+%inline %{
+static type &var_##name = initial_value_##name;
+type setref_##name(type &x) {
+ var_##name = x;
+ return var_##name;
+}
+type& createref_##name(type x) {
+ return *new type(x);
+}
+type value_##name(type &x) {
+ return x;
+}
+%}
+%enddef
+
+// primitive reference variables
+ref(bool, bool);
+ref(char, char);
+ref(unsigned char, unsigned_char);
+ref(signed char, signed_char);
+ref(short, short);
+ref(unsigned short, unsigned_short);
+ref(int, int);
+ref(unsigned int, unsigned_int);
+ref(long, long);
+ref(unsigned long, unsigned_long);
+ref(float, float);
+ref(double, double);
+ref(long long, long_long);
+ref(unsigned long long, unsigned_long_long);
+
+// class reference variable
+ref(TestClass, TestClass);
+