gfactory
Loading...
Searching...
No Matches
Car.h
Go to the documentation of this file.
1#pragma once
2
3// gemc
4#include "gbase.h"
5
6// gfactory
7#include "gdl.h"
8#include "gfactory_options.h"
9
10
11class Car : public GBase<Car> {
12public:
13
14 ~Car() override = default;
15
16 explicit Car(const std::shared_ptr<GOptions>& g) : GBase(g, PLUGIN_LOGGER) {
17 }
18
19 virtual void go() = 0;
20
21 void set_loggers([[ maybe_unused ]] const std::shared_ptr<GOptions>& g) {}
22
23 double generalCarVar = 44;
24
25 // method to dynamically load factories
26 // static Car *instantiate(const dlhandle handle) {
27 //
28 // if (handle == nullptr) return nullptr;
29 //
30 // // must match the extern C declaration in the derived factories
31 // void *maker = dlsym(handle, "CarFactory");
32 //
33 // if (maker == nullptr) return nullptr;
34 //
35 // typedef Car *(*fptr)();
36 //
37 // // static_cast not allowed here
38 // // see http://stackoverflow.com/questions/573294/when-to-use-reinterpret-cast
39 // // need to run the DLL CarFactory function that returns the factory
40 // fptr func = reinterpret_cast<fptr>(reinterpret_cast<void *>(maker));
41 //
42 // return func();
43 // }
44
45 static Car* instantiate(const dlhandle h, std::shared_ptr<GOptions> g) {
46 if (!h) return nullptr;
47 using fptr = Car* (*)(std::shared_ptr<GOptions>);
48
49 // Must match the extern "C" declaration in the derived factories.
50 auto sym = dlsym(h, "CarFactory");
51 if (!sym) return nullptr;
52
53 auto func = reinterpret_cast<fptr>(sym);
54 return func(g);
55 }
56
57};
58
Definition Car.h:11
static Car * instantiate(const dlhandle h, std::shared_ptr< GOptions > g)
Definition Car.h:45
virtual void go()=0
void set_loggers(const std::shared_ptr< GOptions > &g)
Definition Car.h:21
Car(const std::shared_ptr< GOptions > &g)
Definition Car.h:16
~Car() override=default
double generalCarVar
Definition Car.h:23
void * dlhandle
Definition gdl.h:15
constexpr const char * PLUGIN_LOGGER