summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/common/Argument.cpp19
-rw-r--r--src/core/common/Argument.hpp24
2 files changed, 36 insertions, 7 deletions
diff --git a/src/core/common/Argument.cpp b/src/core/common/Argument.cpp
index 21d4f6c..05c9761 100644
--- a/src/core/common/Argument.cpp
+++ b/src/core/common/Argument.cpp
@@ -27,9 +27,8 @@ namespace ousia {
/* Class Argument */
-Argument::Argument(std::string name, const Rtti &type,
- const Rtti &innerType, Variant defaultValue,
- bool hasDefault)
+Argument::Argument(std::string name, const Rtti &type, const Rtti &innerType,
+ Variant defaultValue, bool hasDefault)
: type(type),
innerType(innerType),
name(std::move(name)),
@@ -105,8 +104,7 @@ Argument Argument::Object(std::string name, const Rtti &type)
Variant::fromObject(nullptr), false);
}
-Argument Argument::Object(std::string name, const Rtti &type,
- std::nullptr_t)
+Argument Argument::Object(std::string name, const Rtti &type, std::nullptr_t)
{
return Argument(std::move(name), type, RttiTypes::None,
Variant::fromObject(nullptr), true);
@@ -170,6 +168,17 @@ Argument Argument::Map(std::string name, const Rtti &innerType,
true);
}
+Argument Argument::Cardinality(std::string name)
+{
+ return Argument{name, RttiTypes::Cardinality};
+}
+
+Argument Argument::Cardinality(std::string name,
+ Variant::cardinalityType defaultValue)
+{
+ return Argument{name, RttiTypes::Cardinality, defaultValue};
+}
+
bool Argument::validate(Variant &var, Logger &logger) const
{
if (!VariantConverter::convert(var, type, innerType, logger,
diff --git a/src/core/common/Argument.hpp b/src/core/common/Argument.hpp
index 8d01c2d..42b1722 100644
--- a/src/core/common/Argument.hpp
+++ b/src/core/common/Argument.hpp
@@ -370,6 +370,27 @@ public:
const Variant::mapType &defaultValue);
/**
+ * Named constructor for a cardinality argument with no default value.
+ *
+ * @param name is the name of the argument as used for error messages and in
+ * case the arguments are given as a map.
+ * @return a new Argument instance.
+ */
+ static Argument Cardinality(std::string name);
+
+ /**
+ * Named constructor for a Cardinality argument with default value.
+ *
+ * @param name is the name of the argument as used for error messages and in
+ * case the arguments are given as a map.
+ * @param defaultValue is the default value to be used in case this argument
+ * is not supplied.
+ * @return a new Argument instance.
+ */
+ static Argument Cardinality(std::string name,
+ Variant::cardinalityType defaultValue);
+
+ /**
* Makes sure the given variant is in the requested format and returns true
* if the variant was valid. Logs any error to the given logger instance.
* In case the validation was not successful, but the Argument instance was
@@ -409,7 +430,6 @@ private:
bool valid;
public:
-
/**
* Static Arguments instance with no explicit arguments set.
*/
@@ -418,7 +438,7 @@ public:
/**
* Default constructor. Provides no arguments.
*/
- Arguments() : valid(false) {};
+ Arguments() : valid(false){};
/**
* Constructor of the Arguments class from a list of Argument instances.