Renamed 'ParamConstraint::wantedType' to 'ParamConstraint::requiredType'
This commit is contained in:
parent
09a2ce4e74
commit
1b8c156314
BIN
Hazelnupp.vpp
BIN
Hazelnupp.vpp
Binary file not shown.
@ -182,21 +182,21 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
|||||||
|
|
||||||
// Is a list forced via a constraint? If yes, return an empty list
|
// Is a list forced via a constraint? If yes, return an empty list
|
||||||
if ((constrainType) &&
|
if ((constrainType) &&
|
||||||
(constraint->wantedType == DATA_TYPE::LIST))
|
(constraint->requiredType == DATA_TYPE::LIST))
|
||||||
return new ListValue();
|
return new ListValue();
|
||||||
|
|
||||||
// Is a string forced via a constraint? If yes, return an empty string
|
// Is a string forced via a constraint? If yes, return an empty string
|
||||||
else if ((constrainType) &&
|
else if ((constrainType) &&
|
||||||
(constraint->wantedType == DATA_TYPE::STRING))
|
(constraint->requiredType == DATA_TYPE::STRING))
|
||||||
return new StringValue("");
|
return new StringValue("");
|
||||||
|
|
||||||
// Is an int or float forced via constraint? If yes, throw an exception
|
// Is an int or float forced via constraint? If yes, throw an exception
|
||||||
else if ((constrainType) &&
|
else if ((constrainType) &&
|
||||||
((constraint->wantedType == DATA_TYPE::INT) ||
|
((constraint->requiredType == DATA_TYPE::INT) ||
|
||||||
(constraint->wantedType == DATA_TYPE::FLOAT)))
|
(constraint->requiredType == DATA_TYPE::FLOAT)))
|
||||||
throw HazelnuppConstraintTypeMissmatch(
|
throw HazelnuppConstraintTypeMissmatch(
|
||||||
constraint->key,
|
constraint->key,
|
||||||
constraint->wantedType,
|
constraint->requiredType,
|
||||||
rawInputType,
|
rawInputType,
|
||||||
GetDescription(constraint->key)
|
GetDescription(constraint->key)
|
||||||
);
|
);
|
||||||
@ -207,7 +207,7 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
|||||||
|
|
||||||
// Force void type by constraint
|
// Force void type by constraint
|
||||||
else if ((constrainType) &&
|
else if ((constrainType) &&
|
||||||
(constraint->wantedType == DATA_TYPE::VOID))
|
(constraint->requiredType == DATA_TYPE::VOID))
|
||||||
{
|
{
|
||||||
return new VoidValue;
|
return new VoidValue;
|
||||||
}
|
}
|
||||||
@ -219,11 +219,11 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
|||||||
|
|
||||||
// Should the type be something other than list?
|
// Should the type be something other than list?
|
||||||
if ((constrainType) &&
|
if ((constrainType) &&
|
||||||
(constraint->wantedType != DATA_TYPE::LIST))
|
(constraint->requiredType != DATA_TYPE::LIST))
|
||||||
{
|
{
|
||||||
throw HazelnuppConstraintTypeMissmatch(
|
throw HazelnuppConstraintTypeMissmatch(
|
||||||
constraint->key,
|
constraint->key,
|
||||||
constraint->wantedType,
|
constraint->requiredType,
|
||||||
rawInputType,
|
rawInputType,
|
||||||
GetDescription(constraint->key)
|
GetDescription(constraint->key)
|
||||||
);
|
);
|
||||||
@ -250,10 +250,10 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
|||||||
// Is the type not supposed to be a string?
|
// Is the type not supposed to be a string?
|
||||||
// void and list are already sorted out
|
// void and list are already sorted out
|
||||||
if ((constrainType) &&
|
if ((constrainType) &&
|
||||||
(constraint->wantedType != DATA_TYPE::STRING))
|
(constraint->requiredType != DATA_TYPE::STRING))
|
||||||
{
|
{
|
||||||
// We can only force a list-value from here
|
// We can only force a list-value from here
|
||||||
if (constraint->wantedType == DATA_TYPE::LIST)
|
if (constraint->requiredType == DATA_TYPE::LIST)
|
||||||
{
|
{
|
||||||
ListValue* list = new ListValue();
|
ListValue* list = new ListValue();
|
||||||
Value* tmp = ParseValue({ val });
|
Value* tmp = ParseValue({ val });
|
||||||
@ -266,7 +266,7 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
|||||||
else
|
else
|
||||||
throw HazelnuppConstraintTypeMissmatch(
|
throw HazelnuppConstraintTypeMissmatch(
|
||||||
constraint->key,
|
constraint->key,
|
||||||
constraint->wantedType,
|
constraint->requiredType,
|
||||||
rawInputType,
|
rawInputType,
|
||||||
GetDescription(constraint->key)
|
GetDescription(constraint->key)
|
||||||
);
|
);
|
||||||
@ -278,7 +278,7 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
|||||||
// In this case we have a numeric value.
|
// In this case we have a numeric value.
|
||||||
// We should still produce a string if requested
|
// We should still produce a string if requested
|
||||||
if ((constrainType) &&
|
if ((constrainType) &&
|
||||||
(constraint->wantedType == DATA_TYPE::STRING))
|
(constraint->requiredType == DATA_TYPE::STRING))
|
||||||
return new StringValue(val);
|
return new StringValue(val);
|
||||||
|
|
||||||
// Numeric
|
// Numeric
|
||||||
@ -294,10 +294,10 @@ Value* Hazelnupp::ParseValue(const std::vector<std::string>& values, const Param
|
|||||||
if (constrainType)
|
if (constrainType)
|
||||||
{
|
{
|
||||||
// Must it be an integer?
|
// Must it be an integer?
|
||||||
if (constraint->wantedType == DATA_TYPE::INT)
|
if (constraint->requiredType == DATA_TYPE::INT)
|
||||||
return new IntValue((long long int)num);
|
return new IntValue((long long int)num);
|
||||||
// Must it be a floating point?
|
// Must it be a floating point?
|
||||||
else if (constraint->wantedType == DATA_TYPE::FLOAT)
|
else if (constraint->requiredType == DATA_TYPE::FLOAT)
|
||||||
return new FloatValue(num);
|
return new FloatValue(num);
|
||||||
// Else it must be a List
|
// Else it must be a List
|
||||||
else
|
else
|
||||||
@ -442,7 +442,7 @@ std::string Hazelnupp::GenerateDocumentation() const
|
|||||||
ParamDocEntry& cached = paramInfos[it.first];
|
ParamDocEntry& cached = paramInfos[it.first];
|
||||||
cached.required = it.second.required;
|
cached.required = it.second.required;
|
||||||
cached.typeIsForced = it.second.constrainType;
|
cached.typeIsForced = it.second.constrainType;
|
||||||
cached.type = DataTypeToString(it.second.wantedType);
|
cached.type = DataTypeToString(it.second.requiredType);
|
||||||
|
|
||||||
std::stringstream defaultValueSs;
|
std::stringstream defaultValueSs;
|
||||||
for (const std::string& s : it.second.defaultValue)
|
for (const std::string& s : it.second.defaultValue)
|
||||||
|
@ -23,20 +23,20 @@ namespace Hazelnp
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Constructs a type-safety constraint
|
//! Constructs a type-safety constraint
|
||||||
static ParamConstraint TypeSafety(DATA_TYPE wantedType, bool constrainType = true)
|
static ParamConstraint TypeSafety(DATA_TYPE requiredType, bool constrainType = true)
|
||||||
{
|
{
|
||||||
ParamConstraint pc;
|
ParamConstraint pc;
|
||||||
pc.constrainType = constrainType;
|
pc.constrainType = constrainType;
|
||||||
pc.wantedType = wantedType;
|
pc.requiredType = requiredType;
|
||||||
|
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Whole constructor
|
//! Whole constructor
|
||||||
ParamConstraint(bool constrainType, DATA_TYPE wantedType, const std::vector<std::string>& defaultValue, bool required)
|
ParamConstraint(bool constrainType, DATA_TYPE requiredType, const std::vector<std::string>& defaultValue, bool required)
|
||||||
:
|
:
|
||||||
constrainType{ constrainType },
|
constrainType{ constrainType },
|
||||||
wantedType{ wantedType },
|
requiredType{ requiredType },
|
||||||
defaultValue{ defaultValue },
|
defaultValue{ defaultValue },
|
||||||
required{ required }
|
required{ required }
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ namespace Hazelnp
|
|||||||
bool constrainType = false;
|
bool constrainType = false;
|
||||||
|
|
||||||
//! Constrain the parameter to this value. Requires `constrainType` to be set to true.
|
//! Constrain the parameter to this value. Requires `constrainType` to be set to true.
|
||||||
DATA_TYPE wantedType = DATA_TYPE::VOID;
|
DATA_TYPE requiredType = DATA_TYPE::VOID;
|
||||||
|
|
||||||
//! The default value for this parameter.
|
//! The default value for this parameter.
|
||||||
//! Gets applied if this parameter was not given.
|
//! Gets applied if this parameter was not given.
|
||||||
|
@ -26,9 +26,9 @@ namespace TestHazelnupp
|
|||||||
Hazelnupp nupp;
|
Hazelnupp nupp;
|
||||||
nupp.SetCrashOnFail(false);
|
nupp.SetCrashOnFail(false);
|
||||||
|
|
||||||
nupp.RegisterConstraint("--elenor-int", ParamConstraint::Require({"5994"}));
|
nupp.RegisterConstraint("--elenor-int", ParamConstraint::Require({ "5994" }));
|
||||||
nupp.RegisterConstraint("--federich-float", ParamConstraint::Require({ "420.69" }));
|
nupp.RegisterConstraint("--federich-float", ParamConstraint::Require({ "420.69" }));
|
||||||
nupp.RegisterConstraint("--siegbert-string", ParamConstraint::Require({"banana"}));
|
nupp.RegisterConstraint("--siegbert-string", ParamConstraint::Require({ "banana" }));
|
||||||
nupp.RegisterConstraint("--lieber-liste", ParamConstraint::Require({ "banana", "apple", "59" }));
|
nupp.RegisterConstraint("--lieber-liste", ParamConstraint::Require({ "banana", "apple", "59" }));
|
||||||
|
|
||||||
nupp.Parse(C_Ify(args));
|
nupp.Parse(C_Ify(args));
|
||||||
@ -79,9 +79,9 @@ namespace TestHazelnupp
|
|||||||
nupp.SetCrashOnFail(false);
|
nupp.SetCrashOnFail(false);
|
||||||
|
|
||||||
nupp.RegisterConstraint("--elenor-int", ParamConstraint::Require({ "6871" }));
|
nupp.RegisterConstraint("--elenor-int", ParamConstraint::Require({ "6871" }));
|
||||||
nupp.RegisterConstraint("--federich-float", ParamConstraint::Require({"-199.44"}));
|
nupp.RegisterConstraint("--federich-float", ParamConstraint::Require({ "-199.44" }));
|
||||||
nupp.RegisterConstraint("--siegbert-string", ParamConstraint::Require({"bornana"}));
|
nupp.RegisterConstraint("--siegbert-string", ParamConstraint::Require({ "bornana" }));
|
||||||
nupp.RegisterConstraint("--lieber-liste", ParamConstraint::Require({"bornana", "ollpe", "5"}));
|
nupp.RegisterConstraint("--lieber-liste", ParamConstraint::Require({ "bornana", "ollpe", "5" }));
|
||||||
|
|
||||||
nupp.Parse(C_Ify(args));
|
nupp.Parse(C_Ify(args));
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ namespace TestHazelnupp
|
|||||||
|
|
||||||
nupp.RegisterConstraint(
|
nupp.RegisterConstraint(
|
||||||
"--elenor-int",
|
"--elenor-int",
|
||||||
ParamConstraint::TypeSafety( DATA_TYPE::INT)
|
ParamConstraint::TypeSafety(DATA_TYPE::INT)
|
||||||
);
|
);
|
||||||
|
|
||||||
nupp.Parse(C_Ify(args));
|
nupp.Parse(C_Ify(args));
|
||||||
@ -413,7 +413,7 @@ namespace TestHazelnupp
|
|||||||
|
|
||||||
nupp.RegisterConstraint(
|
nupp.RegisterConstraint(
|
||||||
"--default-val",
|
"--default-val",
|
||||||
ParamConstraint::Require({"32"}, true)
|
ParamConstraint::Require({ "32" }, true)
|
||||||
);
|
);
|
||||||
|
|
||||||
nupp.RegisterConstraint(
|
nupp.RegisterConstraint(
|
||||||
@ -507,7 +507,7 @@ namespace TestHazelnupp
|
|||||||
nupp.SetCrashOnFail(false);
|
nupp.SetCrashOnFail(false);
|
||||||
|
|
||||||
ParamConstraint dftvalConst_expected =
|
ParamConstraint dftvalConst_expected =
|
||||||
ParamConstraint::Require({"32"}, true);
|
ParamConstraint::Require({ "32" }, true);
|
||||||
|
|
||||||
nupp.RegisterConstraint("--default-val", dftvalConst_expected);
|
nupp.RegisterConstraint("--default-val", dftvalConst_expected);
|
||||||
nupp.RegisterConstraint("--not-there", ParamConstraint::Require({}, true));
|
nupp.RegisterConstraint("--not-there", ParamConstraint::Require({}, true));
|
||||||
@ -519,7 +519,7 @@ namespace TestHazelnupp
|
|||||||
// Verify
|
// Verify
|
||||||
Assert::IsTrue(dftvalConst_expected.required == dftvalConst.required, L"required");
|
Assert::IsTrue(dftvalConst_expected.required == dftvalConst.required, L"required");
|
||||||
Assert::IsTrue(dftvalConst_expected.defaultValue == dftvalConst.defaultValue, L"defaultValue");
|
Assert::IsTrue(dftvalConst_expected.defaultValue == dftvalConst.defaultValue, L"defaultValue");
|
||||||
Assert::IsTrue(dftvalConst_expected.wantedType == dftvalConst.wantedType, L"wantedType");
|
Assert::IsTrue(dftvalConst_expected.requiredType == dftvalConst.requiredType, L"requiredType");
|
||||||
Assert::IsTrue(dftvalConst_expected.constrainType == dftvalConst.constrainType, L"constrainType");
|
Assert::IsTrue(dftvalConst_expected.constrainType == dftvalConst.constrainType, L"constrainType");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -244,7 +244,7 @@ Note that you can also combine these two constraint-types by populating the stru
|
|||||||
```cpp
|
```cpp
|
||||||
ParamConstraint pc;
|
ParamConstraint pc;
|
||||||
pc.constrainType = true;
|
pc.constrainType = true;
|
||||||
pc.wantedType = DATA_TYPE::STRING;
|
pc.requiredType = DATA_TYPE::STRING;
|
||||||
pc.defaultValue = {}; // no default value
|
pc.defaultValue = {}; // no default value
|
||||||
pc.required = true;
|
pc.required = true;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user