summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-22 18:45:44 +0100
committerAndreas Stöckel <andreas@somweyr.de>2014-12-22 18:45:44 +0100
commit9ebe4f0b90a7217e479c656209e87ab6292662d5 (patch)
tree56c56be1a26392438b82b34a7bdaeb450aa9e747 /src
parent9c8d6b461246bbee6e3d8ac411c7f10da481acf2 (diff)
added unit tests and documentation for the IntType class
Diffstat (limited to 'src')
-rw-r--r--src/core/model/Typesystem.cpp30
-rw-r--r--src/core/model/Typesystem.hpp40
2 files changed, 48 insertions, 22 deletions
diff --git a/src/core/model/Typesystem.cpp b/src/core/model/Typesystem.cpp
index 36b6743..9be78d1 100644
--- a/src/core/model/Typesystem.cpp
+++ b/src/core/model/Typesystem.cpp
@@ -54,6 +54,16 @@ bool StringType::doBuild(Variant &var, Logger &logger) const
return true;
}
+/* Class IntType */
+
+bool IntType::doBuild(Variant &var, Logger &logger) const
+{
+ if (!var.isInt()) {
+ throw LoggableException{"Expected an integer value."};
+ }
+ return true;
+}
+
/* Class EnumType */
EnumType EnumType::createValidated(Manager &mgr, std::string name,
@@ -79,19 +89,17 @@ EnumType EnumType::createValidated(Manager &mgr, std::string name,
bool ArrayType::doBuild(Variant &var, Logger &logger) const
{
- if (!var.isArray()) {
- throw LoggableException("Expected array!");
- }
- bool res = true;
- for (auto &v : var.asArray()) {
- if (!innerType->build(v, logger)) {
- res = false;
- }
+ if (!var.isArray()) {
+ throw LoggableException("Expected array!");
+ }
+ bool res = true;
+ for (auto &v : var.asArray()) {
+ if (!innerType->build(v, logger)) {
+ res = false;
}
-
- return res;
+ }
+ return res;
}
-
}
/* RTTI type registrations */
diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp
index b05e132..195cf00 100644
--- a/src/core/model/Typesystem.hpp
+++ b/src/core/model/Typesystem.hpp
@@ -110,6 +110,9 @@ public:
/**
* Returns the underlying Typesystem instance.
+ *
+ * @return a Rooted reference pointing at the underlying typesystem
+ * instance.
*/
Rooted<Typesystem> getTypesystem()
{
@@ -127,13 +130,18 @@ protected:
/**
* If possible, converts the given variant to a string. Only works, if the
* variant contains primitive objects (integers, strings, booleans, etc.).
+ *
+ * @param var is a variant containing the data that should be checked and
+ * converted to a string.
+ * @param logger is the Logger instance into which errors should be written.
+ * @return true if the conversion was successful, false otherwise.
*/
bool doBuild(Variant &var, Logger &logger) const override;
public:
/**
* Constructor of the StringType class. Only one instance of StringType
- * should exist per project.
+ * should exist per project graph.
*
* @param mgr is the Manager instance to be used for the Node.
* @param name is the name of the type.
@@ -152,22 +160,30 @@ public:
Variant create() const override { return Variant{""}; }
};
+/**
+ * The IntType class represents the primitive integer type. There should exactly
+ * be a single instance of this class available in a preloaded type system.
+ */
class IntType : public Type {
protected:
/**
- * TODO: DOC
+ * Simply expects the given variant to be an integer. Does not perform any
+ * type conversion.
+ *
+ * @param var is a variant containing the data that should be checked.
+ * @param logger is the Logger instance into which errors should be written.
+ * @return true if the conversion was successful, false otherwise.
*/
- bool doBuild(Variant &var, Logger &logger) const override
- {
- if (!var.isInt()) {
- throw LoggableException{"Expected an integer value."};
- }
- return true;
- }
+ bool doBuild(Variant &var, Logger &logger) const override;
public:
/**
- * TODO: DOC
+ * Constructor of the IntType class. Only one instance of IntType should
+ * exist per project graph.
+ *
+ * @param mgr is the Manager instance to be used for the Node.
+ * @param name is the name of the type.
+ * @param system is a reference to the parent Typesystem instance.
*/
IntType(Manager &mgr, Handle<Typesystem> system)
: Type(mgr, "int", system, true)
@@ -175,7 +191,9 @@ public:
}
/**
- * TODO: DOC
+ * Returns a variant containing the integer value zero.
+ *
+ * @return the integer value zero.
*/
Variant create() const override { return Variant{0}; }
};