diff options
-rw-r--r-- | zend/namespace.cpp | 25 |
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 */ } |