3#include "../FoundationBase.h"
25 enum class LoadStatus {
31 LoadStatus status = LoadStatus::Unloaded;
32 void* handle =
nullptr;
35 virtual void initPtrs() {}
37 static void load(
const std::string & path, LoadStatus & status,
void*& handle );
38 static void unload(
void* handle);
46 template<
typename T = Module>
47 static T
load(
const std::string & path ) {
50 load( path, instance.status, instance.handle );
52 if( instance.status == LoadStatus::Loaded ) {
59 void getProcAddress( T & ptr,
const char* procName ) {
60 ptr =
reinterpret_cast< T
>( getProcAddress( procName ) );
63 void* getProcAddress(
const char* procName );
64 static void* getProcAddress(
void* handle,
const char* procName );
66 bool operator ==(
const Module & rhs )
const {
return ( status == rhs.status ) && ( handle == rhs.handle ); }
69 template<
typename RET,
typename FN,
typename... ARGS>
70 RET Call(FN* fn, ARGS... args)
const {
72 return (*fn)(args...);
118 status = LoadStatus::Loaded;
120 api =
static_cast<const API*
>(apiPtr);
123 ModuleAPI(
const std::string& moduleName) {
124 *
this = load<ModuleAPI>(moduleName);
128 return const_cast<API*
>(api);
131 virtual void initPtrs()
override {
132 const void* (*fn)() =
reinterpret_cast<const void* (*)()
>(getProcAddress(handle,
"getPublicAPI"));
135 api =
static_cast<const API*
>(fn());
140 const API* api =
nullptr;
Helper class for shared libraries that implement the getPublicAPI function and provide a structure of...
Base class for managing libraries dynamically loaded at runtime.
static T load(const std::string &path)
Loads the named shared library.
Contains all Cogs related functionality.