-
Notifications
You must be signed in to change notification settings - Fork 37
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
Remove ambiguity in package names. #425
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #425 +/- ##
===========================================
+ Coverage 57.66% 57.68% +0.02%
===========================================
Files 109 109
Lines 11378 11387 +9
===========================================
+ Hits 6561 6569 +8
- Misses 4817 4818 +1
Continue to review full report at Codecov.
|
Co-authored-by: Andrew Gaspar <agaspar@lanl.gov>
This is a nice improvement IMO. As a downstream consumer I think the API-breaking is justified. It seems to me right now (and like @AndrewGaspar says) that it would be better to just throw an error if you try to add a package that's already added, I'm having a hard time imagining a scenario where you would want the application to proceed when you try to add some package that doesn't get added because of a name conflict. One issue I worry about though is if you are trying to add two packages that have the same |
Thanks, @AndrewGaspar and @brryan for your comments! I've made the changes you suggest, @AndrewGaspar except for deleting the commented out
I think for now we should just forbid this, as @AndrewGaspar suggested and throw an error. But I agree in the future we might need to be more clever. |
@AndrewGaspar I think all your review comments should be addressed now. |
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.
Thanks for doing this @Yurlungur. This issue has bothered me for a long time and your resolution seems quite reasonable.
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.
Thanks for taking care of this!
I was just about to ask if the documentation was updated and then double checked to realize that we don't have docs for this piece (except for "look at the advection example") 😄
I think the pointer to the advection example is fine/enough so let's get this in.
PR Summary
This is related to issue #423 and fixes (in my opinion) an underlying design flaw. In a downstream code, @clellsolomon discovered that there are really two names for each package. There's the label set in the
StateDescriptor
constructor, e.g.,auto pkg = std::make_shared<StateDescriptor>(name1);
and then there's the key in the
std::unordered_map
used forPackages_t
:It's implicitly assumed that
name1
andname2
are the same, but it's not enforced anywhere. And even if we enforced it, it's strange that we require the user to enter this name twice. Here I propose and implement one solution, which I think is the preferred one. I have changedPackates_t
from astd::unordered_map
to it's own class, which adds a package with the same key as the label in the package. E.g., you now call:packages.Add(pkg); // registers the package with name pkg->label()
and you can access the package via
packages.Get("package name");
which has bounds checking, so an error is thrown if the package doesn't exist.
I like this solution because it:
The disadvantages of this solution are:
operator[]
fromPackages_t
and replaced it withAdd
andGet
. However, the changes to downstream codes should be very easy.I'm interested in people's thoughts.
PR Checklist