From b2042dbd58c043ab49e9b0dbb51bf8516fe8cea8 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 14 Oct 2013 07:42:37 -0700 Subject: Initial attempt to register native C++ class methods directly to PHP --- src/methodmember.h | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/methodmember.h (limited to 'src/methodmember.h') diff --git a/src/methodmember.h b/src/methodmember.h new file mode 100644 index 0000000..16f0dd0 --- /dev/null +++ b/src/methodmember.h @@ -0,0 +1,85 @@ +/** + * MethodMember.h + * + * Implementation for a method in a class + * + * @author Emiel Bruijntjes + * @copyright 2013 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Class definition + */ +class MethodMember : public MemberInfo, public Function +{ +public: + /** + * Constructor + * @param name + * @param method + * @param arguments + */ + MethodMember(const char *name, method_callback_0 method, const std::initializer_list &arguments = {}) : Function(name, arguments), _type(0) { _method.m0 = method; } + MethodMember(const char *name, method_callback_1 method, const std::initializer_list &arguments = {}) : Function(name, arguments), _type(1) { _method.m1 = method; } + MethodMember(const char *name, method_callback_2 method, const std::initializer_list &arguments = {}) : Function(name, arguments), _type(2) { _method.m2 = method; } + MethodMember(const char *name, method_callback_3 method, const std::initializer_list &arguments = {}) : Function(name, arguments), _type(3) { _method.m3 = method; } + MethodMember(const char *name, method_callback_4 method, const std::initializer_list &arguments = {}) : Function(name, arguments), _type(4) { _method.m4 = method; } + MethodMember(const char *name, method_callback_5 method, const std::initializer_list &arguments = {}) : Function(name, arguments), _type(5) { _method.m5 = method; } + MethodMember(const char *name, method_callback_6 method, const std::initializer_list &arguments = {}) : Function(name, arguments), _type(6) { _method.m6 = method; } + MethodMember(const char *name, method_callback_7 method, const std::initializer_list &arguments = {}) : Function(name, arguments), _type(7) { _method.m7 = method; } + + /** + * Destructor + */ + virtual ~MethodMember() {} + + /** + * Is this a method member + * @return bool + */ + virtual bool isMethod() { return true; } + + /** + * Fill a function entry object + * @param entry Function entry + * @param classname Name of the class + */ + virtual void fill(struct _zend_function_entry *entry, const char *classname) + { + // call function object + Function::fill(entry, classname); + } + +private: + /** + * Union of supported callbacks + * One of the callbacks will be set + */ + union { + method_callback_0 m0; + method_callback_1 m1; + method_callback_2 m2; + method_callback_3 m3; + method_callback_4 m4; + method_callback_5 m5; + method_callback_6 m6; + method_callback_7 m7; + } _method; + + /** + * The method type that is set + * @var integer + */ + int _type; +}; + +/** + * End of namespace + */ +} + -- cgit v1.2.3