Example base class used to demonstrate dynamic factory loading.
More...
#include <Car.h>
|
| | ~Car () override=default |
| | Virtual destructor for polymorphic deletion.
|
| |
| | Car (const std::shared_ptr< GOptions > &g) |
| | Construct the base with a shared options/configuration instance.
|
| |
| virtual void | go ()=0 |
| | Example pure-virtual behavior implemented by each plugin.
|
| |
| void | set_loggers (const std::shared_ptr< GOptions > &g) |
| | Wire loggers into the object.
|
| |
| | GBase (const std::shared_ptr< GOptions > &gopt, std::string logger_name="") |
| |
| | GBase (const std::shared_ptr< GLogger > &logger) |
| |
| | GBase (const GBase &)=default |
| |
| | GBase (GBase &&) noexcept=default |
| |
| virtual | ~GBase () |
| |
| GBase & | operator= (const GBase &)=default |
| |
| GBase & | operator= (GBase &&) noexcept=default |
| |
|
| double | generalCarVar = 44 |
| | Example data member shared by all derived cars.
|
| |
This type is intentionally small and serves as a reference pattern for:
- a plugin base class deriving from
GBase, and
- a static instantiate() helper that resolves an extern "C" factory symbol from a
dlopen handle and returns a newly allocated instance.
- Note
- In real modules, the base class typically defines the stable ABI/API that plugins implement.
Definition at line 21 of file Car.h.
◆ ~Car()
◆ Car()
| Car::Car |
( |
const std::shared_ptr< GOptions > & | g | ) |
|
|
inlineexplicit |
- Parameters
-
| g | Shared options object used to initialize logging via GBase. |
Definition at line 32 of file Car.h.
◆ go()
In the example program, this is invoked through a std::shared_ptr<Car> returned by the dynamic loader.
Implemented in Ford, and Tesla.
◆ instantiate()
This helper performs the dynamic lookup of the extern "C" factory function from the shared library. The derived plugin library must export a symbol with the exact name:
The expected signature is:
extern "C" Car* CarFactory(const std::shared_ptr<GOptions>&);
- Parameters
-
| h | POSIX dynamic-library handle (from dlopen). |
| g | Options/configuration to pass into the derived constructor. |
- Returns
- A raw pointer to a newly allocated derived
Car, or null on failure.
- Warning
- Ownership of the returned pointer is with the caller. In this module, the pointer is immediately wrapped in
std::shared_ptr<Car> by the manager.
Definition at line 81 of file Car.h.
◆ set_loggers()
| void Car::set_loggers |
( |
const std::shared_ptr< GOptions > & | g | ) |
|
|
inline |
◆ generalCarVar
| double Car::generalCarVar = 44 |
Used by the example to show that base-class state is accessible through the loaded object.
Definition at line 57 of file Car.h.
The documentation for this class was generated from the following file: