| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <map> |
| 24 |
|
| 25 |
#include "DataTypes.h" |
| 26 |
|
| 27 |
namespace Hardware |
| 28 |
{ |
| 29 |
namespace Protocols |
| 30 |
{ |
| 31 |
class Z21TurnoutCacheEntry |
| 32 |
{ |
| 33 |
public: |
| 34 |
Z21TurnoutCacheEntry(const Z21TurnoutCacheEntry&) = delete; |
| 35 |
|
| 36 |
inline Z21TurnoutCacheEntry() |
| 37 |
: protocol(ProtocolNone) |
| 38 |
{ |
| 39 |
} |
| 40 |
|
| 41 |
inline Z21TurnoutCacheEntry& operator=(const Protocol protocol) |
| 42 |
{ |
| 43 |
this->protocol = protocol; |
| 44 |
return *this; |
| 45 |
} |
| 46 |
|
| 47 |
inline Z21TurnoutCacheEntry& operator=(const Z21TurnoutCacheEntry&) = delete; |
| 48 |
|
| 49 |
Protocol protocol; |
| 50 |
}; |
| 51 |
|
| 52 |
class Z21TurnoutCache |
| 53 |
{ |
| 54 |
public: |
| 55 |
Z21TurnoutCache& operator=(const Z21TurnoutCache&) = delete; |
| 56 |
|
| 57 |
inline void SetProtocol(const Address address, const Protocol protocol) |
| 58 |
{ |
| 59 |
cache[address] = protocol; |
| 60 |
} |
| 61 |
|
| 62 |
inline Protocol GetProtocol(const Address address) |
| 63 |
{ |
| 64 |
if (cache.count(address) == 0) |
| 65 |
{ |
| 66 |
return ProtocolDCC; |
| 67 |
} |
| 68 |
return cache[address].protocol; |
| 69 |
} |
| 70 |
|
| 71 |
private: |
| 72 |
std::map<Address, Z21TurnoutCacheEntry> cache; |
| 73 |
}; |
| 74 |
} |
| 75 |
} |
| 76 |
|