Inital commit. Meisten features sind implementiert und müssen getestet werden
This commit is contained in:
28
src/Cache.cpp
Normal file
28
src/Cache.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "Cache.h"
|
||||
#include <algorithm>
|
||||
std::vector<TopicState> Cache::topic_states(std::vector<std::string>& topics) {
|
||||
std::vector<TopicState> states;
|
||||
|
||||
for (const auto& topic : topics) {
|
||||
auto hit = std::find_if(cache.begin(), cache.end(), [&](TopicState& cache_state) {
|
||||
return cache_state.topic == topic;
|
||||
});
|
||||
if (hit != cache.end()) {
|
||||
states.push_back(*hit);
|
||||
}
|
||||
}
|
||||
|
||||
return states;
|
||||
}
|
||||
|
||||
TopicState Cache::set_topic_value(const std::string& topic, const std::string& value) {
|
||||
for (auto& state : cache) {
|
||||
if (state.topic == topic) {
|
||||
state.value = value;
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
return cache.emplace_back(topic, value);
|
||||
}
|
||||
Reference in New Issue
Block a user