diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-02-28 10:25:01 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-02-28 10:25:01 +0100 |
commit | 71055ebdea1e8eec30747a04f36e0c10e750bff5 (patch) | |
tree | 18ed63d5fe64a936c284a38d4f72921a4ddc97df /include/extension.h | |
parent | 85349bbb642a83012a7d0dbccde8b7c1eea1b914 (diff) |
a lot of refactoring, to make it much easier to define classes in an extension
Diffstat (limited to 'include/extension.h')
-rw-r--r-- | include/extension.h | 62 |
1 files changed, 23 insertions, 39 deletions
diff --git a/include/extension.h b/include/extension.h index 1082bcb..4a89cf9 100644 --- a/include/extension.h +++ b/include/extension.h @@ -29,9 +29,20 @@ struct _zend_module_entry; namespace Php { /** + * A couple of predefined native callback functions that can be registered. + * These are functions that optional accept a Request and/or Parameters object, + * and that either return void or a Value object. + */ +typedef void (*native_callback_0)(); +typedef void (*native_callback_1)(Parameters &); +typedef Value (*native_callback_2)(); +typedef Value (*native_callback_3)(Parameters &); + +/** * Forward declaration */ class Extension; +class Function; /** * Optional callback types for starting and stopping the request @@ -40,16 +51,6 @@ class Extension; typedef bool (*request_callback)(Extension *extension); /** - * A couple of predefined native callback functions that can be registered. - * These are functions that optional accept a Request and/or Parameters object, - * and that either return void or a Value object. - */ -typedef void (*native_callback_0)(); -typedef void (*native_callback_1)(Parameters &); -typedef Value (*native_callback_2)(); -typedef Value (*native_callback_3)(Parameters &); - -/** * Class definition */ class Extension @@ -142,32 +143,15 @@ public: } /** - * Add a function to the extension - * - * It is only possible to create functions during the initialization of - * the library, before the Extension::module() method is called. - * - * Note that the function must have been allocated on the HEAP (using - * "new") and that the object will be destructed (using "delete") - * by the extension object (you thus do not have to destruct it - * yourself!) - * - * @param function The function to add - * @return Function The added function - */ - Function *add(Function *function); - - /** * Add a native function directly to the extension * @param name Name of the function * @param function The function to add * @param arguments Optional argument specification - * @return Function The added function */ - Function *add(const char *name, native_callback_0 function, const std::initializer_list<Argument> &arguments = {}); - Function *add(const char *name, native_callback_1 function, const std::initializer_list<Argument> &arguments = {}); - Function *add(const char *name, native_callback_2 function, const std::initializer_list<Argument> &arguments = {}); - Function *add(const char *name, native_callback_3 function, const std::initializer_list<Argument> &arguments = {}); + void add(const char *name, native_callback_0 function, const Arguments &arguments = {}); + void add(const char *name, native_callback_1 function, const Arguments &arguments = {}); + void add(const char *name, native_callback_2 function, const Arguments &arguments = {}); + void add(const char *name, native_callback_3 function, const Arguments &arguments = {}); /** * Add a native class to the extension @@ -175,13 +159,13 @@ public: * @param type The class implementation */ template<typename T> - void add(const char *name, const Class<T> &type) + void add(const Class<T> &type) { - // construct info - _ClassInfo *info = new ClassInfo<T>(name, type); + // make a copy of the object + auto *info = new Class<T>(type); - // add class - _classes.insert(std::unique_ptr<_ClassInfo>(info)); + // and copy it to the list of classes + _classes.insert(std::unique_ptr<ClassBase>(info)); } /** @@ -197,16 +181,16 @@ public: private: /** - * Set of function objects defined in the library + * Functions defined in the library * @var set */ std::set<std::unique_ptr<Function>> _functions; /** - * Set of classes defined in the library + * Classes defined in the library, indexed by their name * @var set */ - std::set<std::unique_ptr<_ClassInfo>> _classes; + std::set<std::unique_ptr<ClassBase>> _classes; /** * The information that is passed to the Zend engine |