diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-30 18:19:03 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2015-01-30 18:19:03 +0100 |
commit | 6cde9cfcf21e18cd175008029432b91143578033 (patch) | |
tree | 8965c9a68ea98cfec9dd756002119d4fe971620b /src/core/common | |
parent | a92d31d1a84124758ae15e80e90efea93f03d416 (diff) |
Added Argument::Cardinality named constructor to Argument
Diffstat (limited to 'src/core/common')
-rw-r--r-- | src/core/common/Argument.cpp | 19 | ||||
-rw-r--r-- | src/core/common/Argument.hpp | 24 |
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. |