Debian Codegraph @

DataModel/ObjectIdentifier.cpp

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
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 #include "DataModel/ObjectIdentifier.h"
22 #include "Utils/Integer.h"
23 #include "Utils/Utils.h"
24
25 namespace DataModel
26 {
•27 void ObjectIdentifier::Deserialize(const std::map<std::string, std::string>& arguments)
28 {
29 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "track", ObjectNone));
30 if (objectID != ObjectNone)
31 {
32 objectType = ObjectTypeTrack;
•33 return;
34 }
35
36 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "signal", ObjectNone));
37 if (objectID != ObjectNone)
38 {
39 objectType = ObjectTypeSignal;
•40 return;
41 }
42
43 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "switch", ObjectNone));
44 if (objectID != ObjectNone)
45 {
46 objectType = ObjectTypeSwitch;
•47 return;
48 }
49
50 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "accessory", ObjectNone));
51 if (objectID != ObjectNone)
52 {
53 objectType = ObjectTypeAccessory;
•54 return;
55 }
56
57 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "feedback", ObjectNone));
58 if (objectID != ObjectNone)
59 {
60 objectType = ObjectTypeFeedback;
•61 return;
62 }
63
64 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "route", ObjectNone));
65 if (objectID != ObjectNone)
66 {
67 objectType = ObjectTypeRoute;
•68 return;
69 }
70
71 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "text", ObjectNone));
72 if (objectID != ObjectNone)
73 {
74 objectType = ObjectTypeText;
•75 return;
76 }
77
78 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "pause", ObjectNone));
79 if (objectID != ObjectNone)
80 {
81 objectType = ObjectTypePause;
•82 return;
83 }
84
85 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "multipleunit", ObjectNone));
86 if (objectID != ObjectNone)
87 {
88 objectType = ObjectTypeMultipleUnit;
•89 return;
90 }
91
92 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "booster", ObjectNone));
93 if (objectID != ObjectNone)
94 {
95 objectType = ObjectTypeBooster;
•96 return;
97 }
98
•99 objectID = static_cast<ObjectID>(Utils::Utils::GetIntegerMapEntry(arguments, "counter", ObjectNone));
100 if (objectID != ObjectNone)
101 {
102 objectType = ObjectTypeCounter;
103 return;
104 }
105
106 objectType = ObjectTypeNone;
107 }
108
109 ObjectIdentifier& ObjectIdentifier::operator=(const std::string& text)
110 {
111 if (text.substr(0, 5).compare("track") == 0)
112 {
113 objectType = ObjectTypeTrack;
114 objectID = Utils::Integer::StringToInteger(text.substr(5), ObjectNone);
115 return *this;
116 }
117 if (text.substr(0, 6).compare("signal") == 0)
118 {
119 objectType = ObjectTypeSignal;
120 objectID = Utils::Integer::StringToInteger(text.substr(6), ObjectNone);
121 return *this;
122 }
123 if (text.substr(0, 5).compare("route") == 0)
124 {
125 objectType = ObjectTypeRoute;
126 objectID = Utils::Integer::StringToInteger(text.substr(5), ObjectNone);
127 return *this;
128 }
129 if (text.substr(0, 4).compare("loco") == 0)
130 {
131 objectType = ObjectTypeLoco;
132 objectID = Utils::Integer::StringToInteger(text.substr(4), ObjectNone);
133 return *this;
134 }
135 if (text.substr(0, 8).compare("feedback") == 0)
136 {
137 objectType = ObjectTypeFeedback;
138 objectID = Utils::Integer::StringToInteger(text.substr(8), ObjectNone);
139 return *this;
140 }
141 if (text.substr(0, 9).compare("accessory") == 0)
142 {
143 objectType = ObjectTypeAccessory;
144 objectID = Utils::Integer::StringToInteger(text.substr(9), ObjectNone);
145 return *this;
146 }
147 if (text.substr(0, 6).compare("switch") == 0)
148 {
149 objectType = ObjectTypeSwitch;
150 objectID = Utils::Integer::StringToInteger(text.substr(6), ObjectNone);
151 return *this;
152 }
153 if (text.substr(0, 5).compare("layer") == 0)
154 {
155 objectType = ObjectTypeLayer;
156 objectID = Utils::Integer::StringToInteger(text.substr(5), ObjectNone);
157 return *this;
158 }
159 if (text.substr(0, 7).compare("cluster") == 0)
160 {
161 objectType = ObjectTypeCluster;
162 objectID = Utils::Integer::StringToInteger(text.substr(7), ObjectNone);
163 return *this;
164 }
165 if (text.substr(0, 9).compare("timetable") == 0)
166 {
167 objectType = ObjectTypeTimeTable;
168 objectID = Utils::Integer::StringToInteger(text.substr(9), ObjectNone);
169 return *this;
170 }
171 if (text.substr(0, 4).compare("text") == 0)
172 {
173 objectType = ObjectTypeText;
174 objectID = Utils::Integer::StringToInteger(text.substr(4), ObjectNone);
175 return *this;
176 }
177 if (text.substr(0, 5).compare("pause") == 0)
178 {
179 objectType = ObjectTypePause;
180 objectID = Utils::Integer::StringToInteger(text.substr(5), ObjectNone);
181 return *this;
182 }
183 if (text.substr(0, 12).compare("multipleunit") == 0)
184 {
185 objectType = ObjectTypeMultipleUnit;
186 objectID = Utils::Integer::StringToInteger(text.substr(12), ObjectNone);
187 return *this;
188 }
189 if (text.substr(0, 7).compare("booster") == 0)
190 {
191 objectType = ObjectTypeBooster;
192 objectID = Utils::Integer::StringToInteger(text.substr(7), ObjectNone);
193 return *this;
194 }
•195 if (text.substr(0, 7).compare("counter") == 0)
196 {
197 objectType = ObjectTypeCounter;
198 objectID = Utils::Integer::StringToInteger(text.substr(7), ObjectNone);
199 return *this;
200 }
201 objectType = ObjectTypeTrack;
202 objectID = Utils::Integer::StringToInteger(text, ObjectNone);
203 return *this;
204 }
205
206 std::string ObjectIdentifier::ObjectTypeToString(const ObjectType objectType)
207 {
208 switch (objectType)
209 {
210 case ObjectTypeNone:
211 return "none";
212
213 case ObjectTypeLoco:
214 return "loco";
215
216 case ObjectTypeTrack:
217 return "track";
218
219 case ObjectTypeFeedback:
220 return "feedback";
221
222 case ObjectTypeAccessory:
223 return "accessory";
224
225 case ObjectTypeSwitch:
226 return "switch";
227
228 case ObjectTypeRoute:
229 return "route";
230
231 case ObjectTypeLayer:
232 return "layer";
233
234 case ObjectTypeSignal:
235 return "signal";
236
237 case ObjectTypeCluster:
238 return "cluster";
239
240 case ObjectTypeTimeTable:
241 return "timetable";
242
243 case ObjectTypeText:
244 return "text";
245
246 case ObjectTypePause:
247 return "pause";
248
249 case ObjectTypeMultipleUnit:
250 return "multipleunit";
251
252 case ObjectTypeBooster:
253 return "booster";
•254
255 case ObjectTypeCounter:
256 return "counter";
257 }
258 return "object";
259 }
260 } // namespace DataModel
261