diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-10-20 14:25:24 -0700 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-10-20 14:25:24 -0700 |
commit | 87462517ca9ae8ece9ef3f97d3f105c72e74a4d7 (patch) | |
tree | b1f53acdcb1e33a774cfea6e17b950c6db54f8a9 /tests/simple/simple.cpp | |
parent | 61ba30d716dab670a5f2ed0ee2f6650375b2058d (diff) |
long types have been replaced with int16, int32 and int64 types to make code more readable and easier portable between architectures
longType and decimalType have been replace by numericType and floatType
Many arithmetic operators have been added to the value class
Solved various issues with copying and moving value objects
Diffstat (limited to 'tests/simple/simple.cpp')
-rw-r--r-- | tests/simple/simple.cpp | 97 |
1 files changed, 83 insertions, 14 deletions
diff --git a/tests/simple/simple.cpp b/tests/simple/simple.cpp index e90fe55..69cf9ce 100644 --- a/tests/simple/simple.cpp +++ b/tests/simple/simple.cpp @@ -15,6 +15,64 @@ */ using namespace std; + +Php::Value bubblesort(Php::Parameters ¶ms) +{ + cout << "start bubblesort" << endl; + + // the array that was passed + Php::Value array(params[0]); + + cout << "go return" << endl; + + return array; + + // size of the array + int size = array.size(); + + cout << "convert to native" << endl; + + int *x = new int[size]; + for (int i=0; i<size; i++) x[i] = array[i]; + + cout << "converted" << endl; + + + // outer loop + for (int i=0; i<size; i++) + { + // left value + int left = x[i]; +// cout << "left: " << left << endl; + + // inner loop + for (int j=i+1; j<size; j++) + { + // right value + int right = x[j]; + + if (left < right) continue; + + // swap values + x[i] = right; + x[j] = left; + left = right; + } + } + + cout << "algorithm end" << endl; + + Php::Value r; + + for (int i=0; i<size; i++) r[i] = x[i]; + + + delete[] x; + + // done + return r; +} + /** * Our own "my_plus" function that will be available in PHP * @param environment @@ -23,22 +81,29 @@ using namespace std; */ static Php::Value my_plus(Php::Environment &env, Php::Parameters ¶ms) { - int p1 = params[0]; - int p2 = params[1]; - return p1 + p2; - - cout << "global g1: " << env["g1"].stringValue() << endl; - cout << "global g2: " << env["g2"].stringValue() << endl; + Php::Value r(0); - Php::Global g(env["g3"]); + for (unsigned int i=0; i<params.size(); i++) r += params[i]; - g = "zo kan het ook"; + return r; - string output = env.call("strtoupper","test in lowercase"); - cout << "output: " << output << endl; - - return p1 + p2; +// int p1 = params[0]; +// int p2 = params[1]; +// return p1 + p2; +// +// cout << "global g1: " << env["g1"].stringValue() << endl; +// cout << "global g2: " << env["g2"].stringValue() << endl; +// +// Php::Global g(env["g3"]); +// +// g = "zo kan het ook"; +// +// string output = env.call("strtoupper","test in lowercase"); +// +// cout << "output: " << output << endl; +// +// return p1 + p2; } /** @@ -88,17 +153,21 @@ extern "C" // export the "get_module" function that will be called by the Zend engine PHPCPP_EXPORT void *get_module() { + cout << "call get_module()" << endl; + // create extension static Php::Extension extension("simple","1.0"); // define the functions extension.add("my_plus", my_plus, { - Php::ByVal("a", Php::longType), - Php::ByVal("b", Php::longType) +// Php::ByVal("a", Php::numericType), +// Php::ByVal("b", Php::numericType) // Php::ByVal("c", "MyClass"), // Php::ByRef("d", Php::stringType) }); + extension.add("bubblesort", bubblesort); + Php::Method<MyCustomClass> x(&MyCustomClass::myMethod); // define classes |