diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-25 05:23:34 -0700 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2013-09-25 05:23:34 -0700 |
commit | 49ac629257835426c311fb7b92b23a9138a9d77b (patch) | |
tree | d7f8d6d843206ecdf29b3877a5e7faf7815f3f24 /include/extension.h | |
parent | 9e1ecc534bace7d00a265a49018c0148a56361ae (diff) |
Work in progress on implementing classes
Diffstat (limited to 'include/extension.h')
-rw-r--r-- | include/extension.h | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/include/extension.h b/include/extension.h index ceeed78..1984aa9 100644 --- a/include/extension.h +++ b/include/extension.h @@ -80,15 +80,15 @@ public: * and after the compatibility has been checked, but before the requests * are handled. You can override this method to add your own initialization. * + * The default behavior of this function is to enable all classes that are + * defined in this extension, so that they are also available in PHP. + * * The method should return true on success, and false on failure (in which * case the extension will not be used) * * @return bool */ - virtual bool initialize() - { - return true; - } + virtual bool initialize(); /** * Finalize the extension @@ -200,6 +200,21 @@ public: Function *add(const char *name, native_callback_7 function, const std::initializer_list<Argument> &arguments = {}); /** + * Add a native class to the extension + * @param name Name of the class + * @param type The class implementation + */ + template<typename T> + void add(const char *name, const Class<T> &type) + { + // construct info + ClassInfo<T> *info = new ClassInfo<T>(name, type); + + // add class + _classes.insert(std::unique_ptr<_ClassInfo>(info)); + } + + /** * Retrieve the module entry * * This is the memory address that should be exported by the get_module() @@ -213,11 +228,17 @@ public: private: /** * Set of function objects defined in the library - * @var map + * @var set */ std::set<std::unique_ptr<Function>> _functions; /** + * Set of classes defined in the library + * @var set + */ + std::set<std::unique_ptr<_ClassInfo>> _classes; + + /** * The information that is passed to the Zend engine * * Although it would be slightly faster to not make this a pointer, this |