Added static constructors to ParamConstraint

This commit is contained in:
Leonetienne
2021-06-03 00:00:53 +02:00
parent 1cd9abd11d
commit 91ab87ca4d
7 changed files with 271 additions and 274 deletions

View File

@@ -9,6 +9,28 @@ public:
//! Empty constructor
ParamConstraint() = default;
//! Constructs a require constraint
static ParamConstraint Require(const std::string& key, const std::vector<std::string>& defaultValue = {}, bool required = true)
{
ParamConstraint pc;
pc.key = key;
pc.defaultValue = defaultValue;
pc.required = required;
return pc;
}
//! Constructs a type-safety constraint
static ParamConstraint TypeSafety(const std::string& key, DATA_TYPE wantedType, bool constrainType = true)
{
ParamConstraint pc;
pc.key = key;
pc.constrainType = constrainType;
pc.wantedType = wantedType;
return pc;
}
//! Whole constructor
ParamConstraint(const std::string& key, bool constrainType, DATA_TYPE wantedType, const std::vector<std::string>& defaultValue, bool required)
:
@@ -21,26 +43,6 @@ public:
return;
}
//! Type-Constraint constructor
ParamConstraint(const std::string& key, bool constrainType, DATA_TYPE wantedType)
:
key{ key },
constrainType{ constrainType },
wantedType{ wantedType }
{
return;
}
//! Require-Constraint constructor
ParamConstraint(const std::string& key, const std::vector<std::string>& defaultValue, bool required = false)
:
key{ key },
defaultValue{ defaultValue },
required{ required }
{
return;
}
//! The key of the parameter to constrain
std::string key;

View File

@@ -48,7 +48,7 @@ int main(int argc, char** argv)
// Use
if (args.HasParam("--alfredo"))
{
std::cout << args["--alfredo"] << std::endl;
std::cout << args["--alfredo"].GetInt32() << std::endl;
}
else
{