CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Component< T >::Accessor Struct Reference

An accessor class that implements high-level access to an entity that has the given component. More...

#include <CeresEngine/Entity/Component.hpp>

Inheritance diagram for CeresEngine::Component< T >::Accessor:
CeresEngine::AudioListenerComponent::Accessor CeresEngine::AudioSourceComponent::Accessor CeresEngine::CameraComponent::Accessor CeresEngine::EnvironmentComponent::Accessor CeresEngine::Graphics::UI::UIComponent::Accessor CeresEngine::LightComponent::Accessor CeresEngine::Motion::Accessor CeresEngine::NetworkEntityComponent::Accessor CeresEngine::PhysicsWorldComponent::Accessor CeresEngine::RenderableComponent::Accessor CeresEngine::RigidBodyComponent::Accessor CeresEngine::ScriptComponent::Accessor CeresEngine::SoftBodyComponent::Accessor CeresEngine::TerrainRenderableComponent::Accessor CeresEngine::TransformComponent::Accessor

Public Member Functions

 Accessor (const Entity &entity)
 

Public Attributes

const Entityentity
 

Protected Types

using C = TC
 

Protected Member Functions

template<typename T >
auto mutate (T C::*ptr)
 Accesses an element from an existing Component.
 
template<typename MutatorFunc , typename T >
requires (CInvocable<MutatorFunc, T&>)
decltype(automutate (MutatorFunc &&func, T C::*ptr)
 Accesses an element from an existing Component.
 
template<typename T1 , typename T2 , typename... Ts>
Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > mutate (T1 C::*ptr1, T2 C::*ptr2, Ts C::*... ptrs)
 TODO Write docs.
 
template<typename MutatorFunc , typename T1 , typename T2 , typename... Ts>
Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > mutate (MutatorFunc &&func, T1 C::*ptr1, T2 C::*ptr2, Ts C::*... ptr)
 
template<typename T >
auto get (T C::*ptr)
 Accesses an element from an existing Component.
 
template<typename T1 , typename T2 , typename... Ts>
Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > get (T1 C::*ptr1, T2 C::*ptr2, Ts C::*... ptrs)
 Accesses an element from an existing Component.
 
template<typename T >
const Tread (const T C::*ptr) const
 Accesses an element from an existing Component.
 
template<typename T1 , typename T2 , typename... Ts>
Tuple< const T1 &, const T2 &, const Ts &... > read (const T1 C::*ptr1, const T2 C::*ptr2, const Ts C::*... ptrs) const
 TODO Write docs.
 
template<typename T >
const Tget (const T C::*ptr) const
 Accesses an element from an existing Component.
 
template<typename T1 , typename T2 , typename... Ts>
Tuple< const T1 &, const T2 &, const Ts &... > get (const T1 C::*ptr1, const T2 C::*ptr2, const Ts C::*... ptrs) const
 Accesses an element from an existing Component.
 

Detailed Description

template<typename T>
struct CeresEngine::Component< T >::Accessor

An accessor class that implements high-level access to an entity that has the given component.

All components are encouraged to offer a TC::Accessor implementation that derives from this class that allows higher-level access to an entity.

Implementations can use the read() and mutate() methods to access data in the component. The C type is a type-alias to the component class the accessor is implemented for.

  • Use read() to access a value from a component. You can give it one or more pointers-to-member of the component type C. Data will be retrieved from the component and returned to you by const-reference.
  • Use mutate() to change a value from a component. You can give it one or more pointers-to-member of the component type C. Data will be retrieved from the component and returned to you by reference. mutate() automatically marks the entity as dirty.
  • Alternatively, you can use get() that will automatically deduce either read() if this is const or mutate() if it is non-const.

To use a custom Accessor you must use EntityObject or some of it's sub-classes.

struct MyComponent : public Component<MyComponent> {
struct Accessor;
String name;
};
struct MyComponent::Accessor : Component<MyComponent>::Accessor {
using Component<MyComponent>::Accessor::Accessor;
const String& getFullyQualifiedName() const { return read(&C::name); }
void setName(String newName) {
if(newName.empty()) throw std::invalid_argument("newName");
if(newName == read(&C::name)) return;
mutate(&C::name) = std::move(newName);
}
};
EntityManager& entityManager = ...;
MyObject object = entityManager.create<MyObject>();
object->setName("Testing");
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
An accessor class that implements high-level access to an entity that has the given component.
Definition Component.hpp:175
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
Template Parameters
TCThe component implementation type.

Member Typedef Documentation

◆ C

template<typename T >
using CeresEngine::Component< T >::Accessor::C = TC
protected

Constructor & Destructor Documentation

◆ Accessor()

template<typename T >
CeresEngine::Component< T >::Accessor::Accessor ( const Entity entity)
inlineexplicit

Member Function Documentation

◆ get() [1/4]

template<typename T >
template<typename T >
const T & CeresEngine::Component< T >::Accessor::get ( const T C::*  ptr) const
protected

Accesses an element from an existing Component.

If the component does not exists, it is undefined behavior.

Template Parameters
Tthe component member type
Parameters
ptrThe component element pointer to member
Returns
A reference to the component element

◆ get() [2/4]

template<typename T >
template<typename T1 , typename T2 , typename... Ts>
Tuple< const T1 &, const T2 &, const Ts &... > CeresEngine::Component< T >::Accessor::get ( const T1 C::*  ptr1,
const T2 C::*  ptr2,
const Ts C::*...  ptrs 
) const
protected

Accesses an element from an existing Component.

If the component does not exists, it is undefined behavior.

Template Parameters
Tthe component member type
Parameters
ptrThe component element pointer to member
Returns
A reference to the component element

◆ get() [3/4]

template<typename T >
template<typename T >
auto CeresEngine::Component< T >::Accessor::get ( T C::*  ptr)
protected

Accesses an element from an existing Component.

If the component does not exists, it is undefined behavior.

Template Parameters
Tthe component member type
Parameters
ptrThe component element pointer to member
Returns
A reference to the component element

◆ get() [4/4]

template<typename T >
template<typename T1 , typename T2 , typename... Ts>
Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > CeresEngine::Component< T >::Accessor::get ( T1 C::*  ptr1,
T2 C::*  ptr2,
Ts C::*...  ptrs 
)
protected

Accesses an element from an existing Component.

If the component does not exists, it is undefined behavior.

Template Parameters
Tthe component member type
Parameters
ptrThe component element pointer to member
Returns
A reference to the component element

◆ mutate() [1/4]

template<typename T >
template<typename MutatorFunc , typename T >
requires (CInvocable<MutatorFunc, T&>)
decltype(auto) CeresEngine::Component< T >::Accessor::mutate ( MutatorFunc &&  func,
T C::*  ptr 
)
protected

Accesses an element from an existing Component.

If the component does not exists, it is undefined behavior.

Template Parameters
TThe component member type
Parameters
ptrThe component element pointer to member
funcThe function to be called with a reference to the property.
Returns
A reference to the component element

◆ mutate() [2/4]

template<typename T >
template<typename MutatorFunc , typename T1 , typename T2 , typename... Ts>
Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > CeresEngine::Component< T >::Accessor::mutate ( MutatorFunc &&  func,
T1 C::*  ptr1,
T2 C::*  ptr2,
Ts C::*...  ptr 
)
protected

◆ mutate() [3/4]

template<typename T >
template<typename T >
auto CeresEngine::Component< T >::Accessor::mutate ( T C::*  ptr)
protected

Accesses an element from an existing Component.

If the component does not exists, it is undefined behavior.

Template Parameters
Tthe component member type
Parameters
ptrThe component element pointer to member
Returns
A reference to the component element

◆ mutate() [4/4]

template<typename T >
template<typename T1 , typename T2 , typename... Ts>
Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > CeresEngine::Component< T >::Accessor::mutate ( T1 C::*  ptr1,
T2 C::*  ptr2,
Ts C::*...  ptrs 
)
protected

TODO Write docs.

◆ read() [1/2]

template<typename T >
template<typename T >
const T & CeresEngine::Component< T >::Accessor::read ( const T C::*  ptr) const
protected

Accesses an element from an existing Component.

If the component does not exists, it is undefined behavior.

Template Parameters
Tthe component member type
Parameters
ptrThe component element pointer to member
Returns
A reference to the component element

◆ read() [2/2]

template<typename T >
template<typename T1 , typename T2 , typename... Ts>
Tuple< const T1 &, const T2 &, const Ts &... > CeresEngine::Component< T >::Accessor::read ( const T1 C::*  ptr1,
const T2 C::*  ptr2,
const Ts C::*...  ptrs 
) const
protected

TODO Write docs.

Member Data Documentation

◆ entity

template<typename T >
const Entity& CeresEngine::Component< T >::Accessor::entity

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