diff options
-rw-r--r-- | include/array.h | 7 | ||||
-rw-r--r-- | include/globals.h | 2 | ||||
-rw-r--r-- | include/hashmember.h | 30 | ||||
-rw-r--r-- | include/value.h | 19 | ||||
-rw-r--r-- | phpcpp.h | 1 | ||||
-rw-r--r-- | src/extension.cpp | 2 | ||||
-rw-r--r-- | src/includes.h | 1 | ||||
-rw-r--r-- | src/value.cpp | 62 |
8 files changed, 101 insertions, 23 deletions
diff --git a/include/array.h b/include/array.h index dcd5e5f..26fec24 100644 --- a/include/array.h +++ b/include/array.h @@ -12,7 +12,7 @@ * Set up namespace */ namespace Php { - + /** * Class definition */ @@ -124,11 +124,6 @@ public: }; /** - * Define for arrays and objects - */ -using Array = Array; - -/** * End of namespace */ } diff --git a/include/globals.h b/include/globals.h index 0278c88..b996131 100644 --- a/include/globals.h +++ b/include/globals.h @@ -68,7 +68,7 @@ public: }; /** - * We always have one instance + * We always have one instance of the GLOBALS instance * @var Globals */ extern Globals &GLOBALS; diff --git a/include/hashmember.h b/include/hashmember.h index 65ca23d..41c40d3 100644 --- a/include/hashmember.h +++ b/include/hashmember.h @@ -43,7 +43,7 @@ public: HashMember &operator=(const Value &value) { // set property in parent array - _base.set(_index, value); + _base->set(_index, value); // if there is a parent, it should sets its value too if (_parent) _parent->operator=(_base); @@ -58,7 +58,7 @@ public: */ Value value() const { - return _base.get(_index); + return _base->get(_index); } /** @@ -67,7 +67,7 @@ public: */ operator Value () const { - return _base.get(_index); + return _base->get(_index); } /** @@ -76,7 +76,7 @@ public: */ operator int16_t () const { - return _base.get(_index).numericValue(); + return _base->get(_index).numericValue(); } /** @@ -85,7 +85,7 @@ public: */ operator int32_t () const { - return _base.get(_index).numericValue(); + return _base->get(_index).numericValue(); } /** @@ -94,7 +94,7 @@ public: */ operator int64_t () const { - return _base.get(_index).numericValue(); + return _base->get(_index).numericValue(); } /** @@ -103,7 +103,7 @@ public: */ operator bool () const { - return _base.get(_index).boolValue(); + return _base->get(_index).boolValue(); } /** @@ -112,7 +112,7 @@ public: */ operator std::string () const { - return _base.get(_index).stringValue(); + return _base->get(_index).stringValue(); } /** @@ -121,7 +121,7 @@ public: */ operator const char * () const { - return _base.get(_index).rawValue(); + return _base->get(_index).rawValue(); } /** @@ -130,7 +130,7 @@ public: */ operator double () const { - return _base.get(_index).decimalValue(); + return _base->get(_index).decimalValue(); } /** @@ -141,7 +141,7 @@ public: */ HashMember operator[](int index) { - return _base.get(_index)[index].add(this); + return _base->get(_index)[index].add(this); } /** @@ -152,7 +152,7 @@ public: */ HashMember operator[](const std::string &key) { - return _base.get(_index)[key].add(this); + return _base->get(_index)[key].add(this); } /** @@ -163,7 +163,7 @@ public: */ HashMember operator[](const char *key) { - return _base.get(_index)[key].add(this); + return _base->get(_index)[key].add(this); } /** @@ -359,7 +359,7 @@ private: * @param base Base value * @param index Index in the array */ - HashMember(const Value *base, Type index) : _base(*base), _index(index) {} + HashMember(Value *base, Type index) : _base(base), _index(index) {} // @todo add move constructor @@ -390,7 +390,7 @@ private: * Base value * @var Value */ - Value _base; + Value *_base; /** * Parent member (in case of nested members) diff --git a/include/value.h b/include/value.h index f2850c9..9c48f1f 100644 --- a/include/value.h +++ b/include/value.h @@ -112,6 +112,12 @@ public: Value(struct _zval_struct *zval, bool ref = false); /** + * Wrap around a hash table + * @param ht Hashtable to wrap + */ + Value(struct _hashtable *ht); + + /** * Wrap around an object implemented by us * @param object Object to be wrapped */ @@ -846,6 +852,18 @@ protected: struct _zval_struct *detach(); /** + * Attach a different zval + * + * This will first detach the current zval, and link the Value object to + * a different zval. Versions exist to attach to a zval and to an entire + * hash table + * + * @param val + */ + void attach(struct _zval_struct *val); + void attach(struct _hashtable *hashtable); + + /** * Set a certain property without running any checks (you must already know * for sure that this is an array, and that the index is not yet in use) * @@ -874,6 +892,7 @@ protected: friend class Member; friend class ClassBase; friend class Iterator; + friend class Extension; }; /** @@ -36,6 +36,7 @@ #include <phpcpp/byval.h> #include <phpcpp/byref.h> #include <phpcpp/global.h> +#include <phpcpp/super.h> #include <phpcpp/hashmember.h> #include <phpcpp/parameters.h> #include <phpcpp/modifiers.h> diff --git a/src/extension.cpp b/src/extension.cpp index 3f29d9c..4c6a46f 100644 --- a/src/extension.cpp +++ b/src/extension.cpp @@ -117,7 +117,7 @@ int Extension::onStartup(int type, int module_number) // is the callback registered? if (extension->_onStartup) extension->_onStartup(); - + // done return BOOL2SUCCESS(true); } diff --git a/src/includes.h b/src/includes.h index 50d4144..b2cb353 100644 --- a/src/includes.h +++ b/src/includes.h @@ -55,6 +55,7 @@ #include "../include/byval.h" #include "../include/byref.h" #include "../include/global.h" +#include "../include/super.h" #include "../include/hashmember.h" #include "../include/parameters.h" #include "../include/modifiers.h" diff --git a/src/value.cpp b/src/value.cpp index a78c2d4..29b6dcd 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -170,6 +170,21 @@ Value::Value(struct _zval_struct *val, bool ref) } /** + * Wrap around a hash table + * @param ht Hashtable to wrap + */ +Value::Value(HashTable *ht) +{ + // construct a zval + MAKE_STD_ZVAL(_val); + Z_ARRVAL_P(_val) = ht; + Z_TYPE_P(_val) = IS_ARRAY; + + // add a reference + Z_ADDREF_P(_val); +} + +/** * Wrap around an object * @param object */ @@ -302,6 +317,9 @@ Value::~Value() */ zval *Value::detach() { + // leap out if already detached + if (!_val) return nullptr; + // copy return value zval *result = _val; @@ -316,6 +334,50 @@ zval *Value::detach() } /** + * Attach a different zval + * + * This will first detach the current zval, and link the Value object to + * a different zval. + * + * @param val + */ +void Value::attach(struct _zval_struct *val) +{ + // detach first + if (_val) detach(); + + // store the zval + _val = val; + + // add one more reference + Z_ADDREF_P(_val); +} + +/** + * Attach a different zval + * + * This will first detach the current zval, and link the Value object to + * a new zval + * + * @param hashtable + */ +void Value::attach(struct _hashtable *hashtable) +{ + // detach first + if (_val) detach(); + + // construct a new zval + MAKE_STD_ZVAL(_val); + + // store pointer to the hashtable, and mark the zval as an array + Z_ARRVAL_P(_val) = hashtable; + Z_TYPE_P(_val) = IS_ARRAY; + + // add a reference + Z_ADDREF_P(_val); +} + +/** * Retrieve the refcount * @return int */ |