gfactory
Car.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gdl.h"
4 
5 class Car {
6 public:
7  virtual void go() = 0;
8 
9  virtual ~Car() = default;
10 
11  void set_loggers([[ maybe_unused ]] GOptions* const g) {}
12 
13  double generalCarVar = 44;
14 
15  // method to dynamically load factories
16  static Car *instantiate(const dlhandle handle) {
17 
18  if (handle == nullptr) return nullptr;
19 
20  // must match the extern C declaration in the derived factories
21  void *maker = dlsym(handle, "CarFactory");
22 
23  if (maker == nullptr) return nullptr;
24 
25  typedef Car *(*fptr)();
26 
27  // static_cast not allowed here
28  // see http://stackoverflow.com/questions/573294/when-to-use-reinterpret-cast
29  // need to run the DLL CarFactory function that returns the factory
30  fptr func = reinterpret_cast<fptr>(reinterpret_cast<void *>(maker));
31 
32  return func();
33  }
34 };
35 
Definition: Car.h:5
static Car * instantiate(const dlhandle handle)
Definition: Car.h:16
virtual void go()=0
virtual ~Car()=default
void set_loggers([[maybe_unused]] GOptions *const g)
Definition: Car.h:11
double generalCarVar
Definition: Car.h:13
void * dlhandle
Definition: gdl.h:15