Cogs.Core
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Cogs::Core::Services Class Reference

Service registry. More...

#include <Services.h>

Public Member Functions

 Services (Context *context)
 
void clear ()
 
template<typename Service , typename... Args>
Service * registerService (Args... args)
 Registers a service of the given type.
 
template<typename Service >
void registerServiceReference (Service *s)
 Registers an externally managed service instance.
 
template<typename Service >
Service * getService ()
 
void addFrameCallback (std::function< void(void)> callback)
 
void dispatchFrameCallbacks ()
 

Private Member Functions

bool ensureUniqueService (Reflection::TypeId typeId)
 
void * locateService (Reflection::TypeId typeId)
 

Private Attributes

std::vector< RegisteredServiceservices
 
std::vector< std::function< void(void)> > callbacks
 
Contextcontext
 

Detailed Description

Service registry.

Provides creation, storage and retrieval of engine services.

Definition at line 31 of file Services.h.

Constructor & Destructor Documentation

◆ Services()

Cogs::Core::Services::Services ( Context context)

Definition at line 10 of file Services.cpp.

◆ ~Services()

Cogs::Core::Services::~Services ( )

Definition at line 16 of file Services.cpp.

Member Function Documentation

◆ addFrameCallback()

void Cogs::Core::Services::addFrameCallback ( std::function< void(void)>  callback)

Definition at line 34 of file Services.cpp.

◆ clear()

void Cogs::Core::Services::clear ( )

Definition at line 21 of file Services.cpp.

◆ dispatchFrameCallbacks()

void Cogs::Core::Services::dispatchFrameCallbacks ( )

Definition at line 39 of file Services.cpp.

◆ ensureUniqueService()

bool Cogs::Core::Services::ensureUniqueService ( Reflection::TypeId  typeId)
private

Definition at line 46 of file Services.cpp.

◆ getService()

template<typename Service >
Service * Cogs::Core::Services::getService ( )
inline

Definition at line 94 of file Services.h.

◆ locateService()

void * Cogs::Core::Services::locateService ( Reflection::TypeId  typeId)
private

Definition at line 57 of file Services.cpp.

◆ registerService()

template<typename Service , typename... Args>
Service * Cogs::Core::Services::registerService ( Args...  args)
inline

Registers a service of the given type.

An instance of the Service class is automatically created, and returned from subsequent calls to getService<Service>().

Template Parameters
ServiceType of service to register. Must be registered with the type system.
ArgsTypes of the arguments to pass to the constructor.
Parameters
argsArguments to pass to the instance constructor.
Returns
A pointer to the newly created instance.

Definition at line 53 of file Services.h.

References Cogs::Core::Context::memory.

◆ registerServiceReference()

template<typename Service >
void Cogs::Core::Services::registerServiceReference ( Service *  s)
inline

Registers an externally managed service instance.

Definition at line 78 of file Services.h.

Member Data Documentation

◆ callbacks

std::vector<std::function<void(void)> > Cogs::Core::Services::callbacks
private

Definition at line 109 of file Services.h.

◆ context

Context* Cogs::Core::Services::context
private

Definition at line 111 of file Services.h.

◆ services

std::vector<RegisteredService> Cogs::Core::Services::services
private

Definition at line 108 of file Services.h.


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