diff --git a/src/libs/antares/study/CMakeLists.txt b/src/libs/antares/study/CMakeLists.txt
index e9a05827ac..bc06a77089 100644
--- a/src/libs/antares/study/CMakeLists.txt
+++ b/src/libs/antares/study/CMakeLists.txt
@@ -249,7 +249,7 @@ set(SRC_STUDY
# Sets
include/antares/study/sets.h
- include/antares/study/sets.hxx
+ area/sets.cpp
# variable selection
include/antares/study/variable-print-info.h
diff --git a/src/libs/antares/study/include/antares/study/sets.hxx b/src/libs/antares/study/area/sets.cpp
similarity index 58%
rename from src/libs/antares/study/include/antares/study/sets.hxx
rename to src/libs/antares/study/area/sets.cpp
index 2a1b777995..f853c21c0c 100644
--- a/src/libs/antares/study/include/antares/study/sets.hxx
+++ b/src/libs/antares/study/area/sets.cpp
@@ -18,57 +18,41 @@
** You should have received a copy of the Mozilla Public Licence 2.0
** along with Antares_Simulator. If not, see .
*/
-#ifndef __ANTARES_LIBS_STUDY_SETS_HXX__
-#define __ANTARES_LIBS_STUDY_SETS_HXX__
+#include "antares/study/sets.h"
-namespace Antares
+namespace Antares::Data
{
-namespace Data
-{
-template
-inline Sets::Sets():
- pModified(false)
-{
-}
-
-template
-inline Sets::Sets(const Sets& rhs):
+Sets::Sets(const Sets& rhs):
pMap(rhs.pMap),
- pOptions(rhs.pOptions),
- pModified(false)
+ pOptions(rhs.pOptions)
{
- if (rhs.pByIndex)
+ if (rhs.pByIndex.size())
{
rebuildIndexes();
}
}
-template
-typename Sets::iterator Sets::begin()
+Sets::iterator Sets::begin()
{
return pMap.begin();
}
-template
-typename Sets::const_iterator Sets::begin() const
+Sets::const_iterator Sets::begin() const
{
return pMap.begin();
}
-template
-typename Sets::iterator Sets::end()
+Sets::iterator Sets::end()
{
return pMap.end();
}
-template
-typename Sets::const_iterator Sets::end() const
+Sets::const_iterator Sets::end() const
{
return pMap.end();
}
-template
-void Sets::clear()
+void Sets::clear()
{
pByIndex.clear();
pNameByIndex.clear();
@@ -76,36 +60,30 @@ void Sets::clear()
pOptions.clear();
}
-template
-inline T& Sets::operator[](uint i)
+Sets::SetAreasType& Sets::operator[](uint i)
{
assert(i < pMap.size() && "Sets: operator[] index out of bounds");
return *(pByIndex[i]);
}
-template
-inline const T& Sets::operator[](uint i) const
+const Sets::SetAreasType& Sets::operator[](uint i) const
{
assert(i < pMap.size() && "Sets: operator[] index out of bounds");
return *(pByIndex[i]);
}
-template
-template
-void Sets::dumpToLogs(L& log) const
+void Sets::dumpToLogs() const
{
using namespace Yuni;
- const typename MapType::const_iterator end = pMap.end();
- for (typename MapType::const_iterator i = pMap.begin(); i != end; ++i)
+ for (const auto& [setId, set]: pMap)
{
- log.info() << " found `" << i->first << "` (" << (uint)i->second->size() << ' '
- << (i->second->size() < 2 ? "item" : "items")
- << ((!hasOutput(i->first)) ? ", no output" : "") << ')';
+ logs.info() << " found `" << setId << "` (" << set->size() << ' '
+ << (set->size() < 2 ? "item" : "items")
+ << ((!hasOutput(setId)) ? ", no output" : "") << ')';
}
}
-template
-void Sets::defaultForAreas()
+void Sets::defaultForAreas()
{
using namespace Yuni;
clear();
@@ -113,23 +91,21 @@ void Sets::defaultForAreas()
opts.caption = "All areas";
opts.comments = "Spatial aggregates on all areas";
opts.output = false;
- opts.rules.push_back(Rule(ruleFilter, new String("add-all")));
- auto item = std::make_shared();
- add("all areas", item, opts);
+ opts.rules.emplace_back(ruleFilter, "add-all");
+ auto district = std::make_shared();
+ add("all areas", district, opts);
}
-template
-YString Sets::toString()
+YString Sets::toString()
{
using namespace Yuni;
using namespace Antares;
static const char* cmds[ruleMax] = {"none", "+", "-", "apply-filter"};
- const auto end = pOptions.cend();
YString ret = "";
- for (auto i = pOptions.cbegin(); i != end; ++i)
+ for (const auto& [setId, options]: pOptions)
{
- const Options& opts = i->second;
- ret << '[' << i->first << "]\n";
+ const Options& opts = options;
+ ret << '[' << setId << "]\n";
ret << "caption = " << opts.caption << '\n';
if (not opts.comments.empty())
{
@@ -150,13 +126,8 @@ YString Sets::toString()
return ret;
}
-template
-template
-bool Sets::saveToFile(const StringT& filename) const
+bool Sets::saveToFile(const Yuni::String& filename) const
{
- using namespace Yuni;
- using namespace Antares;
-
Yuni::IO::File::Stream file;
if (!file.open(filename, Yuni::IO::OpenMode::write | Yuni::IO::OpenMode::truncate))
{
@@ -190,8 +161,7 @@ bool Sets::saveToFile(const StringT& filename) const
return true;
}
-template
-bool Sets::loadFromFile(const std::filesystem::path& filename)
+bool Sets::loadFromFile(const std::filesystem::path& filename)
{
using namespace Yuni;
using namespace Antares;
@@ -221,7 +191,7 @@ bool Sets::loadFromFile(const std::filesystem::path& filename)
}
// Creating a new section
- auto item = std::make_shared();
+ auto district = std::make_shared();
Options opts;
opts.caption = section->name;
@@ -239,17 +209,17 @@ bool Sets::loadFromFile(const std::filesystem::path& filename)
if (p->key == "+")
{
- opts.rules.push_back(Rule(ruleAdd, new String(value)));
+ opts.rules.emplace_back(ruleAdd, value.to());
continue;
}
if (p->key == "-")
{
- opts.rules.push_back(Rule(ruleRemove, new String(value)));
+ opts.rules.emplace_back(ruleRemove, value.to());
continue;
}
if (p->key == "apply-filter")
{
- opts.rules.push_back(Rule(ruleFilter, new String(value)));
+ opts.rules.emplace_back(ruleFilter, value.to());
continue;
}
if (p->key == "output")
@@ -276,7 +246,7 @@ bool Sets::loadFromFile(const std::filesystem::path& filename)
// Add the new group
IDType newid = section->name;
newid.toLower();
- add(newid, item, opts);
+ add(newid, district, opts);
}
// Not modified anymore
@@ -288,31 +258,28 @@ bool Sets::loadFromFile(const std::filesystem::path& filename)
return false;
}
-template
-template
-inline void Sets::rebuildAllFromRules(HandlerT& handler)
+void Sets::rebuildAllFromRules(SetHandlerAreas& handler)
{
- for (uint i = 0; i != pMap.size(); ++i)
+ for (const auto& setId: pNameByIndex)
{
- rebuildFromRules(pNameByIndex[i], handler);
+ rebuildFromRules(setId, handler);
}
}
-template
-template
-void Sets::rebuildFromRules(const IDType& id, HandlerT& handler)
+void Sets::rebuildFromRules(const IDType& id, SetHandlerAreas& handler)
{
using namespace Yuni;
using namespace Antares;
- typename MapOptions::iterator i = pOptions.find(id);
- if (i == pOptions.end())
+ const auto pair = pOptions.find(id);
+ if (pair == pOptions.end())
{
return;
}
+
// Options
- Options& opts = i->second;
- Type& set = *(pMap[id]);
+ Options& opts = pair->second;
+ auto& set = *(pMap[id]);
// Clear the result first
handler.clear(set);
@@ -320,23 +287,20 @@ void Sets::rebuildFromRules(const IDType& id, HandlerT& handler)
for (uint i = 0; i != opts.rules.size(); ++i)
{
const Rule& rule = opts.rules[i];
- const Yuni::String& arg = *(rule.second);
+ const std::string name = rule.second;
switch (rule.first) // type
{
case ruleAdd:
{
// Trying to add a single item
- if (!handler.add(set, arg))
+ if (!handler.add(set, name))
{
// Failed. Maybe the argument references another group
- const IDType other = arg;
- typename MapType::iterator i = pMap.find(other);
+ const IDType other = name;
+ MapType::iterator i = pMap.find(other);
if (i != pMap.end())
{
- if (handler.add(set, *(i->second)))
- {
- break;
- }
+ handler.add(set, *(i->second));
}
}
break;
@@ -344,24 +308,21 @@ void Sets::rebuildFromRules(const IDType& id, HandlerT& handler)
case ruleRemove:
{
// Trying to remove a single item
- if (!handler.remove(set, arg))
+ if (!handler.remove(set, name))
{
// Failed. Maybe the argument references another group
- const IDType other = arg;
- typename MapType::iterator i = pMap.find(other);
+ const IDType other = name;
+ MapType::iterator i = pMap.find(other);
if (i != pMap.end())
{
- if (handler.remove(set, *(i->second)))
- {
- break;
- }
+ handler.remove(set, *(i->second));
}
}
break;
}
case ruleFilter:
{
- handler.applyFilter(set, arg);
+ handler.applyFilter(set, name);
break;
}
case ruleNone:
@@ -379,85 +340,125 @@ void Sets::rebuildFromRules(const IDType& id, HandlerT& handler)
<< " rules, got " << opts.resultSize << " items";
}
-template
-void Sets::rebuildIndexes()
+void Sets::rebuildIndexes()
{
pNameByIndex.clear();
+ pNameByIndex.resize(pMap.size());
+
pByIndex.clear();
+ pByIndex.resize(pMap.size());
- if (!pMap.empty())
+ uint index = 0;
+ for (const auto& [setId, set]: pMap)
{
- pByIndex.resize(pMap.size());
- pNameByIndex.resize(pMap.size());
- const typename MapType::iterator end = pMap.end();
- uint index = 0;
- for (typename MapType::iterator i = pMap.begin(); i != end; ++i)
- {
- pByIndex[index] = i->second;
- pNameByIndex[index] = i->first;
- ++index;
- }
+ pByIndex[index] = set;
+ pNameByIndex[index] = setId;
+ ++index;
}
}
-template
-template
-inline bool Sets::hasOutput(const StringT& s) const
+bool Sets::hasOutput(const Yuni::ShortString128& s) const
{
- // Assert, if a C* container can not be found at compile time
- static_assert(Yuni::Traits::CString::valid);
-
- typename MapOptions::const_iterator i = pOptions.find(s);
- return (i != pOptions.end()) ? i->second.output : false;
+ const auto pair = pOptions.find(s);
+ return (pair != pOptions.end()) ? pair->second.output : false;
}
-template
-inline bool Sets::hasOutput(const uint index) const
+bool Sets::hasOutput(const uint index) const
{
return hasOutput(IDType(pNameByIndex[index]));
}
-template
-template
-inline uint Sets::resultSize(const StringT& s) const
+uint Sets::resultSize(const Yuni::ShortString128& s) const
{
- // Assert, if a C* container can not be found at compile time
- static_assert(Yuni::Traits::CString::valid);
-
- typename MapOptions::const_iterator i = pOptions.find(s);
- return (i != pOptions.end()) ? i->second.resultSize : 0;
+ const auto pair = pOptions.find(s);
+ return (pair != pOptions.end()) ? pair->second.resultSize : 0;
}
-template
-template
-inline typename Sets::IDType Sets::caption(const StringT& s) const
+Sets::IDType Sets::caption(const Yuni::ShortString128& s) const
{
- // Assert, if a C* container can not be found at compile time
- static_assert(Yuni::Traits::CString::valid);
-
- typename MapOptions::const_iterator i = pOptions.find(s);
- return (i != pOptions.end()) ? i->second.caption : IDType();
+ const auto pair = pOptions.find(s);
+ return (pair != pOptions.end()) ? pair->second.caption : IDType();
}
-template
-inline typename Sets::IDType Sets::caption(const uint i) const
+Sets::IDType Sets::caption(const uint i) const
{
return caption(IDType(pNameByIndex[i]));
}
-template
-inline uint Sets::resultSize(const uint index) const
+uint Sets::resultSize(const uint index) const
{
return resultSize(IDType(pNameByIndex[index]));
}
-template
-inline uint Sets::size() const
+uint Sets::size() const
{
return (uint)pMap.size();
}
-} // namespace Data
-} // namespace Antares
+SetHandlerAreas::SetHandlerAreas(AreaList& areas):
+ areas_(areas)
+{
+}
+
+void SetHandlerAreas::clear(Sets::SetAreasType& set)
+{
+ set.clear();
+}
+
+uint SetHandlerAreas::size(Sets::SetAreasType& set)
+{
+ return (uint)set.size();
+}
+
+bool SetHandlerAreas::add(Sets::SetAreasType& set, const std::string& value)
+{
+ Area* area = AreaListLFind(&areas_, value.c_str());
+ if (area)
+ {
+ set.insert(area);
+ return true;
+ }
+ return false;
+}
+
+void SetHandlerAreas::add(Sets::SetAreasType& set, const Sets::SetAreasType& otherSet)
+{
+ set.insert(otherSet.begin(), otherSet.end());
+}
+
+bool SetHandlerAreas::remove(Sets::SetAreasType& set, const std::string& value)
+{
+ Area* area = AreaListLFind(&areas_, value.c_str());
+ if (area)
+ {
+ set.erase(area);
+ return true;
+ }
+ return false;
+}
+
+void SetHandlerAreas::remove(Sets::SetAreasType& set, const Sets::SetAreasType& otherSet)
+{
+ std::ranges::for_each(otherSet, [&set](auto* area) { set.erase(area); });
+}
+
+bool SetHandlerAreas::applyFilter(Sets::SetAreasType& set, const std::string& value)
+{
+ if (value == "add-all")
+ {
+ for (const auto& [areaName, area]: areas_)
+ {
+ set.insert(area);
+ }
+ return true;
+ }
+
+ if (value == "remove-all")
+ {
+ set.clear();
+ return true;
+ }
+ return false;
+}
-#endif // __ANTARES_LIBS_STUDY_SETS_HXX__
+} // namespace Antares::Data
diff --git a/src/libs/antares/study/include/antares/study/sets.h b/src/libs/antares/study/include/antares/study/sets.h
index 414847af2f..3932c99372 100644
--- a/src/libs/antares/study/include/antares/study/sets.h
+++ b/src/libs/antares/study/include/antares/study/sets.h
@@ -18,8 +18,7 @@
** You should have received a copy of the Mozilla Public Licence 2.0
** along with Antares_Simulator. If not, see .
*/
-#ifndef __ANTARES_LIBS_STUDY_SETS_H__
-#define __ANTARES_LIBS_STUDY_SETS_H__
+#pragma once
#include
#include