diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-02-28 15:17:53 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-02-28 15:17:53 +0100 |
commit | 7cf89f18d766368dd4a14d35e4e144107ad7be36 (patch) | |
tree | 0bd4e449cbfddc928c25aaa1abac8b44c028c8e2 /include | |
parent | 6072701319a3bf085bbc354c3e3dae9b7d021be0 (diff) |
implemented properties
Diffstat (limited to 'include')
-rw-r--r-- | include/class.h | 35 | ||||
-rw-r--r-- | include/classbase.h | 33 | ||||
-rw-r--r-- | include/const.h | 58 | ||||
-rw-r--r-- | include/member.h | 184 | ||||
-rw-r--r-- | include/membermodifier.h | 49 | ||||
-rw-r--r-- | include/members.h | 60 | ||||
-rw-r--r-- | include/modifiers.h | 29 | ||||
-rw-r--r-- | include/private.h | 55 | ||||
-rw-r--r-- | include/protected.h | 57 | ||||
-rw-r--r-- | include/public.h | 58 |
10 files changed, 74 insertions, 544 deletions
diff --git a/include/class.h b/include/class.h index fe9ea2e..ad0e1a7 100644 --- a/include/class.h +++ b/include/class.h @@ -50,25 +50,6 @@ public: virtual ~Class() {} /** - * Add a property to the class - * - * Every instance of this class will have this property. The property - * can be Php::Public, Php::Protected or Php::Private (altough setting - * private properties is odd as the implementation of the class is in CPP, - * so why use private properties while the whole implementation is already - * hidden) - * - * @param name Name of the property - * @param property Actual property value - * @param flags Optional flags - */ -// void add(const char *name, const Property &property, int flags = Php::Public) -// { -// // @todo something with the flags -// _properties[name] = property; -// } - - /** * Add a method to the class * * The method will be accessible as one of the class methods in your PHP @@ -91,6 +72,22 @@ public: void add(const char *name, void(T::*method)(Parameters ¶ms), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_1>(method), 0, args); } void add(const char *name, bool(T::*method)(), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_2>(method), 0, args); } void add(const char *name, bool(T::*method)(Parameters ¶ms), const Arguments &args = {}) { ClassBase::add(name, static_cast<method_callback_3>(method), 0, args); } + + /** + * Add a property to the class + * + * Every instance of this class will have this property. The property + * can be Php::Public, Php::Protected or Php::Private (altough setting + * private properties is odd as the implementation of the class is in CPP, + * so why use private properties while the whole implementation is already + * hidden) + * + * @param name Name of the property + * @param value Actual property value + * @param flags Optional flags + */ + template <typename TYPE> + void add(const char *name, const Type &value, int flags = Php::Public) { ClassBase::add(name, value, flags); } protected: /** diff --git a/include/classbase.h b/include/classbase.h index ad382fb..8b6d3dd 100644 --- a/include/classbase.h +++ b/include/classbase.h @@ -31,6 +31,7 @@ typedef Value (Base::*method_callback_3)(Parameters &); * Forward declarations */ class Method; +class Member; /** * Class definition @@ -115,6 +116,30 @@ protected: void add(const char *name, method_callback_2, int flags=0, const Arguments &args = {}); void add(const char *name, method_callback_3, int flags=0, const Arguments &args = {}); + /** + * Add a property to the class + * + * Every instance of this class will have this property. The property + * can be Php::Public, Php::Protected or Php::Private (altough setting + * private properties is odd as the implementation of the class is in CPP, + * so why use private properties while the whole implementation is already + * hidden) + * + * @param name Name of the property + * @param value Actual property value + * @param flags Optional flags + */ + void add(const char *name, std::nullptr_t value, int flags = Php::Public); + void add(const char *name, int16_t value, int flags = Php::Public); + void add(const char *name, int32_t value, int flags = Php::Public); + void add(const char *name, int64_t value, int flags = Php::Public); + void add(const char *name, bool value, int flags = Php::Public); + void add(const char *name, char value, int flags = Php::Public); + void add(const char *name, const std::string &value, int flags = Php::Public); + void add(const char *name, const char *value, int flags = Php::Public); + void add(const char *name, double value, int flags = Php::Public); + + private: /** * Retrieve an array of zend_function_entry objects that hold the @@ -151,16 +176,16 @@ private: struct _zend_function_entry *_entries = nullptr; /** - * All class methods, this is a map indexed by method name + * All class methods * @var set */ std::set<std::shared_ptr<Method>> _methods; /** - * All class properties, also a map indexed by name - * @var Properties + * All class members (class properties) + * @var set */ -// std::map<std::string,Property> _properties; + std::set<std::shared_ptr<Member>> _members; }; /** diff --git a/include/const.h b/include/const.h deleted file mode 100644 index 55c1792..0000000 --- a/include/const.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Const.h - * - * Class for adding constant properties to a class - * - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - * @copyright 2013 Copernica BV - * - * - * @todo implement const in a different manner - */ - -/** - * Namespace - */ -namespace Php { - -/** - * Class definition - */ -//class Const : public Member -//{ -//public: -// /** -// * Constructor -// * @param name Name of the property -// * @param value Default value of the property -// */ -// Const(const char *name) : Member(name, MemberModifier::constMember) {} -// Const(const char *name, std::nullptr_t value) : Member(name, MemberModifier::constMember, value) {} -// Const(const char *name, int value) : Member(name, MemberModifier::constMember, value) {} -// Const(const char *name, long value) : Member(name, MemberModifier::constMember, value) {} -// Const(const char *name, bool value) : Member(name, MemberModifier::constMember, value) {} -// Const(const char *name, char value) : Member(name, MemberModifier::constMember, value) {} -// Const(const char *name, const std::string &value) : Member(name, MemberModifier::constMember, value) {} -// Const(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::constMember, value, size) {} -// Const(const char *name, double value) : Member(name, MemberModifier::constMember, value) {} -// -// /** -// * Constructor -// * @param name Name of the property -// * @param method Method to add -// * @param arguments Optional argument information -// */ -// Const(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, MemberModifier::constMember, method, arguments) {} -// -// /** -// * Destructor -// */ -// virtual ~Const() {} -// -//}; -// -/** - * End of namespace - */ -} - diff --git a/include/member.h b/include/member.h deleted file mode 100644 index 9104c56..0000000 --- a/include/member.h +++ /dev/null @@ -1,184 +0,0 @@ -/** - * Member.h - * - * Base class for elements of a class - * - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - * @copyright 2013 Copernica BV - * - * @todo remove this file completely - */ - -/** - * Forward declarations - */ -struct _zend_class_entry; - -/** - * Namespace - */ -namespace Php { - -/** - * Forward declarations - */ -class MemberInfo; - -///** -// * Class definition -// */ -//class Member -//{ -//public: -// /** -// * Constructor -// * @param name Name of the member -// * @param flags Flag access to a class member (public, protected etc) -// */ -// Member(const char *name, MemberModifier flags); -// -// /** -// * Constructor -// * @param name Name of the member -// * @param flags Flag access to a class member (public, protected etc) -// * @param value The value to add -// */ -// Member(const char *name, MemberModifier flags, std::nullptr_t value); -// -// /** -// * Constructor -// * @param name Name of the member -// * @param flags Flag access to a class member (public, protected etc) -// * @param value The value to add -// */ -// Member(const char *name, MemberModifier flags, int value); -// -// /** -// * Constructor -// * @param name Name of the member -// * @param flags Flag access to a class member (public, protected etc) -// * @param value The value to add -// */ -// Member(const char *name, MemberModifier flags, long value); -// -// /** -// * Constructor -// * @param name Name of the member -// * @param flags Flag access to a class member (public, protected etc) -// * @param value The value to add -// */ -// Member(const char *name, MemberModifier flags, bool value); -// -// /** -// * Constructor -// * @param name Name of the member -// * @param flags Flag access to a class member (public, protected etc) -// * @param value The value to add -// */ -// Member(const char *name, MemberModifier flags, char value); -// -// /** -// * Constructor -// * @param name Name of the member -// * @param flags Flag access to a class member (public, protected etc) -// * @param value The value to add -// */ -// Member(const char *name, MemberModifier flags, const std::string &value); -// -// /** -// * Constructor -// * @param name Name of the member -// * @param flags Flag access to a class member (public, protected etc) -// * @param value The value to add -// * @param size String length -// */ -// Member(const char *name, MemberModifier flags, const char *value, int size = -1); -// -// /** -// * Constructor -// * @param name Name of the member -// * @param flags Flag access to a class member (public, protected etc) -// * @param value The value to add -// */ -// Member(const char *name, MemberModifier flags, double value); -// -// /** -// * Constructor -// * @param name Name of the method -// * @param flags Flag access to a class member (public, protected etc) -// * @param method The method to add -// */ -// Member(const char *name, MemberModifier flags, const _Method &method, const std::initializer_list<Argument> &arguments = {}); -// -// /** -// * Copy constructor -// * @param member The member to copy -// */ -// Member(const Member &member); -// -// /** -// * Move constructor -// * @param member The member to move -// */ -// Member(Member &&member); -// -// /** -// * Destructor -// */ -// virtual ~Member(); -// -// /** -// * Internal method to declare the property -// * @param zend_class_entry -// * @internal -// */ -// void declare(struct _zend_class_entry *entry); -// -// /** -// * Internal method to fill a function entry -// * @param zend_function_entry -// * @param classname -// * @internal -// */ -// void fill(struct _zend_function_entry *entry, const char *classname); -// -// /** -// * Is this a property member -// * @return bool -// */ -// bool isProperty(); -// -// /** -// * Is this a method member -// * @return bool -// */ -// bool isMethod(); -// -// -//private: -// /** -// * Name of the member -// * @var string -// */ -// std::string _name; -// -// /** -// * Flag access to a class member (public, protected etc) -// * @var MemberModifier -// */ -// MemberModifier _flags; -// -// /** -// * The implementation for the member -// * @var MemberInfo -// */ -// MemberInfo *_info; -// -// -//}; -// -/** - * End of namespace - */ -} - diff --git a/include/membermodifier.h b/include/membermodifier.h deleted file mode 100644 index 9c6cb0d..0000000 --- a/include/membermodifier.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * MemberModifier.h - * - * In this file an enumeration type is with the possible - * member modifiers - * - * @author Martijn Otto - * @copyright 2014 Copernica BV - */ - -/** - * Set up namespace - */ -namespace Php { - -/** - * Supported member modifiers - */ -typedef enum _MemberModifier { - /** - * Define whether a member has an implementation - * and whether the implementation can be overwritten - * in an extending class - * - * These properties are only useful for functions - */ - abstractMember = 0x02, - finalMember = 0x04, - - /** - * Define the access level for a member - */ - publicMember = 0x100, - protectedMember = 0x200, - privateMember = 0x400, - - /** - * Define a member that cannot be overwritten. - * Constant members are always public. - * - * This property is only useful for properties - */ - constMember = 0 -} MemberModifier; - -/** - * End namespace - */ -} diff --git a/include/members.h b/include/members.h deleted file mode 100644 index f286620..0000000 --- a/include/members.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Members.h - * - * Internal helper class that holds all members of a class - * - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - * @copyright 2013 Copernica BV - * - * - * @todo remove this file completely - */ - -/** - * Namespace - */ -namespace Php { - -///** -// * Class definition -// */ -//class Members : public std::vector<Member> -//{ -//public: -// /** -// * Constructor -// * @param arguments -// */ -// Members(const std::initializer_list<Member> &members) : std::vector<Member>(members), _methods(NULL) {} -// -// /** -// * Destructor -// */ -// virtual ~Members(); -// -// /** -// * Get access to the methods -// * @param classname -// * @return Methods -// */ -// struct _zend_function_entry *methods(const char *classname); -// -//private: -// /** -// * Number of methods -// * @return integer -// */ -// int methods(); -// -// /** -// * Array of method structures used internally in the Zend engine -// * @var zend_function_entry -// */ -// struct _zend_function_entry *_methods; -//}; - -/** - * End of namespace - */ -} - diff --git a/include/modifiers.h b/include/modifiers.h new file mode 100644 index 0000000..a838341 --- /dev/null +++ b/include/modifiers.h @@ -0,0 +1,29 @@ +/** + * Modifiers.h + * + * In this file an enumeration type is with the possible + * member modifiers + * + * @author Martijn Otto + * @copyright 2014 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * The modifiers are constants + */ +extern const int Abstract; +extern const int Final; +extern const int Public; +extern const int Protected; +extern const int Private; +extern const int Const; + +/** + * End namespace + */ +} diff --git a/include/private.h b/include/private.h deleted file mode 100644 index f21ba6b..0000000 --- a/include/private.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Private.h - * - * Class for adding private properties to a class - * - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - * @copyright 2013 Copernica BV - */ - -/** - * Namespace - */ -namespace Php { - -/** - * Class definition - */ -//class Private : public Member -//{ -//public: -// /** -// * Constructor -// * @param name Name of the property -// * @param value Default value of the property -// */ -// Private(const char *name) : Member(name, MemberModifier::privateMember) {} -// Private(const char *name, std::nullptr_t value) : Member(name, MemberModifier::privateMember, value) {} -// Private(const char *name, int value) : Member(name, MemberModifier::privateMember, value) {} -// Private(const char *name, long value) : Member(name, MemberModifier::privateMember, value) {} -// Private(const char *name, bool value) : Member(name, MemberModifier::privateMember, value) {} -// Private(const char *name, char value) : Member(name, MemberModifier::privateMember, value) {} -// Private(const char *name, const std::string &value) : Member(name, MemberModifier::privateMember, value) {} -// Private(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::privateMember, value, size) {} -// Private(const char *name, double value) : Member(name, MemberModifier::privateMember, value) {} -// -// /** -// * Constructor -// * @param name Name of the property -// * @param method Method to add -// * @param arguments Optional argument information -// */ -// Private(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, MemberModifier::privateMember, method, arguments) {} -// -// /** -// * Destructor -// */ -// virtual ~Private() {} -// -//}; -// -/** - * End of namespace - */ -} - diff --git a/include/protected.h b/include/protected.h deleted file mode 100644 index aeee064..0000000 --- a/include/protected.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Protected.h - * - * Class for adding protected properties to a class - * - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - * @copyright 2013 Copernica BV - * - * @todo remove this class completely - */ - -/** - * 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) : Member(name, MemberModifier::protectedMember) {} -// Protected(const char *name, std::nullptr_t value) : Member(name, MemberModifier::protectedMember, value) {} -// Protected(const char *name, int value) : Member(name, MemberModifier::protectedMember, value) {} -// Protected(const char *name, long value) : Member(name, MemberModifier::protectedMember, value) {} -// Protected(const char *name, bool value) : Member(name, MemberModifier::protectedMember, value) {} -// Protected(const char *name, char value) : Member(name, MemberModifier::protectedMember, value) {} -// Protected(const char *name, const std::string &value) : Member(name, MemberModifier::protectedMember, value) {} -// Protected(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::protectedMember, value, size) {} -// Protected(const char *name, double value) : Member(name, MemberModifier::protectedMember, value) {} -// -// /** -// * Constructor -// * @param name Name of the property -// * @param method Method to add -// * @param arguments Optional argument information -// */ -// Protected(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, MemberModifier::protectedMember, method, arguments) {} -// -// /** -// * Destructor -// */ -// virtual ~Protected() {} -// -//}; -// -/** - * End of namespace - */ -} - diff --git a/include/public.h b/include/public.h deleted file mode 100644 index a2f91f3..0000000 --- a/include/public.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Public.h - * - * Class for adding public properties to a class - * - * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> - * @copyright 2013 Copernica BV - * - * @todo remove this file completely - */ - -/** - * 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) : Member(name, MemberModifier::publicMember) {} -// Public(const char *name, std::nullptr_t value) : Member(name, MemberModifier::publicMember, value) {} -// Public(const char *name, int value) : Member(name, MemberModifier::publicMember, value) {} -// Public(const char *name, long value) : Member(name, MemberModifier::publicMember, value) {} -// Public(const char *name, bool value) : Member(name, MemberModifier::publicMember, value) {} -// Public(const char *name, char value) : Member(name, MemberModifier::publicMember, value) {} -// Public(const char *name, const std::string &value) : Member(name, MemberModifier::publicMember, value) {} -// Public(const char *name, const char *value, int size=-1) : Member(name, MemberModifier::publicMember, value, size) {} -// Public(const char *name, double value) : Member(name, MemberModifier::publicMember, value) {} -// -// /** -// * Constructor -// * @param name Name of the property -// * @param method Method to add -// * @param arguments Optional argument information -// */ -// Public(const char *name, const _Method &method, const std::initializer_list<Argument> &arguments = {}) : Member(name, MemberModifier::publicMember, method, arguments) {} -// -// /** -// * Destructor -// */ -// virtual ~Public() {} -// -// -//}; -// -/** - * End of namespace - */ -} - |