Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Jul 1, 2024
1 parent 8885fa7 commit fda4e11
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@

namespace Antares
{
using AreaErrorMessages = std::vector<std::string>;

class HydroErrorsCollector
{
public:
struct AreaSingleErrorMessage
{
std::string message = "";
unsigned int message_number = 0;
};

class AreaReference
{
public:
AreaReference(HydroErrorsCollector* collector, const std::string& name);
friend void operator<<(const AreaReference& ref, const std::string& msg);
template<class T>
AreaReference& operator<<(const T& msg);

~AreaReference()
{
// std::cout << areasErrorMap_ << std::endl;
}

private:
AreaErrorMessages& areasErrorMessages_;
AreaSingleErrorMessage& areaSingleErrorMessage_;
};

AreaReference operator()(const std::string& name);
Expand All @@ -51,7 +57,16 @@ class HydroErrorsCollector

private:
// for log
std::map<std::string, AreaErrorMessages> areasErrorMap_;
std::multimap<std::string, AreaSingleErrorMessage> areasErrorMap_;
};

template<class T>
HydroErrorsCollector::AreaReference& operator<<(const T& msg)
{
std::ostringstream strfy;
strfy << msg;
areaSingleErrorMessage_.message += strfy.str();
return *this;
}

} // namespace Antares
23 changes: 10 additions & 13 deletions src/solver/hydro/management/HydroErrorsCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ namespace Antares

void HydroErrorsCollector::CheckForErrors() const
{
if (!aresErrorMap_.empty())
if (!areasErrorMap_.empty())
{
for (const auto& [area_name, area_msgs]: areasErrorMap_)
for (const auto& [area_name, msg]: areasErrorMap_)
{
logs.error() << "In Area " << area_name;
for (const auto& msg: area_msgs)
{
logs.error() << msg;
}
logs.error() << "In Area " << area_name << msg;
}
throw FatalError("Hydro validation has failed !");
}
}

HydroErrorsCollector::AreaReference::AreaReference(HydroErrorsCollector* collector,
const std::string& name):
areasErrorMap_(collector->areasErrorMap_[name])
areaSingleErrorMessage_(
collector->areasErrorMap_
.insert(

{name,
{.message = "", .message_number = (unsigned int)collector->areasErrorMap_.count(name)}})
->second)
{
}

Expand All @@ -34,9 +36,4 @@ HydroErrorsCollector::AreaReference HydroErrorsCollector::operator()(const std::
return AreaReference(this, name);
}

void operator<<(const HydroErrorsCollector::AreaReference& ref, const std::string& msg)
{
// TODO what to do with empty msg?
ref.areasErrorMessages_.push_back(msg);
}
} // namespace Antares

0 comments on commit fda4e11

Please sign in to comment.