#pragma once #include "interfaces/sensor.hpp" #include #include #include #include class SensorCache { public: template std::shared_ptr makeSensor(std::string_view service, std::string_view path, Args&&... args) { cleanupExpiredSensors(); auto id = SensorType::makeId(service, path); auto it = sensors.find(id); if (it == sensors.end()) { auto sensor = std::make_shared( std::move(id), std::forward(args)...); sensors[sensor->id()] = sensor; return sensor; } return std::static_pointer_cast(it->second.lock()); } private: using SensorsContainer = boost::container::flat_map>; SensorsContainer sensors; SensorsContainer::iterator findExpiredSensor(SensorsContainer::iterator); void cleanupExpiredSensors(); };