libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::BasicComponentList< StoredPtr > Class Template Reference

Extends PartList<Component, StoredPtr> with name- and type-based search helpers. More...

#include <ComponentList.h>

Inheritance diagram for Ship::BasicComponentList< StoredPtr >:
[legend]
Collaboration diagram for Ship::BasicComponentList< StoredPtr >:
[legend]

Public Types

using PartListBase = PartList< Component, StoredPtr >
 

Public Member Functions

 BasicComponentList ()=default
 
 BasicComponentList (const size_t initialAllocation)
 
 BasicComponentList (Component *owner, ComponentListRole role)
 Constructs a list with relationship role metadata.
 
bool Has (const std::string &name) const
 Checks whether any component with the given name exists.
 
template<typename T >
bool Has (const std::string &name) const
 Checks whether any component with the given name matches type T.
 
std::shared_ptr< std::vector< std::shared_ptr< Component > > > Get (const std::string &name) const
 Returns all components with the given name.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > Get (const std::string &name) const
 Returns all components of type T with the given name.
 
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.
 
- Public Member Functions inherited from Ship::PartList< Component, StoredPtr >
 PartList (const size_t initialAllocation=0)
 Constructs a PartList, optionally pre-allocating storage.
 
virtual ~PartList ()=default
 
bool Has (std::shared_ptr< Component > part) const
 Checks whether a specific Part is in the list.
 
bool Has () const
 Checks whether any Part of type T is in the list.
 
bool Has (const uint64_t id) const
 Checks whether a Part with the given ID is in the list.
 
bool Has () const
 Checks whether the list contains any Parts at all.
 
size_t GetCount () const
 Returns the number of currently live Parts in the list.
 
uint64_t GetMutationVersion () const
 Returns a monotonically increasing counter that increments on every add or remove.
 
std::shared_ptr< ComponentGet (const uint64_t id) const
 Retrieves a Part by its unique ID.
 
std::shared_ptr< std::vector< std::shared_ptr< Component > > > Get () const
 Returns a snapshot (copy) of all currently live Parts in the list.
 
std::shared_ptr< std::vector< std::shared_ptr< T > > > Get () const
 Returns all Parts that can be dynamic_cast to type T.
 
std::shared_ptr< std::vector< std::shared_ptr< Component > > > Get (const std::vector< uint64_t > &ids) const
 Returns all Parts whose IDs appear in the given vector.
 
std::shared_ptr< T > GetFirst () const
 Returns the first Part that can be dynamic_cast to T.
 
ListReturnCode Add (std::shared_ptr< Component > part, const bool force=false)
 Adds a Part to the list if not already present.
 
ListReturnCode Add (const std::vector< std::shared_ptr< Component > > &parts, const bool force=false)
 Adds multiple Parts to the list.
 
ListReturnCode Remove (std::shared_ptr< Component > part, const bool force=false)
 Removes a specific Part from the list.
 
ListReturnCode Remove (const uint64_t id, const bool force=false)
 Removes a Part by its unique ID.
 
ListReturnCode Remove (const bool force=false)
 Removes all Parts from the list.
 
ListReturnCode Remove (const std::vector< std::shared_ptr< Component > > &parts, const bool force=false)
 Removes multiple Parts from the list.
 
ListReturnCode Remove (const bool force=false)
 Removes all Parts that can be dynamic_cast to type T.
 
ListReturnCode Remove (const std::vector< uint64_t > &ids, const bool force=false)
 Removes all Parts whose IDs appear in the given vector.
 
- Public Member Functions inherited from Ship::Part
 Part ()
 Constructs a Part and assigns it a unique ID.
 
 Part (std::shared_ptr< Context > context)
 Constructs a Part with an explicit Context reference and unique ID.
 
virtual ~Part ()=default
 
uint64_t GetId () const
 Returns the unique identifier for this Part.
 
bool operator== (const Part &other) const
 Compares two Parts for equality by their unique IDs.
 
std::shared_ptr< ContextGetContext () const
 Returns the Context this Part belongs to, or nullptr if unset.
 
void SetContext (std::shared_ptr< Context > ctx)
 Sets the Context this Part belongs to.
 

Protected Member Functions

void Added (std::shared_ptr< Component > part, const bool forced) override
 Synchronization hook called after a component is added.
 
void Removed (std::shared_ptr< Component > part, const bool forced) override
 Synchronization hook called after a component is removed.
 
- Protected Member Functions inherited from Ship::PartList< Component, StoredPtr >
std::enable_if< std::is_same< P, std::shared_ptr< Component > >::value, std::vector< P > & >::type GetList ()
 Direct access to the underlying vector for strong-storage lists.
 
std::enable_if< std::is_same< P, std::shared_ptr< Component > >::value, conststd::vector< P > & >::type GetList () const
 Direct const access to the underlying vector for strong-storage lists.
 
std::recursive_mutex & GetMutex () const
 Returns the internal recursive mutex used to guard list access.
 
virtual bool CanAdd (std::shared_ptr< Component > part)
 Permission hook called before adding a Part. Override to deny.
 
virtual bool CanRemove (std::shared_ptr< Component > part)
 Permission hook called before removing a Part. Override to deny.
 
- Protected Member Functions inherited from Ship::Part
virtual void OnAdded (bool forced)
 Called after this Part has been added to a PartList.
 
virtual void OnRemoved (bool forced)
 Called after this Part has been removed from a PartList.
 

Detailed Description

template<typename StoredPtr>
class Ship::BasicComponentList< StoredPtr >

Extends PartList<Component, StoredPtr> with name- and type-based search helpers.

Template Parameters
StoredPtrBacking pointer storage type (std::shared_ptr<Component> for owning child lists, std::weak_ptr<Component> for non-owning parent lists).

Member Typedef Documentation

◆ PartListBase

template<typename StoredPtr >
using Ship::BasicComponentList< StoredPtr >::PartListBase = PartList<Component, StoredPtr>

Constructor & Destructor Documentation

◆ BasicComponentList() [1/3]

template<typename StoredPtr >
Ship::BasicComponentList< StoredPtr >::BasicComponentList ( )
default

◆ BasicComponentList() [2/3]

template<typename StoredPtr >
Ship::BasicComponentList< StoredPtr >::BasicComponentList ( const size_t  initialAllocation)
inlineexplicit

◆ BasicComponentList() [3/3]

template<typename StoredPtr >
Ship::BasicComponentList< StoredPtr >::BasicComponentList ( Component owner,
ComponentListRole  role 
)

Constructs a list with relationship role metadata.

Parameters
ownerThe owning component of this list.
roleRole of this list in relationship synchronization.

Member Function Documentation

◆ Added()

template<typename StoredPtr >
void Ship::BasicComponentList< StoredPtr >::Added ( std::shared_ptr< Component part,
const bool  forced 
)
overrideprotectedvirtual

Synchronization hook called after a component is added.

Maintains bidirectional parent/child links and tickable registration.

Reimplemented from Ship::PartList< Component, StoredPtr >.

◆ Get() [1/3]

template<typename StoredPtr >
std::shared_ptr< std::vector< std::shared_ptr< Component > > > Ship::BasicComponentList< StoredPtr >::Get ( const std::string &  name) const

Returns all components with the given name.

Parameters
nameName to search for.
Returns
Matching live components.

◆ Get() [2/3]

template<typename StoredPtr >
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > Ship::BasicComponentList< StoredPtr >::Get ( const std::string &  name) const

Returns all components of type T with the given name.

Template Parameters
TTarget type tested via dynamic_cast.
Parameters
nameName to search for.
Returns
Matching typed components.

◆ Get() [3/3]

template<typename StoredPtr >
std::shared_ptr< std::vector< std::shared_ptr< Component > > > Ship::BasicComponentList< StoredPtr >::Get ( const std::vector< std::string > &  names) const

Returns all components whose names are in the provided set.

Parameters
namesNames to match.
Returns
Matching live components.

◆ Has() [1/2]

template<typename StoredPtr >
bool Ship::BasicComponentList< StoredPtr >::Has ( const std::string &  name) const

Checks whether any component with the given name exists.

Parameters
nameName to search for.
Returns
True if any live entry has this name.

◆ Has() [2/2]

template<typename StoredPtr >
template<typename T >
bool Ship::BasicComponentList< StoredPtr >::Has ( const std::string &  name) const

Checks whether any component with the given name matches type T.

Template Parameters
TTarget type tested via dynamic_cast.
Parameters
nameName to search for.
Returns
True if a typed component with matching name exists.

◆ Removed()

template<typename StoredPtr >
void Ship::BasicComponentList< StoredPtr >::Removed ( std::shared_ptr< Component part,
const bool  forced 
)
overrideprotectedvirtual

Synchronization hook called after a component is removed.

Maintains bidirectional parent/child links and tickable unregistration.

Reimplemented from Ship::PartList< Component, StoredPtr >.


The documentation for this class was generated from the following files: