Debian Codegraph @

DataModel/LocoConfig.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 <string>
24
25 #include "DataModel/Loco.h"
26 #include "DataModel/MultipleUnit.h"
27 #include "Hardware/LocoCache.h"
28
29 namespace DataModel
30 {
31 class LocoConfig
32 {
33 public:
34 inline LocoConfig(const LocoType type = LocoTypeLoco)
35 : controlId(ControlNone),
36 locoId(LocoNone),
37 address(AddressDefault),
38 protocol(ProtocolNone),
39 type(type),
40 isInUse(false)
41 {
42 }
43
44 inline LocoConfig(const DataModel::Loco& loco)
45 : controlId(loco.GetControlID()),
46 locoId(loco.GetID()),
47 address(loco.GetAddress()),
48 protocol(loco.GetProtocol()),
49 type(LocoTypeLoco),
50 name(loco.GetName()),
51 matchKey(loco.GetMatchKey()),
52 isInUse(loco.IsInUse())
53 {
54 ConfigureFunctions(loco.GetFunctionStates());
55 }
56
57 inline LocoConfig(const Hardware::LocoCacheEntry& loco)
58 : controlId(loco.GetControlID()),
59 locoId(loco.GetLocoID()),
60 address(loco.GetAddress()),
61 protocol(loco.GetProtocol()),
62 type(loco.GetType()),
63 name(loco.GetName()),
64 matchKey(loco.GetMatchKey()),
65 isInUse(false),
66 slaves(loco.GetSlaveIDs())
67 {
68 ConfigureFunctions(loco.GetFunctionStates());
69 }
70
71 inline LocoConfig& operator=(const DataModel::Loco& loco)
72 {
73 controlId = loco.GetControlID();
74 locoId = loco.GetID();
75 address = loco.GetAddress();
76 protocol = loco.GetProtocol();
77 type = LocoTypeLoco;
78 name = loco.GetName();
79 matchKey = loco.GetMatchKey();
80 isInUse = loco.IsInUse();
81 ConfigureFunctions(loco.GetFunctionStates());
82 return *this;
83 }
84
85 inline LocoConfig& operator=(const Hardware::LocoCacheEntry& loco)
86 {
87 controlId = loco.GetControlID();
88 locoId = loco.GetLocoID();
89 address = loco.GetAddress();
90 protocol = loco.GetProtocol();
91 type = loco.GetType();
92 name = loco.GetName();
93 matchKey = loco.GetMatchKey();
94 ConfigureFunctions(loco.GetFunctionStates());
95 slaves = loco.GetSlaveIDs();
96 return *this;
97 }
98
99 inline LocoConfig& operator=(const DataModel::MultipleUnit& multipleUnit)
100 {
101 controlId = multipleUnit.GetControlID();
102 locoId = multipleUnit.GetID();
103 address = multipleUnit.GetAddress();
104 protocol = ProtocolNone;
105 type = LocoTypeMultipleUnit;
106 name = multipleUnit.GetName();
107 matchKey = multipleUnit.GetMatchKey();
108 isInUse = multipleUnit.IsInUse();
109 ConfigureFunctions(multipleUnit.GetFunctionStates());
110 slaves = multipleUnit.GetSlaveIDs();
111 return *this;
112 }
113
114 inline ControlID GetControlId() const
115 {
116 return controlId;
117 }
118
119 inline LocoID GetLocoId() const
120 {
121 return locoId;
122 }
123
124 inline Address GetAddress() const
125 {
126 return address;
127 }
128
129 inline Protocol GetProtocol() const
130 {
131 return protocol;
132 }
133
134 inline LocoType GetType() const
135 {
136 return type;
137 }
138
139 inline void SetType(const LocoType type)
140 {
141 this->type = type;
142 }
143
144 inline std::string GetName() const
145 {
146 return name;
147 }
148
149 inline void SetName(const std::string& name)
150 {
151 this->name = name;
152 }
153
154 inline std::string GetMatchKey() const
155 {
156 return matchKey;
157 }
158
159 inline bool IsInUse() const
160 {
161 return isInUse;
162 }
163
164 inline void GetFunctions(LocoFunctionEntry* out) const
165 {
166 functions.GetFunctions(out);
167 }
168
169 inline void ConfigureFunctions(const std::vector<LocoFunctionEntry>& newEntries)
170 {
171 functions.ConfigureFunctions(newEntries);
172 }
173
174 inline void AddSlave(const LocoID locoID)
175 {
176 slaves.push_back(locoID);
177 }
178
179 inline const std::vector<LocoID>& GetSlaves() const
180 {
181 return slaves;
182 }
183
184 private:
185 ControlID controlId;
186 LocoID locoId;
187 Address address;
188 Protocol protocol;
189 LocoType type;
190 std::string name;
191 std::string matchKey;
192 bool isInUse;
193 LocoFunctions functions;
194 std::vector<LocoID> slaves;
195 };
196 } // namespace DataModel