ASL
|
This class represents a dynamically loadable library (a DLL on Windows, a shared library on Linux).
It can be used to load functions at runtime, or to create objects of classes defined in the library. To create and use objects they need to be derived from known base class (acting as an interface declaration).
Make sure the object is alive while functions from it are used. Keep a (smart) pointer instead of a value object if needed.
Use ASL_EXPORT_CLASS
to export classes from a library so that they can be easily imported in applications with library.create("ClassName")
.
Exporting and importing classes needs a public header:
One implementation built into dynamic library cat.dll
:
Then another program at runtime can load the library and create an object of class Cat
. It only needs the public base class header ("Animal.h"), not the Cat
subclass.
The class can be exported with an alternative name, for example to have many plugins export classes with the same name so that clients don't need knowledge about what classes are exported.
#include <Library.h>
Public Member Functions | |
Library (const String &name) | |
Creates and opens a dynamic library. | |
void | open (String file, bool tryprefix=true) |
Opens a dynamic library. | |
void | close () |
Closes the library. | |
bool | loaded () const |
Returns true if the library was loaded correctly. | |
void * | get (const char *sym) |
Gets the address of the given symbol name in the library. | |
void * | create (const String &className) |
Creates an object of class 'className' exported in the library with the ASL_EXPORT_CLASS macro Returns a null pointer if that class is not exported. | |