Open 3D Engine AzCore API Reference 25.05.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::DynamicModuleHandle Class Referenceabstract

#include <DynamicModuleHandle.h>

Public Types

enum class  LoadFlags : uint32_t { None = 0 , InitFuncRequired = 1 << 0 , GlobalSymbols = 1 << 1 , NoLoad = 1 << 2 }
 Flags used for loading a dynamic module. More...
 

Public Member Functions

virtual ~DynamicModuleHandle ()=default
 Platform-specific implementation should call Unload().
 
 DynamicModuleHandle (const DynamicModuleHandle &)=delete
 
DynamicModuleHandleoperator= (const DynamicModuleHandle &)=delete
 
bool Load (bool isInitializeFunctionRequired, bool globalSymbols=false)
 
bool Load (LoadFlags flags=LoadFlags::None)
 
bool Unload ()
 
virtual bool IsLoaded () const =0
 
const charGetFilename () const
 
template<typename Function >
Function GetFunction (const char *functionName) const
 

Static Public Member Functions

static AZStd::unique_ptr< DynamicModuleHandleCreate (const char *fullFileName, bool correctModuleName=true)
 

Protected Types

enum class  LoadStatus { LoadSuccess , LoadFailure , AlreadyLoaded }
 

Protected Member Functions

 DynamicModuleHandle (const char *fileFullName)
 
template<typename T >
constexpr bool CheckBitsAny (T v, T bits)
 
virtual LoadStatus LoadModule (LoadFlags flags)=0
 
virtual bool UnloadModule ()=0
 
virtual voidGetFunctionAddress (const char *functionName) const =0
 

Protected Attributes

AZ::IO::FixedMaxPathString m_fileName
 Store the module name for future loads.
 
AZ::EnvironmentVariable< boolm_initialized
 

Detailed Description

Handles platform-specific interaction with dynamic modules (aka DLLs, aka dynamic link libraries, aka shared libraries).

Member Enumeration Documentation

◆ LoadFlags

Flags used for loading a dynamic module.

Enumerator
GlobalSymbols 

Whether a missing InitializeDynamicModuleFunction causes the Load to fail.

NoLoad 

On platforms that support it, make the module's symbols global and available for the relocation processing of other modules. Otherwise, the symbols need to be queried manually.

Member Function Documentation

◆ Create()

static AZStd::unique_ptr< DynamicModuleHandle > AZ::DynamicModuleHandle::Create ( const char fullFileName,
bool  correctModuleName = true 
)
static

Creates a platform-specific DynamicModuleHandle.

Parameters
fullFileNameThe file name of the dynamic module to load
correctModuleNameOption to correct the filename to conform to the current platform's dynamic module naming convention. (i.e. lib<ModuleName>.so on unix-like platforms)

Note that the specified module is not loaded until Load is called.

Returns
Unique ptr to the newly created dynamic module handler.

◆ GetFilename()

const char * AZ::DynamicModuleHandle::GetFilename ( ) const
inline
Returns
the module's name on disk.

◆ GetFunction()

template<typename Function >
Function AZ::DynamicModuleHandle::GetFunction ( const char functionName) const
inline

Returns a function from the module. nullptr is returned if the function is inaccessible or the module is not loaded.

◆ IsLoaded()

virtual bool AZ::DynamicModuleHandle::IsLoaded ( ) const
pure virtual
Returns
whether the module has been successfully loaded.

◆ Load() [1/2]

bool AZ::DynamicModuleHandle::Load ( bool  isInitializeFunctionRequired,
bool  globalSymbols = false 
)

Loads the module. Invokes the InitializeDynamicModuleFunction if it is found in the module and this is the first time loading the module.

Parameters
isInitializeFunctionRequiredWhether a missing InitializeDynamicModuleFunction causes the Load to fail.
globalSymbolsOn platforms that support it, make the module's symbols global and available for the relocation processing of other modules. Otherwise, the symbols need to be queried manually.
Returns
True if the module loaded successfully.

◆ Load() [2/2]

bool AZ::DynamicModuleHandle::Load ( LoadFlags  flags = LoadFlags::None)

Loads the module. Invokes the InitializeDynamicModuleFunction if it is found in the module and this is the first time loading the module.

Parameters
flagsFlags to control the loading of the module. LoadFlags
Returns
True if the module loaded successfully.

◆ Unload()

bool AZ::DynamicModuleHandle::Unload ( )

Unload the module. Invokes the UninitializeDynamicModuleFunction if it is found in the module and this was the first handle to load the module.

Returns
true if the module unloaded successfully.

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