|
Cogs.Core
|
Helper class for shared libraries that implement the getPublicAPI function and provide a structure of function pointers that contain the module's public API. More...
#include <Module.h>
Public Member Functions | |
| ModuleAPI (void *h, const void *apiPtr) | |
| ModuleAPI (const std::string &moduleName) | |
| API * | operator-> () |
| virtual void | initPtrs () override |
Public Member Functions inherited from Cogs::Module | |
| virtual void | initPtrs () |
| template<typename T > | |
| void | getProcAddress (T &ptr, const char *procName) |
| void * | getProcAddress (const char *procName) |
| Retrieves a pointer to the named function. | |
| bool | operator== (const Module &rhs) const |
Private Attributes | |
| const API * | api = nullptr |
Additional Inherited Members | |
Public Types inherited from Cogs::Module | |
| enum class | LoadStatus { Unloaded , Loaded , Failed } |
Static Public Member Functions inherited from Cogs::Module | |
| static void | load (const std::string &path, LoadStatus &status, void *&handle) |
| Attempts to load a shared library with the given name. | |
| static void | unload (void *handle) |
| template<typename T = Module> | |
| static T | load (const std::string &path) |
| Loads the named shared library. | |
| static void * | getProcAddress (void *handle, const char *procName) |
| Retrives the address of the named function within the shared library identified by the specified handle. | |
Public Attributes inherited from Cogs::Module | |
| LoadStatus | status = LoadStatus::Unloaded |
| void * | handle = nullptr |
Protected Member Functions inherited from Cogs::Module | |
| template<typename RET , typename FN , typename... ARGS> | |
| RET | Call (FN *fn, ARGS... args) const |
Helper class for shared libraries that implement the getPublicAPI function and provide a structure of function pointers that contain the module's public API.
For any shared library that implements a public function called getPublicAPI that returns a pointer to a struct of function pointers like this:
struct PublicAPI { using SomePublicFn = void();
SomePublicFn* somePublicFn = nullptr;
PublicAPI(); // Initialises member pointers to real function addresses. };
MYLIBRARY_API const void* getPublicAPI(); // Declare static instance of PublicAPI and return address.
An application just needs to implement the following class that encapsulates the module innards to be able to call those functions in a shared library:
class MyModule : public Cogs::Application::ModuleAPI<PublicAPI> { public: MyModule() : ModuleAPI("MySharedLibrary") {}
static MyModule& instance() { static MyModule i; return i; } };
And then it can simply call any defined function like this:
MyModule::instance()->somePublicFn(); *============================================================================================
|
inline |
|
inline |
|
inlineoverridevirtual |
Reimplemented from Cogs::Module.
|
inline |
|
private |