Skip to content
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

Insert Options attributes with initializer_list #2598

Merged
merged 6 commits into from
Oct 14, 2022
Merged

Conversation

bendudson
Copy link
Contributor

@bendudson bendudson commented Oct 13, 2022

This is probably more readable if setting multiple attributes:

Options options;
options["value"].setAttributes({
    {"units", "m/s"},
    {"conversion", 10.2},
    {"long_name", "important value"}
  });

Uses std::map::emplace internally, so doesn't replace or update values.
Replaces any values that were previously set.

Includes tests and some documentation.

This is probably more readable if setting multiple attributes:
```
Options options;
options["value"].insertAttributes({
    {"units", "m/s"},
    {"conversion", 10.2},
    {"long_name", "important value"}
  });
```

Uses `std::map::emplace` internally, so doesn't replace or update
values.

Includes tests and some documentation.
@bendudson bendudson added feature small-change Changes less than 100 lines - should be quick to review labels Oct 13, 2022
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

ZedThree
ZedThree previously approved these changes Oct 13, 2022
Copy link
Member

@ZedThree ZedThree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I wonder if we should go even further and have something like:

namespace bout {
struct Metadata {
  std::string units;
  std::string conversion;
  std::string long_name;
}
}

Maybe that actually adds too much complication for not enough benefit.

Uses std::map::emplace internally, so doesn't replace or update values.

It would be good to note this in the docstring and the manual, might be surprising otherwise!

Change the semantics so that attributes are always set, rather than
not replacing already set attributes. This way is probably more intuitive.
@bendudson
Copy link
Contributor Author

Thanks @ZedThree ! The semantics of map::emplace are quite weird, so I've changed it to Options.setAttributes() and it always updates/replaces any value already set.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

include/options.hxx Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Forgot to update the test, now that attributes are replaced.
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@boutproject boutproject deleted a comment from github-actions bot Oct 14, 2022
@ZedThree ZedThree merged commit 68ebf1c into next Oct 14, 2022
@ZedThree ZedThree deleted the next-options-attributes branch October 14, 2022 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature small-change Changes less than 100 lines - should be quick to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants