diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-14 12:42:35 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-14 12:42:35 +0100 |
commit | 1f1a0fa9349d37e623ae763b48c7ea21681cd45b (patch) | |
tree | d5bc49690b2bb1f85f3560c28845dcc02566d330 /include/classbase.h | |
parent | 91e1175a467cb9e2f90e7421a1398430d075f776 (diff) |
implementation of properties using callback methods
Diffstat (limited to 'include/classbase.h')
-rw-r--r-- | include/classbase.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/classbase.h b/include/classbase.h index 1979f94..3ae8568 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -52,10 +52,17 @@ typedef Value (Base::*method_callback_6)() const; typedef Value (Base::*method_callback_7)(Parameters &) const; /** + * Signatures for getters and setters + */ +typedef Value (Base::*getter_callback)(); +typedef void (Base::*setter_callback)(const Php::Value &value); + +/** * Forward declarations */ class Method; class Member; +class Property; /** * Class definition @@ -87,6 +94,7 @@ public: _type(that._type), _methods(that._methods), _members(that._members), + _properties(that._properties), _entry(nullptr) {} /** @@ -98,6 +106,7 @@ public: _type(that._type), _methods(std::move(that._methods)), _members(std::move(that._members)), + _properties(std::move(that._properties)), _entry(that._entry) { // other entry are invalid now (not that it is used..., class objects are @@ -269,6 +278,14 @@ protected: void property(const char *name, const char *value, int flags = Php::Public); void property(const char *name, double value, int flags = Php::Public); + /** + * Set property with callbacks + * @param name Name of the property + * @param getter Getter method + * @param setter Setter method + */ + void property(const char *name, const getter_callback &getter, const setter_callback &setter); + private: /** * Retrieve an array of zend_function_entry objects that hold the @@ -281,6 +298,14 @@ private: const struct _zend_function_entry *entries(); /** + * Helper method to turn a property into a zval + * @param value + * @param type + * @return Value + */ + static struct _zval_struct *toZval(Value &&value, int type); + + /** * Static member functions to create or clone objects based on this class * @param entry Pointer to class information * @param val The object to be cloned @@ -504,6 +529,12 @@ private: std::list<std::shared_ptr<Member>> _members; /** + * Map of dynamically accessible properties + * @var std::map + */ + std::map<std::string,std::shared_ptr<Property>> _properties; + + /** * Base object has access to the members * This is needed by the Base::store() method */ |