Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /** | |||
2 | * @file function_pointer_sensor.h | |||
3 | * @brief A sensor to provide a bridge from old getX()-style functions to the new sensor registry. | |||
4 | * | |||
5 | * @date September 12, 2019 | |||
6 | * @author Matthew Kennedy, (c) 2019 | |||
7 | */ | |||
8 | ||||
9 | #pragma once | |||
10 | ||||
11 | #include "sensor.h" | |||
12 | ||||
13 | /* This class is intended as a bridge to bridge from old getMySensor() functions | |||
14 | * to the new system. This way, producers and consumers can be independently | |||
15 | * updated to the new system, with sensors being usable either way for some time. | |||
16 | */ | |||
17 | class FunctionPointerSensor final : public Sensor { | |||
18 | public: | |||
19 | 3 | FunctionPointerSensor(SensorType type, float (*func)()) | ||
20 | 3 | : Sensor(type) | ||
21 | 3 | , m_func(func) {} | ||
22 | ||||
23 | 1 | SensorResult get() const final { | ||
24 |
1/1✓ Branch 2 taken 1 time.
|
1 | float result = m_func(); | |
25 | ||||
26 | // check for NaN | |||
27 | 1 | bool valid = !(result != result); | ||
28 | ||||
29 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 1 time.
|
1 | if (!valid) { |
30 | ✗ | return unexpected; | ||
31 | } | |||
32 | ||||
33 | 1 | return result; | ||
34 | } | |||
35 | ||||
36 | ✗ | void showInfo(const char* /*sensorName*/) const override {} | ||
37 | ||||
38 | private: | |||
39 | float (*m_func)(); | |||
40 | }; | |||
41 |