diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-30 13:49:23 -0700 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-30 13:49:23 -0700 |
commit | 777eb276f635c949ccdcf9613ad55d42190cb387 (patch) | |
tree | f5451ae464a37414412d122ff6a283f713638dfa /include | |
parent | ecfca6b1197658afb85fffd6f6ac9e92311a4b07 (diff) |
Work in progress on adding public and protected properties to classes
Diffstat (limited to 'include')
-rw-r--r-- | include/class.h | 36 | ||||
-rw-r--r-- | include/classinfo.h | 16 | ||||
-rw-r--r-- | include/member.h | 72 | ||||
-rw-r--r-- | include/protected.h | 39 | ||||
-rw-r--r-- | include/public.h | 40 | ||||
-rw-r--r-- | include/value.h | 1 |
6 files changed, 201 insertions, 3 deletions
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 <emiel.bruijntjes@copernica.com> * @copyright 2013 Copernica BV */ - + +/** + * Forward declarations + */ +struct _zend_class_entry; + /** * Set up namespace */ @@ -32,15 +37,21 @@ public: Class() {} /** + * Constructor with initializer list to define the properties + * @param members + */ + Class(const std::initializer_list<Member> &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<Member> _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 <emiel.bruijntjes@copernica.com> + * @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 <emiel.bruijntjes@copernica.com> + * @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 <emiel.bruijntjes@copernica.com> + * @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; }; /** |