Skip to content

Commit

Permalink
Merge branch 'bprather/pep1' into jdolence/meshblockdata_add
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Prather committed Aug 15, 2023
2 parents 4e51cc1 + 608721e commit 5692912
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Current develop

### Added (new features/APIs/variables/...)
- [[PR 907]](https://github.com/parthenon-hpc-lab/parthenon/pull/907) PEP1: Allow subclassing StateDescriptor
- [[PR 900]](https://github.com/parthenon-hpc-lab/parthenon/pull/900) Add Morton numbers and expand functionality of LogicalLocation
- [[PR 902]](https://github.com/parthenon-hpc-lab/parthenon/pull/902) Add ability to output NaNs for de-allocated sparse fields
- [[PR 887]](https://github.com/parthenon-hpc-lab/parthenon/pull/887) Add ability to dump more types of params and read them from restarts
Expand Down
35 changes: 34 additions & 1 deletion src/interface/packages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <memory>
#include <string>
#include <vector>

#include "basic_types.hpp"

Expand All @@ -26,15 +27,47 @@ class Packages_t {
Packages_t() = default;
void Add(const std::shared_ptr<StateDescriptor> &package);

std::shared_ptr<StateDescriptor> const &Get(const std::string &name) {
std::shared_ptr<StateDescriptor> const &Get(const std::string &name) const {
return packages_.at(name);
}

// Retrieve a package pointer, cast to a given type T
template <typename T>
T *Get(const std::string &name) const {
return static_cast<T *>(packages_.at(name).get());
}

const Dictionary<std::shared_ptr<StateDescriptor>> &AllPackages() const {
return packages_;
}
Dictionary<std::shared_ptr<StateDescriptor>> &AllPackages() { return packages_; }

// Returns a sub-Dictionary containing just pointers to packages of type T.
// Dictionary is a *new copy*, and members are bare pointers, not shared_ptr.
template <typename T>
const Dictionary<T *> AllPackagesOfType() const {
Dictionary<T *> sub_dict;
for (auto package : packages_) {
if (T *cast_package = dynamic_cast<T *>(package.second.get())) {
sub_dict[package.first] = cast_package;
}
}
return sub_dict;
}

// Returns a list of pointers to packages of type T.
// List contains bare pointers, not shared_ptr objects
template <typename T>
const std::vector<T *> ListPackagesOfType() const {
std::vector<T *> sub_list;
for (auto package : packages_) {
if (T *cast_package = dynamic_cast<T *>(package.second.get())) {
sub_list.append(cast_package);
}
}
return sub_list;
}

private:
Dictionary<std::shared_ptr<StateDescriptor>> packages_;
};
Expand Down
3 changes: 3 additions & 0 deletions src/interface/state_descriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class StateDescriptor {
}
}

// Virtual destructor for subclassing
virtual ~StateDescriptor() = default;

static std::shared_ptr<StateDescriptor>
CreateResolvedStateDescriptor(Packages_t &packages);

Expand Down

0 comments on commit 5692912

Please sign in to comment.