2D_Engine/ChannelManager.hpp

56 lines
1.5 KiB
C++

/********************\
| Copyright 2024, |
| Ulysse Cura |
\********************/
////////////////////////////////////////////////////////////////////////////
// //
// Programme des channels, sert au entitée pour avoir //
// un channel de discution, comme un interrupteur qui vas mettre son état //
// dans un channel, ou une porte qui vas lire dans un channel pour savoir //
// elle doit s'ouvrir ou non. //
// //
////////////////////////////////////////////////////////////////////////////
#ifndef CHANNELMANAGER_HPP
#define CHANNELMANAGER_HPP
#include <unordered_map> // unordered_map
using std::unordered_map;
class ChannelManager {
public:
// Setter
void setChannel(int channelID, bool value)
{
channels[channelID] = value;
}
// Getter
bool getChannel(int channelID) const
{
auto it = channels.find(channelID);
return it != channels.end() ? it->second : false;
}
// Verify if all given channels are in corresponding state
bool areChannelsInState(const unordered_map<int, bool> &states)
{
for(const auto &state : states)
{
if(getChannel(state.first) != state.second)
{
return false;
}
}
return true;
}
private:
unordered_map<int, bool> channels;
};
#endif