gfactory
Loading...
Searching...
No Matches
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 ]]
const
std::shared_ptr<GOptions>& 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
static
Car
*
instantiate
(
const
dlhandle
h, std::shared_ptr<GOptions> g) {
36
if
(!h)
return
nullptr
;
37
using
fptr =
Car
* (*)(std::shared_ptr<GOptions>);
38
39
// Must match the extern "C" declaration in the derived factories.
40
auto
sym = dlsym(h,
"CarFactory"
);
41
if
(!sym)
return
nullptr
;
42
43
auto
func =
reinterpret_cast<
fptr
>
(sym);
44
return
func(g);
45
}
46
47
};
48
Car
Definition
Car.h:5
Car::instantiate
static Car * instantiate(const dlhandle h, std::shared_ptr< GOptions > g)
Definition
Car.h:35
Car::go
virtual void go()=0
Car::~Car
virtual ~Car()=default
Car::set_loggers
void set_loggers(const std::shared_ptr< GOptions > &g)
Definition
Car.h:11
Car::generalCarVar
double generalCarVar
Definition
Car.h:13
gdl.h
dlhandle
void * dlhandle
Definition
gdl.h:15
examples
Car.h
Generated by
1.10.0