summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-18 23:34:34 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-18 23:34:34 +0100
commit5ea3a8d897496cbbafc5202b2b874396cb37914e (patch)
tree8a98ddbb7b1856de24dba23de552390d566476a4
parenta4968eb347bb53f9f5467336425c6472f3cc298b (diff)
implemented namespace::constants() method
-rw-r--r--zend/namespace.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/zend/namespace.cpp b/zend/namespace.cpp
index 893f2f0..575becf 100644
--- a/zend/namespace.cpp
+++ b/zend/namespace.cpp
@@ -140,6 +140,31 @@ void Namespace::classes(const std::function<void(const std::string &ns, ClassBas
}
/**
+ * Apply a callback to each registered constant
+ *
+ * The callback will be called with the name of the namespace, and
+ * a reference to the registered constant
+ *
+ * @param callback
+ */
+void Namespace::constants(const std::function<void(const std::string &ns, Constant &constant)> &callback)
+{
+ // loop through the constants, and apply the callback
+ for (auto &c : _constants) callback(_name, *c);
+
+ // loop through the other namespaces
+ for (auto &ns : _namespaces) ns->constants([this, callback](const std::string &ns, Constant &constant) {
+
+ // if this is the root namespace, we don't have to change the prefix
+ if (_name.size() == 0) return callback(ns, constant);
+
+ // construct a new prefix
+ // @todo this could be slightly inefficient
+ return callback(_name + "\\" + ns, constant);
+ });
+}
+
+/**
* End namespace
*/
}