ASL
Loading...
Searching...
No Matches
Dynamically loadable libraries

Detailed Description

Class Library allows loading a dynamic/shared library at runtime and import symbols from it (usually functions).

It also allows importing classes exported from a library and instantiating objects with them.

A dynamic library can contain this:

class Cat : public Animal {...}; // implements virtual functions from class Animal
ASL_EXPORT_CLASS_AS(Cat, Animal)
#define ASL_EXPORT_CLASS_AS(Class, Name)
Export a class to be instantiated with dynamic runtime loading but giving a specific name for importi...
Definition Library.h:222

And a program can load it at runtime and instantiate the exported class Cat, with the name "Animal".

#include "Animal.h"
Library lib("plugins/cat"); // Loads "cat.dll" on Widows or "libcat.so" on Linux
Animal* cat = (Animal*) lib.create("Animal");
cat->speak();

The program does not need the declaration of class Cat, only that of the base class Animal.

See also
Factory

Classes

class  Library
 This class represents a dynamically loadable library (a DLL on Windows, a shared library on Linux). More...
 

Macros

#define ASL_LIB_EXT
 Extension of dynamic/shared libraries (OS-dependent: "dll", "so" or "dylib")
 
#define ASL_LIB_PREFIX
 Standard prefix of libraries (OS-dependent: "lib" on Unix)
 
#define ASL_EXPORT_CLASS(Class)
 Export a class to be instantiated with dynamic runtime loading with Library::create("className").
 
#define ASL_EXPORT_CLASS_AS(Class, Name)
 Export a class to be instantiated with dynamic runtime loading but giving a specific name for importing.
 

Macro Definition Documentation

◆ ASL_EXPORT_CLASS

#define ASL_EXPORT_CLASS (   Class)

Export a class to be instantiated with dynamic runtime loading with Library::create("className").

The argument must be an identifier (no "::") and it will be used when importing.

◆ ASL_EXPORT_CLASS_AS

#define ASL_EXPORT_CLASS_AS (   Class,
  Name 
)

Export a class to be instantiated with dynamic runtime loading but giving a specific name for importing.

The arguments must be identifiers (no "::") and the second will be used when importing.