Debian Codegraph @

DataModel/ObjectIdentifier.cpp

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