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

Extension registry used to host and manage extension instances. More...

#include <ExtensionRegistry.h>

Public Types

enum class  ExtensionModuleLoadResult { Success , Failure , NoExtensionsFound }
 Defines possible results of an extension module load. More...
 

Static Public Member Functions

static void add (Extension *extension, StringView version)
 Adds the given extension to the registry, ensuring the initialization methods are called at appropriate times.
 
static bool hasExtension (const StringView &key, bool silent=false)
 Check if an extension with the given key is present in this build.
 
static void * getExtensionSymbol (const char *extension, const char *name)
 Retrieves the address of a symbol in the extension module.
 
static void initializeStatic ()
 Performs static initialization of all extensions registered with add().
 
static void initialize (Context *context)
 Performs initialization of all extensions registered with add().
 
static void cleanup (Context *context)
 Cleanup the given context.
 
static void remove (Context *context)
 Removes the given context.
 
static const void * loadExtensionModule (const std::string &path, void **modulehandle=nullptr, ExtensionModuleLoadResult *result=nullptr)
 Load the extension module with the given name.
 
template<typename API >
static ModuleAPI< API > loadExtensionModule (const std::string &path)
 Loads the extension module with the given name.
 
template<typename ComponentSystemType >
static ComponentSystemType * registerExtensionSystem (Context *context, SystemPriority::ESystemPriority systemPriority, uint32_t capacity)
 Registers an instance of the given component system type in the extension system registry.
 
template<typename ComponentSystemType >
static ComponentSystemType * getExtensionSystem (Context *context)
 Retrieve the extension component system of the given template type.
 

Static Private Member Functions

static std::vector< Extension * > & getExtensions ()
 Get the extension registry.
 
static std::deque< Extension * > & getDelayedExtensions ()
 

Static Private Attributes

static std::vector< Context * > contexts
 
static bool initialized = false
 
static bool locked = false
 

Detailed Description

Extension registry used to host and manage extension instances.

Definition at line 106 of file ExtensionRegistry.h.

Member Enumeration Documentation

◆ ExtensionModuleLoadResult

Defines possible results of an extension module load.

Enumerator
Success 

Module was loaded successfully and extensions loaded.

Failure 

Module failed loading.

NoExtensionsFound 

Module loaded, but no valid extensions were registered by the module. The module code has still been loaded into the process and may be accessed.

Definition at line 157 of file ExtensionRegistry.h.

Member Function Documentation

◆ add()

void Cogs::Core::ExtensionRegistry::add ( Extension extension,
StringView  version 
)
static

Adds the given extension to the registry, ensuring the initialization methods are called at appropriate times.

Parameters
extensionPointer to the extension to add.

Definition at line 34 of file ExtensionRegistry.cpp.

References Cogs::StringView::data(), Cogs::StringView::empty(), and getExtensions().

◆ cleanup()

void Cogs::Core::ExtensionRegistry::cleanup ( Context context)
static

Cleanup the given context.

Definition at line 115 of file ExtensionRegistry.cpp.

Referenced by Cogs::Core::Engine::~Engine().

◆ getDelayedExtensions()

std::deque< Cogs::Core::Extension * > & Cogs::Core::ExtensionRegistry::getDelayedExtensions ( )
staticprivate

Definition at line 213 of file ExtensionRegistry.cpp.

◆ getExtensions()

std::vector< Cogs::Core::Extension * > & Cogs::Core::ExtensionRegistry::getExtensions ( )
staticprivate

Get the extension registry.

Definition at line 206 of file ExtensionRegistry.cpp.

Referenced by add().

◆ getExtensionSymbol()

void * Cogs::Core::ExtensionRegistry::getExtensionSymbol ( const char *  extension,
const char *  name 
)
static

Retrieves the address of a symbol in the extension module.

Parameters
extensionExtension name.
symbolSymbol name.
Returns
Address of the symbol or nullptr.

Definition at line 81 of file ExtensionRegistry.cpp.

◆ getExtensionSystem()

template<typename ComponentSystemType >
static ComponentSystemType * Cogs::Core::ExtensionRegistry::getExtensionSystem ( Context context)
inlinestatic

Retrieve the extension component system of the given template type.

Template Parameters
ComponentSystemTypeType of the component system to retrieve.
Parameters
contextContext to retrieve the system from.
Returns
Pointer to the extension system instance of the given type.

Definition at line 227 of file ExtensionRegistry.h.

References Cogs::Core::Context::getExtensionSystem().

◆ hasExtension()

bool Cogs::Core::ExtensionRegistry::hasExtension ( const StringView key,
bool  silent = false 
)
static

Check if an extension with the given key is present in this build.

Parameters
keyPointer to a string containing the key to search for.
silentDo not log that an extension is missing.

Definition at line 64 of file ExtensionRegistry.cpp.

◆ initialize()

void Cogs::Core::ExtensionRegistry::initialize ( Context context)
static

Performs initialization of all extensions registered with add().

This method should be called once after creating a new context.

Definition at line 106 of file ExtensionRegistry.cpp.

Referenced by Cogs::Core::Context::initialize().

◆ initializeStatic()

void Cogs::Core::ExtensionRegistry::initializeStatic ( )
static

Performs static initialization of all extensions registered with add().

This method should only be called once per application run.

Definition at line 91 of file ExtensionRegistry.cpp.

Referenced by Cogs::Core::Context::initializeStatic().

◆ loadExtensionModule() [1/2]

template<typename API >
static ModuleAPI< API > Cogs::Core::ExtensionRegistry::loadExtensionModule ( const std::string &  path)
inlinestatic

Loads the extension module with the given name.

Parameters
pathPath to a dynamic library file to load.
Returns
A ModuleAPI with the API initialised ready for use. See the ModuleAPI definition for a better understanding of how this works.

Definition at line 188 of file ExtensionRegistry.h.

◆ loadExtensionModule() [2/2]

const void * Cogs::Core::ExtensionRegistry::loadExtensionModule ( const std::string &  path,
void **  modulehandle = nullptr,
ExtensionModuleLoadResult result = nullptr 
)
static

Load the extension module with the given name.

The name must point to a valid dynamic library.

Parameters
pathPath to a dynamic library file to load.
Returns
Result of the extension load.

Definition at line 127 of file ExtensionRegistry.cpp.

References Cogs::Core::Extension::initialize(), and Cogs::Core::Extension::initializeStatic().

◆ registerExtensionSystem()

template<typename ComponentSystemType >
static ComponentSystemType * Cogs::Core::ExtensionRegistry::registerExtensionSystem ( Context context,
SystemPriority::ESystemPriority  systemPriority,
uint32_t  capacity 
)
inlinestatic

Registers an instance of the given component system type in the extension system registry.

Template Parameters
ComponentSystemTypeType of system to create. Must provide specialized getExtensionKey() method.
Parameters
systemPriorityPriority to use when registering the system.
contextContext to register the system in.
capacityInitial system capacity.

Definition at line 208 of file ExtensionRegistry.h.

References Cogs::Core::Context::engine, and Cogs::Core::Context::registerExtensionSystem().

◆ remove()

void Cogs::Core::ExtensionRegistry::remove ( Context context)
static

Removes the given context.

Definition at line 122 of file ExtensionRegistry.cpp.

Referenced by Cogs::Core::Engine::~Engine().

Member Data Documentation

◆ contexts

std::vector< Cogs::Core::Context * > Cogs::Core::ExtensionRegistry::contexts
staticprivate

Definition at line 240 of file ExtensionRegistry.h.

◆ initialized

bool Cogs::Core::ExtensionRegistry::initialized = false
staticprivate

Definition at line 241 of file ExtensionRegistry.h.

◆ locked

bool Cogs::Core::ExtensionRegistry::locked = false
staticprivate

Definition at line 242 of file ExtensionRegistry.h.


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