gfactory
Loading...
Searching...
No Matches
Car Class Referenceabstract

Example base class used to demonstrate dynamic factory loading. More...

#include <Car.h>

Public Member Functions

 ~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.
 
- Public Member Functions inherited from GBase< Car >
 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 ()
 
GBaseoperator= (const GBase &)=default
 
GBaseoperator= (GBase &&) noexcept=default
 

Static Public Member Functions

static Carinstantiate (const dlhandle h, std::shared_ptr< GOptions > g)
 Resolve the plugin factory symbol and instantiate a derived Car.
 

Data Fields

double generalCarVar = 44
 Example data member shared by all derived cars.
 

Additional Inherited Members

- Protected Attributes inherited from GBase< Car >
std::shared_ptr< GLoggerlog
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~Car()

Car::~Car ( )
overridedefault

◆ Car()

Car::Car ( const std::shared_ptr< GOptions > & g)
inlineexplicit
Parameters
gShared options object used to initialize logging via GBase.

Definition at line 32 of file Car.h.

Member Function Documentation

◆ go()

virtual void Car::go ( )
pure virtual

In the example program, this is invoked through a std::shared_ptr<Car> returned by the dynamic loader.

Implemented in Ford, and Tesla.

◆ instantiate()

static Car * Car::instantiate ( const dlhandle h,
std::shared_ptr< GOptions > g )
inlinestatic

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:

  • CarFactory

The expected signature is:

  • extern "C" Car* CarFactory(const std::shared_ptr<GOptions>&);
Parameters
hPOSIX dynamic-library handle (from dlopen).
gOptions/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

This is called by LoadAndRegisterObjectFromLibrary() after instantiation. For the example, it is a no-op.

Definition at line 49 of file Car.h.

Field Documentation

◆ 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: