SensorGroupTemplate.h 1.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * SensorGroupTemplate.h
 *
 *  Created on: 03.08.2018
 *      Author: Micha Mueller
 */

#ifndef SENSORGROUPTEMPLATE_H_
#define SENSORGROUPTEMPLATE_H_

#include "SensorGroupInterface.h"

#include <vector>

template <typename S>
class SensorGroupTemplate : public SensorGroupInterface {
	//the template shall only be instantiated for classes which derive from SensorBase
	static_assert(std::is_base_of<SensorBase, S>::value, "S must derive from SensorBase!");

public:
	SensorGroupTemplate(const std::string groupName) :
		SensorGroupInterface(groupName) {}

	virtual ~SensorGroupTemplate() {
		for(auto s : _sensors) {
			delete s;
		}
	}

	virtual void pushBackSensor(SensorBase* s) override {
		if (S* dSensor = dynamic_cast<S*>(s)) {
			_sensors.push_back(dSensor);
			_baseSensors.push_back(s);
		} else {
			LOG(warning) << "Sensorgroup " << _groupName << ": Type mismatch when storing sensor! Sensor omitted";
		}
	}

	virtual std::vector<SensorBase*>& getSensors() override	{ return _baseSensors; }

	virtual void init(boost::asio::io_service& io) {
42
		SensorGroupInterface::init(io);
43
44
45
46
47
48
49
50
51
52
53
54

		for(auto s : _sensors) {
			s->initSensor(_cacheSize);
		}
	}

protected:
	std::vector<S*> _sensors;
	std::vector<SensorBase*> _baseSensors;
};

#endif /* SENSORGROUPTEMPLATE_H_ */