summaryrefslogtreecommitdiff
path: root/Examples/php/enum
diff options
context:
space:
mode:
Diffstat (limited to 'Examples/php/enum')
-rw-r--r--Examples/php/enum/Makefile24
-rw-r--r--Examples/php/enum/example.cxx37
-rw-r--r--Examples/php/enum/example.h13
-rw-r--r--Examples/php/enum/example.i12
-rw-r--r--Examples/php/enum/runme.php32
5 files changed, 118 insertions, 0 deletions
diff --git a/Examples/php/enum/Makefile b/Examples/php/enum/Makefile
new file mode 100644
index 0000000..252a726
--- /dev/null
+++ b/Examples/php/enum/Makefile
@@ -0,0 +1,24 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT = -noproxy
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
+ php_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile php_clean
+ rm -f $(TARGET).php
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile php_run
diff --git a/Examples/php/enum/example.cxx b/Examples/php/enum/example.cxx
new file mode 100644
index 0000000..df7bb63
--- /dev/null
+++ b/Examples/php/enum/example.cxx
@@ -0,0 +1,37 @@
+/* File : example.cxx */
+
+#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/php/enum/example.h b/Examples/php/enum/example.h
new file mode 100644
index 0000000..525d62a
--- /dev/null
+++ b/Examples/php/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/php/enum/example.i b/Examples/php/enum/example.i
new file mode 100644
index 0000000..abf2547
--- /dev/null
+++ b/Examples/php/enum/example.i
@@ -0,0 +1,12 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+
+/* Let's just grab the original header file here */
+
+%include "example.h"
+
diff --git a/Examples/php/enum/runme.php b/Examples/php/enum/runme.php
new file mode 100644
index 0000000..55b0bc4
--- /dev/null
+++ b/Examples/php/enum/runme.php
@@ -0,0 +1,32 @@
+<?php
+
+require "example.php";
+
+# ----- Object creation -----
+
+# Print out the value of some enums
+print "*** color ***";
+print " RED =" . RED;
+print " BLUE =" . BLUE;
+print " GREEN =" . GREEN;
+
+print "\n*** Foo::speed ***";
+print " Foo_IMPULSE =" . Foo_IMPULSE;
+print " Foo_WARP =" . Foo_WARP;
+print " Foo_LUDICROUS =" . Foo_LUDICROUS;
+
+print "\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);
+
+print "\nTesting use of enum with class method\n";
+$f = new_Foo();
+
+Foo_enum_test($f,Foo_IMPULSE);
+Foo_enum_test($f,Foo_WARP);
+Foo_enum_test($f,Foo_LUDICROUS);
+
+?>