libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::Part Class Reference

Base class for all identifiable objects in the component system. More...

#include <Part.h>

Inheritance diagram for Ship::Part:
[legend]

Public Member Functions

 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

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.
 

Friends

template<typename , typename >
class PartList
 

Detailed Description

Base class for all identifiable objects in the component system.

Every Part is automatically assigned a unique, monotonically increasing ID at construction time. IDs are never reused during the lifetime of the process.

Every Part also stores a weak reference to the Context it belongs to. This reference is set when the Part is added to the component hierarchy and propagated to child components by ComponentList.

Constructor & Destructor Documentation

◆ Part() [1/2]

Ship::Part::Part ( )

Constructs a Part and assigns it a unique ID.

◆ Part() [2/2]

Ship::Part::Part ( std::shared_ptr< Context context)
explicit

Constructs a Part with an explicit Context reference and unique ID.

◆ ~Part()

virtual Ship::Part::~Part ( )
virtualdefault

Member Function Documentation

◆ GetContext()

std::shared_ptr< Context > Ship::Part::GetContext ( ) const

Returns the Context this Part belongs to, or nullptr if unset.

The context is propagated automatically by ComponentList when this Part is added to a hierarchy. Components should cache their dependencies from this Context (or from constructor parameters) rather than using the Context singleton.

◆ GetId()

uint64_t Ship::Part::GetId ( ) const

Returns the unique identifier for this Part.

◆ OnAdded()

virtual void Ship::Part::OnAdded ( bool  forced)
protectedvirtual

Called after this Part has been added to a PartList.

Override in subclasses to react to being added (e.g. caching siblings). The default implementation is a no-op.

Parameters
forcedWhether the addition bypassed permission checks.

◆ OnRemoved()

virtual void Ship::Part::OnRemoved ( bool  forced)
protectedvirtual

Called after this Part has been removed from a PartList.

Override in subclasses to react to being removed (e.g. clearing caches). The default implementation is a no-op.

Parameters
forcedWhether the removal bypassed permission checks.

◆ operator==()

bool Ship::Part::operator== ( const Part other) const

Compares two Parts for equality by their unique IDs.

Parameters
otherThe Part to compare against.
Returns
True if both Parts share the same ID.

◆ SetContext()

void Ship::Part::SetContext ( std::shared_ptr< Context ctx)

Sets the Context this Part belongs to.

Called by ComponentList when a Part is added to the hierarchy. Not normally called directly by application code.

Parameters
ctxThe Context to associate with this Part.

Friends And Related Symbol Documentation

◆ PartList

template<typename , typename >
friend class PartList
friend

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