diff options
Diffstat (limited to 'Examples/tcl/enum')
| -rw-r--r-- | Examples/tcl/enum/Makefile | 19 | ||||
| -rw-r--r-- | Examples/tcl/enum/example.cxx | 37 | ||||
| -rw-r--r-- | Examples/tcl/enum/example.h | 13 | ||||
| -rw-r--r-- | Examples/tcl/enum/example.i | 11 | ||||
| -rw-r--r-- | Examples/tcl/enum/index.html | 35 | ||||
| -rw-r--r-- | Examples/tcl/enum/runme.tcl | 32 |
6 files changed, 147 insertions, 0 deletions
diff --git a/Examples/tcl/enum/Makefile b/Examples/tcl/enum/Makefile new file mode 100644 index 0000000..c01283c --- /dev/null +++ b/Examples/tcl/enum/Makefile @@ -0,0 +1,19 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +LIBS = -lm + +all:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tcl_cpp + +static:: + $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static + +clean:: + $(MAKE) -f $(TOP)/Makefile tcl_clean + +check: all diff --git a/Examples/tcl/enum/example.cxx b/Examples/tcl/enum/example.cxx new file mode 100644 index 0000000..6785e57 --- /dev/null +++ b/Examples/tcl/enum/example.cxx @@ -0,0 +1,37 @@ +/* File : example.c */ + +#include "example.h" +#include <stdio.h> + +void Foo::enum_test(speed s) { + if (s == IMPULSE) { + printf("IMPULSE speed\n"); + } else if (s == WARP) { + printf("WARP speed\n"); + } else if (s == LUDICROUS) { + printf("LUDICROUS speed\n"); + } else { + printf("Unknown speed\n"); + } +} + +void enum_test(color c, Foo::speed s) { + if (c == RED) { + printf("color = RED, "); + } else if (c == BLUE) { + printf("color = BLUE, "); + } else if (c == GREEN) { + printf("color = GREEN, "); + } else { + printf("color = Unknown color!, "); + } + if (s == Foo::IMPULSE) { + printf("speed = IMPULSE speed\n"); + } else if (s == Foo::WARP) { + printf("speed = WARP speed\n"); + } else if (s == Foo::LUDICROUS) { + printf("speed = LUDICROUS speed\n"); + } else { + printf("speed = Unknown speed!\n"); + } +} diff --git a/Examples/tcl/enum/example.h b/Examples/tcl/enum/example.h new file mode 100644 index 0000000..525d62a --- /dev/null +++ b/Examples/tcl/enum/example.h @@ -0,0 +1,13 @@ +/* File : example.h */ + +enum color { RED, BLUE, GREEN }; + +class Foo { + public: + Foo() { } + enum speed { IMPULSE, WARP, LUDICROUS }; + void enum_test(speed s); +}; + +void enum_test(color c, Foo::speed s); + diff --git a/Examples/tcl/enum/example.i b/Examples/tcl/enum/example.i new file mode 100644 index 0000000..23ee8a8 --- /dev/null +++ b/Examples/tcl/enum/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ + +%include "example.h" + diff --git a/Examples/tcl/enum/index.html b/Examples/tcl/enum/index.html new file mode 100644 index 0000000..559f6a8 --- /dev/null +++ b/Examples/tcl/enum/index.html @@ -0,0 +1,35 @@ +<html> +<head> +<title>SWIG:Examples:tcl:enum</title> +</head> + +<body bgcolor="#ffffff"> + + +<tt>SWIG/Examples/tcl/enum/</tt> +<hr> + +<H2>Wrapping enumerations</H2> + +<p> +This example tests SWIG's ability to wrap enumerations. By default, SWIG +converts enumeration specifications into integer constants. Further use +of enumerated types are handled as integers. + +<ul> +<li><a href="example.h">example.h</a>. Header file containing some enums. +<li><a href="example.i">example.i</a>. Interface file. +<li><a href="runme.tcl">runme.tcl</a>. Sample Tcl script. +</ul> + +<h2>Notes</h2> + +<ul> +<li>SWIG allows arbitrary integers to be passed as enum values. However, +the result of passing an integer not corresponding to any of the values +specified in the <tt>enum</tt> specification is undefined. +</ul> + +<hr> +</body> +</html> diff --git a/Examples/tcl/enum/runme.tcl b/Examples/tcl/enum/runme.tcl new file mode 100644 index 0000000..3d4e52a --- /dev/null +++ b/Examples/tcl/enum/runme.tcl @@ -0,0 +1,32 @@ +# file: runme.tcl + +catch { load ./example[info sharedlibextension] example} + +# ----- Object creation ----- + +# Print out the value of some enums +puts "*** color ***" +puts " RED = $RED" +puts " BLUE = $BLUE" +puts " GREEN = $GREEN" + +puts "\n*** Foo::speed ***" +puts " Foo_IMPULSE = $Foo_IMPULSE" +puts " Foo_WARP = $Foo_WARP" +puts " Foo_LUDICROUS = $Foo_LUDICROUS" + + +puts "\nTesting use of enums with functions\n" + +enum_test $RED $Foo_IMPULSE +enum_test $BLUE $Foo_WARP +enum_test $GREEN $Foo_LUDICROUS +enum_test 1234 5678 + +puts "\nTesting use of enum with class method" +Foo f + +f enum_test $Foo_IMPULSE +f enum_test $Foo_WARP +f enum_test $Foo_LUDICROUS + |
