diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-10 10:08:58 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-10 10:08:58 +0100 |
commit | fb80367d418f9a9fb059c98d5aec80febeb3bd23 (patch) | |
tree | d1a1c40b8339ba36eaac61c64753c45f1e5e0642 | |
parent | bdbc7b6c2430aaf396f79fc9ca097534f2c964ac (diff) | |
parent | 7320131b8caada0e7237e33ef4e0340577627ef4 (diff) |
Merge branch 'improvements' of https://github.com/valmat/PHP-CPP
-rw-r--r-- | include/array.h | 4 | ||||
-rw-r--r-- | include/byref.h | 2 | ||||
-rw-r--r-- | include/byval.h | 2 | ||||
-rw-r--r-- | include/class.h | 2 | ||||
-rw-r--r-- | include/classbase.h | 2 | ||||
-rw-r--r-- | include/global.h | 4 | ||||
-rw-r--r-- | include/hashmember.h | 2 | ||||
-rw-r--r-- | include/hiddenpointer.h | 2 | ||||
-rw-r--r-- | include/object.h | 26 | ||||
-rw-r--r-- | include/value.h | 67 | ||||
-rw-r--r-- | zend/value.cpp | 384 |
11 files changed, 59 insertions, 438 deletions
diff --git a/include/array.h b/include/array.h index 4d6b6b1..d238862 100644 --- a/include/array.h +++ b/include/array.h @@ -38,7 +38,7 @@ public: * Move constructor from a value object * @param value */ - Array(Value &&value) : Value(std::move(value)) + Array(Value &&value) noexcept : Value(std::move(value)) { // type must be valid if (value.type() != Type::Array) throw FatalError("Moving a non-array to an array variable"); @@ -107,7 +107,7 @@ public: * @param value * @return Array */ - Array &operator=(Value &&value) + Array &operator=(Value &&value) noexcept { // skip self assignment if (this == &value) return *this; diff --git a/include/byref.h b/include/byref.h index 317c5c6..ff60981 100644 --- a/include/byref.h +++ b/include/byref.h @@ -45,7 +45,7 @@ public: * Move constructor * @param argument */ - ByRef(ByRef &&argument) : Argument(argument) {} + ByRef(ByRef &&argument) noexcept : Argument(argument) {} /** * Destructor diff --git a/include/byval.h b/include/byval.h index 66f9b8f..3606df7 100644 --- a/include/byval.h +++ b/include/byval.h @@ -45,7 +45,7 @@ public: * Move constructor * @param argument */ - ByVal(ByVal &&argument) : Argument(argument) {} + ByVal(ByVal &&argument) noexcept : Argument(argument) {} /** * Destructor diff --git a/include/class.h b/include/class.h index cffc7bd..9257213 100644 --- a/include/class.h +++ b/include/class.h @@ -48,7 +48,7 @@ public: * Move constructor * @param that */ - Class(Class<T> &&that) : ClassBase(std::move(that)) {} + Class(Class<T> &&that) noexcept : ClassBase(std::move(that)) {} /** * Destructor diff --git a/include/classbase.h b/include/classbase.h index 9f0bac3..1129298 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -85,7 +85,7 @@ public: * Move constructor * @param that */ - ClassBase(ClassBase &&that) : _impl(std::move(that._impl)) {} + ClassBase(ClassBase &&that) noexcept : _impl(std::move(that._impl)) {} /** * Destructor diff --git a/include/global.h b/include/global.h index ae54212..4593e5d 100644 --- a/include/global.h +++ b/include/global.h @@ -34,7 +34,7 @@ public: * Move constructor * @param global */ - Global(Global &&global) : Value(std::move(global)), _name(std::move(global._name)), _exists(global._exists) {} + Global(Global &&global) noexcept : Value(std::move(global)), _name(std::move(global._name)), _exists(global._exists) {} /** * Destructor @@ -70,7 +70,7 @@ public: * @return Global */ /* - Global &operator=(Global &&global) + Global &operator=(Global &&global) noexcept { // skip self assignment if (&global == this) return *this; diff --git a/include/hashmember.h b/include/hashmember.h index 6853228..b5b6c17 100644 --- a/include/hashmember.h +++ b/include/hashmember.h @@ -579,7 +579,7 @@ protected: * Move constructor * @param value Other element */ -// HashMember(HashMember<Type> &&member) : +// HashMember(HashMember<Type> &&member) noexcept : // _parent(std::move(member._parent)), _index(std::move(member._index)) {} private: diff --git a/include/hiddenpointer.h b/include/hiddenpointer.h index dc981c0..5465ebb 100644 --- a/include/hiddenpointer.h +++ b/include/hiddenpointer.h @@ -84,7 +84,7 @@ public: * Move constructor * @param that */ - HiddenPointer(HiddenPointer<Type> &&that) : _allocated(that._allocated), _buffer(that._buffer) + HiddenPointer(HiddenPointer<Type> &&that) noexcept : _allocated(that._allocated), _buffer(that._buffer) { // the other object is no longer allocated that._allocated = false; diff --git a/include/object.h b/include/object.h index 9387408..2e92f6a 100644 --- a/include/object.h +++ b/include/object.h @@ -71,28 +71,10 @@ public: * number of parameters that are passed to the constructor * * @param name Name of the class to instantiate - * @param arg0 Optional argument 1 - * @param arg1 Optional argument 2 - * @param arg2 Optional argument 3 - * @param arg3 Optional argument 4 - * @param arg4 Optional argument 5 - * @param arg5 Optional argument 6 - * @param arg6 Optional argument 7 - * @param arg7 Optional argument 8 - * @param arg8 Optional argument 9 - * @param arg9 Optional argument 10 + * @param args Optional arguments */ - Object(const char *name) : Value() { if (instantiate(name)) call("__construct"); } - Object(const char *name, Value p0) : Value() { if (instantiate(name)) call("__construct", p0); } - Object(const char *name, Value p0, Value p1) : Value() { if (instantiate(name)) call("__construct", p0, p1); } - Object(const char *name, Value p0, Value p1, Value p2) : Value() { if (instantiate(name)) call("__construct", p0, p1, p2); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3) : Value() { if (instantiate(name)) call("__construct", p0, p1, p2, p3); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4) : Value() { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) : Value() { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) : Value() { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5, p6); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) : Value() { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5, p6, p7); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) : Value() { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5, p6, p7, p8); } - Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) : Value() { if (instantiate(name)) call("__construct", p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } + template <typename ...Args> + Object(const char *name, Args&&... args) : Value() { if (instantiate(name)) call("__construct", std::forward<Value>(args)...); } /** * Destructor @@ -137,7 +119,7 @@ public: * @param value * @return ForcedValue */ - Object &operator=(Value &&value) + Object &operator=(Value &&value) noexcept { // skip self assignment if (this == &value) return *this; diff --git a/include/value.h b/include/value.h index 7bdd853..f0b7345 100644 --- a/include/value.h +++ b/include/value.h @@ -129,7 +129,7 @@ public: * Move constructor * @param value */ - Value(Value &&that); + Value(Value &&that) noexcept; /** * Destructor @@ -141,7 +141,7 @@ public: * @param value * @return Value */ - Value &operator=(Value &&value); + Value &operator=(Value &&value) noexcept; /** * Assignment operator for various types @@ -944,24 +944,32 @@ public: return get(key.stringValue()); } - /** * Call the function in PHP - * We have ten variants of this function, depending on the number of parameters * This call operator is only useful when the variable represents a callable * @return Value */ Value operator()() const; - Value operator()(Value p0) const; - Value operator()(Value p0, Value p1) const; - Value operator()(Value p0, Value p1, Value p2) const; - Value operator()(Value p0, Value p1, Value p2, Value p3) const; - Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4) const; - Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) const; - Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) const; - Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) const; - Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) const; - Value operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) const; + + /** + * Call the function - if the variable holds a callable thing + * @param args Optional arguments + * @return Value + */ + template <typename ...Args> + Value operator()(Args&&... args) const + { + // store arguments + Value vargs[] = { static_cast<Value>(args)... }; + //Value vargs[] = { std::forward<Value>(args)... }; + + // array of parameters + _zval_struct **params[sizeof...(Args)]; + for(unsigned i=0; i < sizeof...(Args); i++) {params[i] = &vargs[i]._val;} + + // call the function + return exec(sizeof...(Args), params); + } /** * Call a method @@ -971,16 +979,27 @@ public: * @return Value */ Value call(const char *name); - Value call(const char *name, Value p0); - Value call(const char *name, Value p0, Value p1); - Value call(const char *name, Value p0, Value p1, Value p2); - Value call(const char *name, Value p0, Value p1, Value p2, Value p3); - Value call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4); - Value call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5); - Value call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6); - Value call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7); - Value call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8); - Value call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9); + + /** + * + * Call the method - if the variable holds an object with the given method + * @param name name of the method to call + * @param p0 The first parameter + * @return Value + */ + template <typename ...Args> + Value call(const char *name, Args&&... args) + { + // store arguments + Value vargs[] = { static_cast<Value>(args)... }; + + // array of parameters + _zval_struct **params[sizeof...(Args)]; + for(unsigned i=0; i < sizeof...(Args); i++) {params[i] = &vargs[i]._val;} + + // call the function + return exec(name, sizeof...(Args), params); + } /** * Retrieve the original implementation diff --git a/zend/value.cpp b/zend/value.cpp index 64bdb0e..228b810 100644 --- a/zend/value.cpp +++ b/zend/value.cpp @@ -286,7 +286,7 @@ Value::Value(const Value &that) * Move constructor * @param value */ -Value::Value(Value &&that) : _val(that._val) +Value::Value(Value &&that) noexcept: _val(that._val) { // clear the other object that._val = nullptr; @@ -397,7 +397,7 @@ int Value::refcount() const * @param value * @return Value */ -Value &Value::operator=(Value &&value) +Value &Value::operator=(Value &&value) noexcept { // skip self assignment if (this == &value) return *this; @@ -854,191 +854,6 @@ Value Value::operator()() const } /** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @return Value - */ -Value Value::operator()(Value p0) const -{ - // array of parameters - zval **params[1] = { &p0._val }; - - // call the function - return exec(1, params); -} - -/** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @param p1 The second parameter - * @return Value - */ -Value Value::operator()(Value p0, Value p1) const -{ - // array of parameters - zval **params[2] = { &p0._val, &p1._val }; - - // call the function - return exec(2, params); -} - -/** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @return Value - */ -Value Value::operator()(Value p0, Value p1, Value p2) const -{ - // array of parameters - zval **params[3] = { &p0._val, &p1._val, &p2._val }; - - // call the function - return exec(3, params); -} - -/** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @return Value - */ -Value Value::operator()(Value p0, Value p1, Value p2, Value p3) const -{ - // array of parameters - zval **params[4] = { &p0._val, &p1._val, &p2._val, &p3._val }; - - // call the function - return exec(4, params); -} - -/** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @return Value - */ -Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4) const -{ - // array of parameters - zval **params[5] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val }; - - // call the function - return exec(5, params); -} - -/** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @return Value - */ -Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) const -{ - // array of parameters - zval **params[6] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val }; - - // call the function - return exec(6, params); -} - -/** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @param p6 The seventh parameter - * @return Value - */ -Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) const -{ - // array of parameters - zval **params[7] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val }; - - // call the function - return exec(7, params); -} - -/** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @param p6 The seventh parameter - * @param p7 The eighth parameter - * @return Value - */ -Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) const -{ - // array of parameters - zval **params[8] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val }; - - // call the function - return exec(8, params); -} - -/** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @param p6 The seventh parameter - * @param p7 The eighth parameter - * @param p8 The ninth parameter - * @return Value - */ -Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) const -{ - // array of parameters - zval **params[9] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val }; - - // call the function - return exec(9, params); -} - -/** - * Call the function - if the variable holds a callable thing - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @param p6 The seventh parameter - * @param p7 The eighth parameter - * @param p8 The ninth parameter - * @param p9 The tenth parameter - * @return Value - */ -Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) const -{ - // array of parameters - zval **params[10] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val, &p9._val }; - - // call the function - return exec(10, params); -} - -/** * Call the method - if the variable holds an object with the given method * @param name name of the method to call * @return Value @@ -1050,201 +865,6 @@ Value Value::call(const char *name) } /** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @return Value - */ -Value Value::call(const char *name, Value p0) -{ - // array of parameters - zval **params[] = { &p0._val }; - - // call with zero parameters - return exec(name, 1, params); -} - -/** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @param p1 The second parameter - * @return Value - */ -Value Value::call(const char *name, Value p0, Value p1) -{ - // array of parameters - zval **params[] = { &p0._val, &p1._val }; - - // call with zero parameters - return exec(name, 2, params); -} - -/** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @return Value - */ -Value Value::call(const char *name, Value p0, Value p1, Value p2) -{ - // array of parameters - zval **params[] = { &p0._val, &p1._val, &p2._val }; - - // call with zero parameters - return exec(name, 3, params); -} - -/** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @return Value - */ -Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3) -{ - // array of parameters - zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val }; - - // call with zero parameters - return exec(name, 4, params); -} - -/** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @return Value - */ -Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4) -{ - // array of parameters - zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val }; - - // call with zero parameters - return exec(name, 5, params); -} - -/** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @return Value - */ -Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) -{ - // array of parameters - zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val }; - - // call with zero parameters - return exec(name, 6, params); -} - -/** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @param p6 The seventh parameter - * @return Value - */ -Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) -{ - // array of parameters - zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val }; - - // call with zero parameters - return exec(name, 7, params); -} - -/** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @param p6 The seventh parameter - * @param p7 The eighth parameter - * @return Value - */ -Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) -{ - // array of parameters - zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val }; - - // call with zero parameters - return exec(name, 8, params); -} - -/** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @param p6 The seventh parameter - * @param p7 The eighth parameter - * @param p8 The ninth parameter - * @return Value - */ -Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) -{ - // array of parameters - zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val }; - - // call with zero parameters - return exec(name, 9, params); -} - -/** - * Call the method - if the variable holds an object with the given method - * @param name name of the method to call - * @param p0 The first parameter - * @param p1 The second parameter - * @param p2 The third parameter - * @param p3 The fourth parameter - * @param p4 The fifth parameter - * @param p5 The sixth parameter - * @param p6 The seventh parameter - * @param p7 The eighth parameter - * @param p8 The ninth parameter - * @param p9 The tenth parameter - * @return Value - */ -Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) -{ - // array of parameters - zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val, &p9._val }; - - // call with zero parameters - return exec(name, 10, params); -} - -/** * Helper function that runs the actual call * @param object The object to call it on * @param method The function or method to call |