| 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 DccPpExLocoCacheEntry |
| 32 |
{ |
| 33 |
public: |
| 34 |
DccPpExLocoCacheEntry() |
| 35 |
: speed(MinSpeed), |
| 36 |
orientation(OrientationRight) |
| 37 |
{ |
| 38 |
} |
| 39 |
|
| 40 |
DccPpExLocoCacheEntry(const Speed speed, const Orientation orientation) |
| 41 |
: speed(speed), |
| 42 |
orientation(orientation) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
Speed speed; |
| 47 |
Orientation orientation; |
| 48 |
}; |
| 49 |
|
| 50 |
class DccPpExLocoCache |
| 51 |
{ |
| 52 |
public: |
| 53 |
DccPpExLocoCache& operator=(const DccPpExLocoCache&) = delete; |
| 54 |
|
| 55 |
DccPpExLocoCacheEntry GetData(const Address address) |
| 56 |
{ |
| 57 |
if (cache.count(address) == 1) |
| 58 |
{ |
| 59 |
return cache[address]; |
| 60 |
} |
| 61 |
DccPpExLocoCacheEntry entry; |
| 62 |
return entry; |
| 63 |
} |
| 64 |
|
| 65 |
void SetSpeed(const Address address, const Speed speed) |
| 66 |
{ |
| 67 |
DccPpExLocoCacheEntry entry = GetData(address); |
| 68 |
entry.speed = speed; |
| 69 |
cache[address] = entry; |
| 70 |
} |
| 71 |
|
| 72 |
Speed GetSpeed(const Address address) |
| 73 |
{ |
| 74 |
if (cache.count(address) == 0) |
| 75 |
{ |
| 76 |
return MinSpeed; |
| 77 |
} |
| 78 |
return cache[address].speed; |
| 79 |
} |
| 80 |
|
| 81 |
void SetOrientation(const Address address, const Orientation orientation) |
| 82 |
{ |
| 83 |
DccPpExLocoCacheEntry entry = GetData(address); |
| 84 |
entry.orientation = orientation; |
| 85 |
cache[address] = entry; |
| 86 |
} |
| 87 |
|
| 88 |
Orientation GetOrientation(const Address address) |
| 89 |
{ |
| 90 |
if (cache.count(address) == 0) |
| 91 |
{ |
| 92 |
return OrientationRight; |
| 93 |
} |
| 94 |
return cache[address].orientation; |
| 95 |
} |
| 96 |
|
| 97 |
private: |
| 98 |
std::map<Address, DccPpExLocoCacheEntry> cache; |
| 99 |
}; |
| 100 |
} |
| 101 |
} |
| 102 |
|