update swig on windows
This commit is contained in:
20
winx64/bin/swigwin-4.0.0/Examples/php/reference/Makefile
Normal file
20
winx64/bin/swigwin-4.0.0/Examples/php/reference/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
php_cpp
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||
49
winx64/bin/swigwin-4.0.0/Examples/php/reference/example.cxx
Normal file
49
winx64/bin/swigwin-4.0.0/Examples/php/reference/example.cxx
Normal file
@@ -0,0 +1,49 @@
|
||||
/* File : example.cxx */
|
||||
|
||||
/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
|
||||
#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
|
||||
# define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
#include "example.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
Vector operator+(const Vector &a, const Vector &b) {
|
||||
Vector r;
|
||||
r.x = a.x + b.x;
|
||||
r.y = a.y + b.y;
|
||||
r.z = a.z + b.z;
|
||||
return r;
|
||||
}
|
||||
|
||||
char *Vector::as_string() {
|
||||
static char temp[512];
|
||||
sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z);
|
||||
return temp;
|
||||
}
|
||||
|
||||
VectorArray::VectorArray(int size) {
|
||||
items = new Vector[size];
|
||||
maxsize = size;
|
||||
printf("VectorArray new: self=%p\n", (void *)this);
|
||||
}
|
||||
|
||||
VectorArray::~VectorArray() {
|
||||
printf("VectorArray delete: self=%p\n", (void *)this);
|
||||
delete [] items;
|
||||
}
|
||||
|
||||
Vector &VectorArray::operator[](int index) {
|
||||
printf("VectorArray: read[%d] self=%p\n", index, (void *)this);
|
||||
if ((index < 0) || (index >= maxsize)) {
|
||||
printf("Panic! Array index out of bounds.\n");
|
||||
exit(1);
|
||||
}
|
||||
return items[index];
|
||||
}
|
||||
|
||||
int VectorArray::size() {
|
||||
printf("VectorArray: size %d self=%p\n", maxsize, (void *)this);
|
||||
return maxsize;
|
||||
}
|
||||
22
winx64/bin/swigwin-4.0.0/Examples/php/reference/example.h
Normal file
22
winx64/bin/swigwin-4.0.0/Examples/php/reference/example.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* File : example.h */
|
||||
|
||||
class Vector {
|
||||
private:
|
||||
double x,y,z;
|
||||
public:
|
||||
Vector() : x(0), y(0), z(0) { }
|
||||
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
|
||||
friend Vector operator+(const Vector &a, const Vector &b);
|
||||
char *as_string();
|
||||
};
|
||||
|
||||
class VectorArray {
|
||||
private:
|
||||
Vector *items;
|
||||
int maxsize;
|
||||
public:
|
||||
VectorArray(int maxsize);
|
||||
~VectorArray();
|
||||
Vector &operator[](int);
|
||||
int size();
|
||||
};
|
||||
43
winx64/bin/swigwin-4.0.0/Examples/php/reference/example.i
Normal file
43
winx64/bin/swigwin-4.0.0/Examples/php/reference/example.i
Normal file
@@ -0,0 +1,43 @@
|
||||
/* File : example.i */
|
||||
|
||||
/* This file has a few "typical" uses of C++ references. */
|
||||
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
class Vector {
|
||||
public:
|
||||
Vector(double x, double y, double z);
|
||||
~Vector();
|
||||
char *as_string();
|
||||
};
|
||||
|
||||
/* This helper function calls an overloaded operator */
|
||||
%inline %{
|
||||
Vector addv(Vector &a, Vector &b) {
|
||||
return a+b;
|
||||
}
|
||||
%}
|
||||
|
||||
/* Wrapper around an array of vectors class */
|
||||
|
||||
class VectorArray {
|
||||
public:
|
||||
VectorArray(int maxsize);
|
||||
~VectorArray();
|
||||
int size();
|
||||
|
||||
/* This wrapper provides an alternative to the [] operator */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
printf("VectorArray extended get: %p %d\n", (void *)$self, index);
|
||||
return (*$self)[index];
|
||||
}
|
||||
void set(int index, Vector &a) {
|
||||
(*$self)[index] = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
49
winx64/bin/swigwin-4.0.0/Examples/php/reference/runme.php
Normal file
49
winx64/bin/swigwin-4.0.0/Examples/php/reference/runme.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
# This file illustrates the manipulation of C++ references in PHP.
|
||||
|
||||
require "example.php";
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
print "Creating some objects:\n";
|
||||
$a = new Vector(3, 4, 5);
|
||||
$b = new Vector(10, 11, 12);
|
||||
|
||||
print " Created a: {$a->as_string()}\n";
|
||||
print " Created b: {$b->as_string()}\n";
|
||||
|
||||
# ----- Call an overloaded operator -----
|
||||
|
||||
# This calls the wrapper we placed around
|
||||
#
|
||||
# operator+(const Vector &a, const Vector &)
|
||||
#
|
||||
# It returns a new allocated object.
|
||||
|
||||
print "Adding a+b\n";
|
||||
$c = example::addv($a, $b);
|
||||
print " a+b ={$c->as_string()}\n";
|
||||
|
||||
# ----- Create a vector array -----
|
||||
|
||||
print "Creating an array of vectors\n";
|
||||
$va = new VectorArray(10);
|
||||
|
||||
print " va: size={$va->size()}\n";
|
||||
|
||||
# ----- Set some values in the array -----
|
||||
|
||||
# These operators copy the value of $a and $b to the vector array
|
||||
$va->set(0, $a);
|
||||
$va->set(1, $b);
|
||||
$va->set(2, addv($a, $b));
|
||||
|
||||
# Get some values from the array
|
||||
|
||||
print "Getting some array values\n";
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
print " va[$i] = {$va->get($i)->as_string()}\n";
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user