summaryrefslogtreecommitdiff
path: root/include/namespace.h
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-17 22:19:08 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-17 22:19:08 +0100
commit5fd8b29a1981d2d4f7c4e9925729fbe9f1c558bb (patch)
treee0738b3ebb653d1a7ae8a8c1f62f309f1895bfe5 /include/namespace.h
parent821e65d876cc0ce2b32471791b02d9f7cc784c99 (diff)
added initial implementation for registering constants
Diffstat (limited to 'include/namespace.h')
-rw-r--r--include/namespace.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/include/namespace.h b/include/namespace.h
index 84f0740..4bb23db 100644
--- a/include/namespace.h
+++ b/include/namespace.h
@@ -43,6 +43,12 @@ protected:
std::list<std::shared_ptr<ClassBase>> _classes;
/**
+ * Constants defined in the namespace
+ * @var list
+ */
+ std::list<std::shared_ptr<Constant>> _constants;
+
+ /**
* Namespaces defined inside the namespace
* @var list
*/
@@ -163,6 +169,40 @@ public:
}
/**
+ * Add a constant to the namespace
+ * @param constant The constant to add
+ * @return Namespace Same object to allow chaining
+ */
+ Namespace &add(Constant &&constant)
+ {
+ // skip when locked
+ if (locked()) return *this;
+
+ // and add it to the list of constants
+ _constants.push_back(std::unique_ptr<Constant>(new Constant(std::move(constant))));
+
+ // allow chaining
+ return *this;
+ }
+
+ /**
+ * Add a constant to the namespace
+ * @param constant The constant to add
+ * @return Namespace Same object to allow chaining
+ */
+ Namespace &add(const Constant &constant)
+ {
+ // skip when locked
+ if (locked()) return *this;
+
+ // and add it to the list of constants
+ _constants.push_back(std::unique_ptr<Constant>(new Constant(constant)));
+
+ // allow chaining
+ return *this;
+ }
+
+ /**
* Add a namespace to the namespace by moving it
* @param ns The namespace
* @return Namespace Same object to allow chaining
@@ -231,6 +271,16 @@ public:
* @param callback
*/
void classes(const std::function<void(const std::string &ns, ClassBase &clss)> &callback);
+
+ /**
+ * 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 constants(const std::function<void(const std::string &ns, Constant &constant)> &callback);
};