Debian Codegraph @

Hardware/Protocols/Z21TurnoutCache.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 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 } // namespace
75 } // namespace
76