libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
ComponentList.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <memory>
5#include <vector>
6#include <algorithm>
7#include <mutex>
8
10
11namespace Ship {
12
13class Component;
14
22 None,
23 Children,
24 Parents
25};
26
34template <typename StoredPtr> class BasicComponentList : public PartList<Component, StoredPtr> {
35 public:
39
40 BasicComponentList() = default;
41
42 explicit BasicComponentList(const size_t initialAllocation) : PartList<Component, StoredPtr>(initialAllocation) {
43 }
44
51
57 bool Has(const std::string& name) const;
58
65 template <typename T> bool Has(const std::string& name) const;
66
72 std::shared_ptr<std::vector<std::shared_ptr<Component>>> Get(const std::string& name) const;
73
80 template <typename T> std::shared_ptr<std::vector<std::shared_ptr<T>>> Get(const std::string& name) const;
81
87 std::shared_ptr<std::vector<std::shared_ptr<Component>>> Get(const std::vector<std::string>& names) const;
88
89 protected:
95 void Added(std::shared_ptr<Component> part, const bool forced) override;
96
102 void Removed(std::shared_ptr<Component> part, const bool forced) override;
103
104 private:
105 Component* mOwner = nullptr;
107};
108
113
114} // namespace Ship
Extends PartList<Component, StoredPtr> with name- and type-based search helpers.
Definition ComponentList.h:34
BasicComponentList(Component *owner, ComponentListRole role)
Constructs a list with relationship role metadata.
void Removed(std::shared_ptr< Component > part, const bool forced) override
Synchronization hook called after a component is removed.
void Added(std::shared_ptr< Component > part, const bool forced) override
Synchronization hook called after a component is added.
std::shared_ptr< std::vector< std::shared_ptr< Component > > > Get(const std::vector< std::string > &names) const
Returns all components whose names are in the provided set.
bool Has(const std::string &name) const
Checks whether any component with the given name exists.
std::shared_ptr< std::vector< std::shared_ptr< Component > > > Get(const std::string &name) const
Returns all components with the given name.
BasicComponentList(const size_t initialAllocation)
Definition ComponentList.h:42
A named Part with a parent/child hierarchy and optional thread safety.
Definition Component.h:34
A thread-safe ordered list of Parts.
Definition PartList.h:114
bool Has() const
Checks whether any Part of type T is in the list.
Definition PartList.h:777
std::shared_ptr< std::vector< std::shared_ptr< Component > > > Get() const
Returns a snapshot (copy) of all currently live Parts in the list.
Definition PartList.h:825
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
ComponentListRole
Describes the role of a ComponentList within a parent/child relationship.
Definition ComponentList.h:21
@ Children
This list holds children; adding updates the child's parent list.
@ None
No automatic relationship management.
@ Parents
This list holds parents; adding updates the parent's child list.