Skip to content

Commit

Permalink
Create struct
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes committed Dec 19, 2024
1 parent 02d75d0 commit 5af3641
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

#pragma once
#include <optional>
#include <set>
#include <string>

Expand All @@ -38,7 +37,13 @@ struct AdditionalConstraint

unsigned int globalIndex = 0;

std::optional<std::string> validate() const;
struct ValidateResult
{
bool ok;
std::string error_msg;
};

ValidateResult validate() const;

private:
bool isValidVariable() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@

namespace Antares::Data::ShortTermStorage
{
std::optional<std::string> AdditionalConstraint::validate() const
AdditionalConstraint::ValidateResult AdditionalConstraint::validate() const
{
if (cluster_id.empty())
{
return "Cluster ID is empty.";
return {false, "Cluster ID is empty."};
}

if (!isValidVariable())
{
return "Invalid variable type. Must be 'injection', 'withdrawal', or 'netting'.";
return {false, "Invalid variable type. Must be 'injection', 'withdrawal', or 'netting'."};
}

if (!isValidOperatorType())
{
return "Invalid operator type. Must be 'less', 'equal', or 'greater'.";
return {false, "Invalid operator type. Must be 'less', 'equal', or 'greater'."};
}

if (!isValidHoursRange())
{
return "Hours set contains invalid values. Must be between 1 and 168.";
return {false, "Hours set contains invalid values. Must be between 1 and 168."};
}

return {};
return {true, ""};
}

bool AdditionalConstraint::isValidHoursRange() const
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/parts/short-term-storage/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)
}
}

if (auto errorMaybe = constraint.validate())
if (auto ret = constraint.validate(); !ret.ok)
{
logs.error() << "Invalid constraint in section: " << section->name;
logs.error() << errorMaybe.value();
logs.error() << ret.error_msg;
return false;
}

Expand Down

0 comments on commit 5af3641

Please sign in to comment.