Skip to content

Commit

Permalink
Merge branch 'develop' into brryan/param_whitespace_sanitize
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurlungur authored Oct 20, 2023
2 parents 2e72486 + ae0632a commit 600fead
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
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 932]](https://github.com/parthenon-hpc-lab/parthenon/pull/932) Add GetOrAddFlag to metadata
- [[PR 931]](https://github.com/parthenon-hpc-lab/parthenon/pull/931) Allow SparsePacks with subsets of blocks
- [[PR 921]](https://github.com/parthenon-hpc-lab/parthenon/pull/921) Add more flexible ways of adding and using MeshData/MeshBlockData objects to DataCollections
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
5 changes: 4 additions & 1 deletion 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 Expand Up @@ -429,7 +432,7 @@ class StateDescriptor {

friend std::ostream &operator<<(std::ostream &os, const StateDescriptor &sd);

private:
protected:
void InvertControllerMap();

Params params_;
Expand Down

0 comments on commit 600fead

Please sign in to comment.