From 9bc5d1ed595e0ff0b7cec9a87d06a7923c211ebd Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 6 Apr 2014 14:44:03 +0200 Subject: removed all zend dependencies from the public extension object, and moved it into the src directory --- include/namespace.h | 155 +++++++++++++++++++++------------------------------- 1 file changed, 63 insertions(+), 92 deletions(-) (limited to 'include/namespace.h') diff --git a/include/namespace.h b/include/namespace.h index de73924..cd871d4 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -23,32 +23,37 @@ class Function; */ class Namespace { -public: +protected: /** - * Constructor - * @param name Name of the namespace + * Name of the namespace + * @var string */ - Namespace(const char *name) : _name(name) {} + std::string _name; + + /** + * Functions defined in the namespace + * @var list + */ + std::list> _functions; + + /** + * Classes defined in the namespace + * @var list + */ + std::list> _classes; /** - * Copy constructor - * @param ns Namespace to copy + * Namespaces defined inside the namespace + * @var list */ - Namespace(const Namespace &ns) : - _name(ns._name), - _functions(ns._functions), - _classes(ns._classes), - _namespaces(ns._namespaces) {} - + std::list> _namespaces; + +public: /** - * Move constructor - * @param ns + * Constructor + * @param name Name of the namespace */ - Namespace(Namespace &&ns) : - _name(std::move(ns._name)), - _functions(std::move(ns._functions)), - _classes(std::move(ns._classes)), - _namespaces(std::move(ns._namespaces)) {} + Namespace(const char *name) : _name(name) {} /** * Destructor @@ -56,7 +61,7 @@ public: virtual ~Namespace() {} /** - * Add a native function directly to the extension + * Add a native function directly to the namespace * @param name Name of the function * @param function The function to add * @param arguments Optional argument specification @@ -68,131 +73,91 @@ public: Namespace &add(const char *name, const native_callback_3 &function, const Arguments &arguments = {}); /** - * Add a native class to the extension by moving it + * Add a native class to the namespace by moving it * @param type The class implementation * @return Namespace Same object to allow chaining */ template Namespace &add(Class &&type) { - // make a copy of the object - auto *copy = new Class(std::move(type)); - - // and add it to the list of classes - _classes.push_back(std::unique_ptr(copy)); + // make a copy of the object, and add it to the list of classes + _classes.push_back(std::unique_ptr(new Class(std::move(type)))); // allow chaining return *this; } /** - * Add a native class to the extension by copying it + * Add a native class to the namespace by copying it * @param type The class implementation - * @param Namespace Same object to allow chaining + * @return Namespace Same object to allow chaining */ template Namespace &add(const Class &type) { - // make a copy of the object - auto *copy = new Class(std::move(type)); - // and add it to the list of classes - _classes.push_back(std::unique_ptr(copy)); + _classes.push_back(std::unique_ptr(new Class(type))); // allow chaining return *this; } /** - * Add an interface to the extension by moving it + * Add an interface to the namespace by moving it * @param interface The interface properties + * @return Namespace Same object to allow chaining */ Namespace &add(Interface &&interface) { - // make a copy of the object - auto *copy = new Interface(std::move(interface)); - - // and add it to the list of classes - _classes.push_back(std::unique_ptr(copy)); + // make a copy and add it to the list of classes + _classes.push_back(std::unique_ptr(new Interface(std::move(interface)))); // allow chaining return *this; } /** - * Add an interface to the extension by copying it + * Add an interface to the namespace by copying it * @param interface The interface properties + * @return Namespace Same object to allow chaining */ Namespace &add(const Interface &interface) { - // make a copy of the object - auto *copy = new Interface(interface); - - // and add it to the list of classes - _classes.push_back(std::unique_ptr(copy)); + // make a copy and add it to the list of classes + _classes.push_back(std::unique_ptr(new Interface(interface))); // allow chaining return *this; } /** - * Add a namespace to the extension by moving it + * Add a namespace to the namespace by moving it * @param ns The namespace + * @return Namespace Same object to allow chaining */ Namespace &add(Namespace &&ns) { - // make a copy of the object - auto *copy = new Namespace(std::move(ns)); - // add it to the list of namespaces - _namespaces.push_back(std::unique_ptr(copy)); + _namespaces.push_back(std::unique_ptr(new Namespace(std::move(ns)))); // allow chaining return *this; } /** - * Add a namespace to the extension by copying it + * Add a namespace to the namespace by copying it * @param ns The namespace + * @return Namespace Same object to allow chaining */ Namespace &add(const Namespace &ns) { - // make a copy of the object - auto *copy = new Namespace(std::move(ns)); - - // add it to the list of namespaces - _namespaces.push_back(std::unique_ptr(copy)); + // make a copy and add it to the list of namespaces + _namespaces.push_back(std::unique_ptr(new Namespace(ns))); // allow chaining return *this; } - -protected: - /** - * Name of the namespace - * @var string - */ - std::string _name; - - /** - * Functions defined by the extension - * @var list - */ - std::list> _functions; - - /** - * Classes defined by the extension - * @var list - */ - std::list> _classes; - - /** - * Namespaces defined by the extension - * @var list - */ - std::list> _namespaces; - /** * The total number of functions * @return size_t @@ -208,21 +173,27 @@ protected: // done return result; } - + /** - * Initialize all functions in this namespace - * @param ns Namespace prefix - * @param entries The array to be filled - * @return int Number of functions that were initialized + * Apply a callback to each registered function + * + * The callback will be called with the name of the namespace, and + * a reference to the registered function. + * + * @param callback */ - size_t initialize(const std::string &ns, struct _zend_function_entry entries[]); - + void apply(const std::function &callback); + /** - * Initialize the namespace after it was registered - * @param parent Parent namespace - * @param tsrm_ls + * Apply a callback to each registered class + * + * The callback will be called with the name of the namespace, and + * a reference to the registered class. + * + * @param callback */ - void initialize(const std::string &parent TSRMLS_DC); + void apply(const std::function &callback); + }; /** -- cgit v1.2.3