-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Districts : simplifying the code #2279
Conversation
This reverts commit 065acfb.
We create a shared_ptr on the stack, stock the raw pointer in a vector then exit the scop. At this point the pointer is not valid anymore
Now that type setsOfLinks is gone (see previous commit), template about class Sets is useless. We remove it to simplify code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor remarks.
typename
makes no sense if there is no template, useauto
instead- Use modern style for loops
src/libs/antares/study/area/sets.cpp
Outdated
const typename MapType::const_iterator end = pMap.end(); | ||
for (typename MapType::const_iterator i = pMap.begin(); i != end; ++i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const typename MapType::const_iterator end = pMap.end(); | |
for (typename MapType::const_iterator i = pMap.begin(); i != end; ++i) | |
for (const auto& [name, content] : pMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that, no problem, but we should keep in mind that any std::map / std::vector used as a data members of class Sets (for instance pMap) should not exist : please see PR presentation comment.
std::map and std::vector are used because of a chaotic architecture of class Sets.
Making changes on these std::map and std::vector manipulations is making changes on things that should disappear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Done : all typenames were removed from sets.h/.cpp |
Add unit / study tests |
Please retry analysis of this Pull-Request directly on SonarCloud |
I added many tests to be run on CI (see this commit), knowing that district results are taken into account when running CI tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor remarks
- Revert workflow files
- Use
emplace_back(args...)
instead ofpush_back(T(args...))
src/libs/antares/study/area/sets.cpp
Outdated
opts.rules.push_back(Rule(ruleFilter, new String("add-all"))); | ||
auto item = std::make_shared<T>(); | ||
add("all areas", item, opts); | ||
opts.rules.push_back(Rule(ruleFilter, "add-all")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opts.rules.push_back(Rule(ruleFilter, "add-all")); | |
opts.rules.emplace_back(ruleFilter, "add-all"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Construction in place. I get it.
src/libs/antares/study/area/sets.cpp
Outdated
@@ -239,17 +209,17 @@ bool Sets<T>::loadFromFile(const std::filesystem::path& filename) | |||
|
|||
if (p->key == "+") | |||
{ | |||
opts.rules.push_back(Rule(ruleAdd, new String(value))); | |||
opts.rules.push_back(Rule(ruleAdd, value.to<std::string>())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so much better, the previous code was very confusing regarding memory ownership
.github/workflows/ubuntu.yml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this
.github/workflows/windows-vcpkg.yml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert
Unit tests could be added easier by doing recommended refactoring (see PR presentation) |
Quality Gate passedIssues Measures |
Type SetsOfAreas (see study.h) is used to print aggregated results for a group of areas.
Its friend SetsOfLinks is defined but never used.
We remove it and make subsequent simplifications :
What should be done in the future :
Instead, we should define a class Set (for a single set), and make existing class Sets a collection of Set.
Properties of a set should be contained in class Set. Besides the fact it would be more natural and clear, I suspect it would cause many simplifications and code reductions.