Commit 4285374
Allow std::string "name" arguments for ParmParse methods (#4695)
## Summary
The `ParmParse` constructor accepts argument `prefix == std::string`.
But once the object is created, methods on it require `char *` objects
for the `name` argument, leading to code like:
```
std::string prefix = "prefix";
std::string name = "name";
ParmParse pp(prefix);
pp.get(name.c_str(), input);
```
The proposed patch adds wrappers to allow arguments to `ParmParse`
methods `get`, `query`, etc, to allow the `name` argument to be a
`std::string`, so the `c_str()` is not needed and the interface is
consistent. It also fixes a few mismatches between comments and code.
## Additional background
Wrappers are provided for all methods except one. It was not possible to
add a `std::string` interface for the two-name version of `get`:
```
void get (const char* new_name, const char* old_name, T& ref)
```
because with `string` values for the first two arguments and an `int`
value for the third, this creates an ambiguity with the standard `get`:
```
void get (const std::string& name,
std::string& ref,
int ival = FIRST)
```
For this reason, a wrapper is not provided for the two-name version of
`get`.
Currently the only thing that disambiguates this template from the
standard `get` is that in the two-name version both names are `char*`
and in the template the second argument `ref` is `std::string`, allowing
the first argument to be `string` breaks this. This is an unforunate
feature of the API design.
Furthermore I believe this function is somewhat obscure and it should
possibly be deprecated or renamed to `get_with_fallback` or `get2` or
similar.
## Checklist
The proposed changes:
- [ ] fix a bug or incorrect behavior in AMReX
- [x] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX
users
- [ ] include documentation in the code and/or rst files, if appropriate
---------
Co-authored-by: Charles G Waldman <[email protected]>
Co-authored-by: Weiqun Zhang <[email protected]>1 parent e92641d commit 4285374
File tree
5 files changed
+595
-417
lines changed- Src
- Base
- Extern/HYPRE
- Tests
- EB_CNS/Source
- EB/CNS/Source
5 files changed
+595
-417
lines changed
0 commit comments