From 777eb276f635c949ccdcf9613ad55d42190cb387 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 30 Sep 2013 13:49:23 -0700 Subject: Work in progress on adding public and protected properties to classes --- include/class.h | 36 ++++++++++++++++++++++++--- include/classinfo.h | 16 ++++++++++++ include/member.h | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/protected.h | 39 +++++++++++++++++++++++++++++ include/public.h | 40 +++++++++++++++++++++++++++++ include/value.h | 1 + 6 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 include/member.h create mode 100644 include/protected.h create mode 100644 include/public.h (limited to 'include') diff --git a/include/class.h b/include/class.h index 38398b9..d5d48b4 100644 --- a/include/class.h +++ b/include/class.h @@ -13,7 +13,12 @@ * @author Emiel Bruijntjes * @copyright 2013 Copernica BV */ - + +/** + * Forward declarations + */ +struct _zend_class_entry; + /** * Set up namespace */ @@ -31,16 +36,22 @@ public: */ Class() {} + /** + * Constructor with initializer list to define the properties + * @param members + */ + Class(const std::initializer_list &members) : _members(members) {} + /** * Move constructor * @param that */ - Class(Class &&that) {} + Class(Class &&that) : _members(std::move(that._members)) {} /** * Copy constructor */ - Class(const Class &that) {} + Class(const Class &that) : _members(that._members) {} /** * Destructor @@ -57,7 +68,26 @@ public: return new T(); } + /** + * Initialize the class + * This will declare all members + * @param entry + */ + void initialize(struct _zend_class_entry *entry) + { + // loop through the members + for (auto iter = _members.begin(); iter != _members.end(); iter++) + { + iter->declare(entry); + } + } + protected: + /** + * The initial arguments + * @var vector + */ + std::vector _members; }; diff --git a/include/classinfo.h b/include/classinfo.h index fb92ce4..cbf2c66 100644 --- a/include/classinfo.h +++ b/include/classinfo.h @@ -56,6 +56,12 @@ public: * @return Base */ virtual Base *construct() = 0; + + /** + * Initialize the class + * @param entry + */ + virtual void initialize(struct _zend_class_entry *entry) = 0; private: /** @@ -113,6 +119,16 @@ public: { return _type.construct(); } + + /** + * Initialize the class + * @param entry + */ + virtual void initialize(struct _zend_class_entry *entry) + { + // pass to the entry + _type.initialize(entry); + } private: /** diff --git a/include/member.h b/include/member.h new file mode 100644 index 0000000..4a9a754 --- /dev/null +++ b/include/member.h @@ -0,0 +1,72 @@ +/** + * Member.h + * + * Base class for elements of a class + * + * @author Emiel Bruijntjes + * @copyright 2013 Copernica BV + */ + +/** + * Forward declarations + */ +struct _zend_class_entry; + +/** + * Namespace + */ +namespace Php { + +/** + * Class definition + */ +class Member +{ +public: + /** + * Constructor + * @param name Name of the member + * @param pub Is this a public property (otherwise it is protected) + * @param value The value to add + */ + Member(const char *name, bool pub, const Value &value) : + _name(name), _public(pub), _value(value) {} + + /** + * Destructor + */ + virtual ~Member() {} + + /** + * Internal method to declare the property + * @var zend_class_entry + */ + void declare(struct _zend_class_entry *entry); + + +private: + /** + * Name of the member + * @var string + */ + std::string _name; + + /** + * Is this a public property + * @var bool + */ + bool _public; + + /** + * The default value + * @var Value + */ + Value _value; + +}; + +/** + * End of namespace + */ +} + diff --git a/include/protected.h b/include/protected.h new file mode 100644 index 0000000..e660f76 --- /dev/null +++ b/include/protected.h @@ -0,0 +1,39 @@ +/** + * Protected.h + * + * Class for adding public properties to a class + * + * @author Emiel Bruijntjes + * @copyright 2013 Copernica BV + */ + +/** + * Namespace + */ +namespace Php { + +/** + * Class definition + */ +class Protected : public Member +{ +public: + /** + * Constructor + * @param name Name of the property + * @param value Default value of the property + */ + Protected(const char *name, const Value &value) : Member(name, false, value) {} + + /** + * Destructor + */ + virtual ~Protected() {} + +}; + +/** + * End of namespace + */ +} + diff --git a/include/public.h b/include/public.h new file mode 100644 index 0000000..17a5d0c --- /dev/null +++ b/include/public.h @@ -0,0 +1,40 @@ +/** + * Public.h + * + * Class for adding public properties to a class + * + * @author Emiel Bruijntjes + * @copyright 2013 Copernica BV + */ + +/** + * Namespace + */ +namespace Php { + +/** + * Class definition + */ +class Public : public Member +{ +public: + /** + * Constructor + * @param name Name of the property + * @param value Default value of the property + */ + Public(const char *name, const Value &value) : Member(name, true, value) {} + + /** + * Destructor + */ + virtual ~Public() {} + + +}; + +/** + * End of namespace + */ +} + diff --git a/include/value.h b/include/value.h index 652b7ef..6c879e6 100644 --- a/include/value.h +++ b/include/value.h @@ -497,6 +497,7 @@ protected: * The environment can access the zval directly */ friend class Environment; + friend class Member; }; /** -- cgit v1.2.3