From 5af3641431d4e39b5aa16af120c9fec972da703d Mon Sep 17 00:00:00 2001 From: Florian OMNES Date: Thu, 19 Dec 2024 13:10:59 +0100 Subject: [PATCH] Create struct --- .../parts/short-term-storage/AdditionalConstraint.h | 9 +++++++-- .../short-term-storage/AdditionalConstraint.cpp | 12 ++++++------ .../study/parts/short-term-storage/container.cpp | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/libs/antares/study/include/antares/study/parts/short-term-storage/AdditionalConstraint.h b/src/libs/antares/study/include/antares/study/parts/short-term-storage/AdditionalConstraint.h index 155ace32b1..e16b991a05 100644 --- a/src/libs/antares/study/include/antares/study/parts/short-term-storage/AdditionalConstraint.h +++ b/src/libs/antares/study/include/antares/study/parts/short-term-storage/AdditionalConstraint.h @@ -20,7 +20,6 @@ */ #pragma once -#include #include #include @@ -38,7 +37,13 @@ struct AdditionalConstraint unsigned int globalIndex = 0; - std::optional validate() const; + struct ValidateResult + { + bool ok; + std::string error_msg; + }; + + ValidateResult validate() const; private: bool isValidVariable() const; diff --git a/src/libs/antares/study/parts/short-term-storage/AdditionalConstraint.cpp b/src/libs/antares/study/parts/short-term-storage/AdditionalConstraint.cpp index e8ae87e9e9..2ca904041c 100644 --- a/src/libs/antares/study/parts/short-term-storage/AdditionalConstraint.cpp +++ b/src/libs/antares/study/parts/short-term-storage/AdditionalConstraint.cpp @@ -22,29 +22,29 @@ namespace Antares::Data::ShortTermStorage { -std::optional 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 diff --git a/src/libs/antares/study/parts/short-term-storage/container.cpp b/src/libs/antares/study/parts/short-term-storage/container.cpp index b0a6cfb9fe..39a958c5c7 100644 --- a/src/libs/antares/study/parts/short-term-storage/container.cpp +++ b/src/libs/antares/study/parts/short-term-storage/container.cpp @@ -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; }