summaryrefslogtreecommitdiff
path: root/include/namespace.h
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-04-09 11:00:05 +0600
committervalmat <ufabiz@gmail.com>2014-04-09 11:00:05 +0600
commit6c7c846edd5b74450b76532da33c25e6cc6a10a4 (patch)
tree51b0e0be5c43ddba6ca9351026fc94bf8ae7bc07 /include/namespace.h
parent08ed8866a5bba0b23a8d5587116a968512df2568 (diff)
parent33760c3efba4207eac826ff080b5f9b9672fc60e (diff)
Merge branch 'master' into ini-master
Conflicts: include/namespace.h zend/extensionimpl.cpp
Diffstat (limited to 'include/namespace.h')
-rw-r--r--include/namespace.h178
1 files changed, 71 insertions, 107 deletions
diff --git a/include/namespace.h b/include/namespace.h
index 5830339..25d4e5e 100644
--- a/include/namespace.h
+++ b/include/namespace.h
@@ -23,32 +23,43 @@ 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<std::shared_ptr<Function>> _functions;
+
+ /**
+ * Classes defined in the namespace
+ * @var list
+ */
+ std::list<std::shared_ptr<ClassBase>> _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<std::shared_ptr<Namespace>> _namespaces;
+
/**
- * Move constructor
- * @param ns
+ * Ini entry defined by the extension
+ * @var list
*/
- Namespace(Namespace &&ns) :
- _name(std::move(ns._name)),
- _functions(std::move(ns._functions)),
- _classes(std::move(ns._classes)),
- _namespaces(std::move(ns._namespaces)) {}
+ std::list<std::shared_ptr<Ini>> _ini_entries;
+
+public:
+ /**
+ * Constructor
+ * @param name Name of the namespace
+ */
+ Namespace(const char *name) : _name(name) {}
/**
* Destructor
@@ -56,7 +67,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,106 +79,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<typename T>
Namespace &add(Class<T> &&type)
{
- // make a copy of the object
- auto *copy = new Class<T>(std::move(type));
-
- // and add it to the list of classes
- _classes.push_back(std::unique_ptr<ClassBase>(copy));
+ // make a copy of the object, and add it to the list of classes
+ _classes.push_back(std::unique_ptr<ClassBase>(new Class<T>(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<typename T>
Namespace &add(const Class<T> &type)
{
- // make a copy of the object
- auto *copy = new Class<T>(std::move(type));
-
// and add it to the list of classes
- _classes.push_back(std::unique_ptr<ClassBase>(copy));
+ _classes.push_back(std::unique_ptr<ClassBase>(new Class<T>(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<ClassBase>(copy));
+ // make a copy and add it to the list of classes
+ _classes.push_back(std::unique_ptr<ClassBase>(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<ClassBase>(copy));
+ // make a copy and add it to the list of classes
+ _classes.push_back(std::unique_ptr<ClassBase>(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<Namespace>(copy));
+ _namespaces.push_back(std::unique_ptr<Namespace>(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<Namespace>(copy));
+ // make a copy and add it to the list of namespaces
+ _namespaces.push_back(std::unique_ptr<Namespace>(new Namespace(ns)));
// allow chaining
return *this;
}
-
/**
* Add a ini entry to the extension by moving it
* @param ini The class implementation
@@ -175,11 +171,8 @@ public:
*/
Namespace &add(Ini &&ini)
{
- // make a copy of the object
- auto *copy = new Ini(std::move(ini));
-
// and add it to the list of classes
- _ini_entries.push_back(std::unique_ptr<Ini>(copy));
+ _ini_entries.push_back(std::unique_ptr<Ini>(new Ini(std::move(ini))));
// allow chaining
return *this;
@@ -192,48 +185,13 @@ public:
*/
Namespace &add(const Ini &ini)
{
- // make a copy of the object
- auto *copy = new Ini(std::move(ini));
-
// and add it to the list of classes
- _ini_entries.push_back(std::unique_ptr<Ini>(copy));
+ _ini_entries.push_back(std::unique_ptr<Ini>(new Ini(ini)));
// allow chaining
return *this;
}
-
-protected:
- /**
- * Name of the namespace
- * @var string
- */
- std::string _name;
-
- /**
- * Functions defined by the extension
- * @var list
- */
- std::list<std::shared_ptr<Function>> _functions;
-
- /**
- * Classes defined by the extension
- * @var list
- */
- std::list<std::shared_ptr<ClassBase>> _classes;
-
- /**
- * Namespaces defined by the extension
- * @var list
- */
- std::list<std::shared_ptr<Namespace>> _namespaces;
-
- /**
- * Ini entry defined by the extension
- * @var list
- */
- std::list<std::shared_ptr<Ini>> _ini_entries;
-
/**
* The total number of functions
* @return size_t
@@ -249,21 +207,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<void(const std::string &ns, Function &func)> &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<void(const std::string &ns, ClassBase &clss)> &callback);
+
};
/**