Debian Codegraph @

Hardware/Protocols/DccPpExLocoCache.h

raw symbols SCIP
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
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 } // namespace
101 } // namespace
102