Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/xml/CommonXMLStructure.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file CommonXMLStructure.h
15
/// @author Pablo Alvarez Lopez
16
/// @date May 2021
17
///
18
// Structure for common XML Parsing
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <utils/common/SUMOTime.h>
24
#include <utils/common/RGBColor.h>
25
#include <utils/geom/PositionVector.h>
26
#include <utils/vehicle/SUMOVehicleParameter.h>
27
#include <utils/vehicle/SUMOVTypeParameter.h>
28
#include <utils/xml/SUMOSAXHandler.h>
29
#include <utils/xml/SUMOXMLDefinitions.h>
30
31
32
// ===========================================================================
33
// class definitions
34
// ===========================================================================
35
36
class CommonXMLStructure {
37
38
public:
39
40
/// @brief class declaration
41
class SumoBaseObject;
42
43
/// @brief plan parameters (used for group all from-to parameters related with plans)
44
class PlanParameters {
45
46
public:
47
// @brief default constructor
48
PlanParameters();
49
50
/// @brief constructor for parsing the parameters from SUMOSAXAttributes
51
PlanParameters(const CommonXMLStructure::SumoBaseObject* sumoBaseObject,
52
const SUMOSAXAttributes& attrs, bool& parsedOk);
53
54
/// @brief clear parameters
55
void clear();
56
57
/// @brief check if this is a single-edge plan
58
bool isSingleEdgePlan() const;
59
60
/// @brief get number of defined plans
61
int getNumberOfDefinedParameters() const;
62
63
/// @brief get the walk tag for the current combination of parameters
64
SumoXMLTag getWalkTag() const;
65
66
/// @brief get the personTrip tag for the current combination of parameters
67
SumoXMLTag getPersonTripTag() const;
68
69
/// @brief get the ride tag for the current combination of parameters
70
SumoXMLTag getRideTag() const;
71
72
/// @brief get the transport tag for the current combination of parameters
73
SumoXMLTag getTransportTag() const;
74
75
/// @brief get the tranship tag for the current combination of parameters
76
SumoXMLTag getTranshipTag() const;
77
78
/// @brief get the person stop tag for the current combination of parameters
79
SumoXMLTag getPersonStopTag() const;
80
81
/// @brief get the container stop tag for the current combination of parameters
82
SumoXMLTag getContainerStopTag() const;
83
84
/// @brief from edge
85
std::string fromEdge;
86
87
/// @brief to edge
88
std::string toEdge;
89
90
/// @brief consecutive edges
91
std::vector<std::string> consecutiveEdges;
92
93
/// @brief from junction
94
std::string fromJunction;
95
96
/// @brief to junction
97
std::string toJunction;
98
99
/// @brief from TAZ
100
std::string fromTAZ;
101
102
/// @brief to TAZ
103
std::string toTAZ;
104
105
/// @brief from busStop
106
std::string fromBusStop;
107
108
/// @brief to busStop
109
std::string toBusStop;
110
111
/// @brief from trainStop
112
std::string fromTrainStop;
113
114
/// @brief to trainStop
115
std::string toTrainStop;
116
117
/// @brief from containerStop
118
std::string fromContainerStop;
119
120
/// @brief to containerStop
121
std::string toContainerStop;
122
123
/// @brief from chargingStation
124
std::string fromChargingStation;
125
126
/// @brief to chargingStation
127
std::string toChargingStation;
128
129
/// @brief from parkingArea
130
std::string fromParkingArea;
131
132
/// @brief to parkingArea
133
std::string toParkingArea;
134
135
/// @brief from route
136
std::string fromRoute;
137
138
/// @brief to route
139
std::string toRoute;
140
141
private:
142
/// @brief get previous plan obj
143
const CommonXMLStructure::SumoBaseObject* getPreviousPlanObj(const CommonXMLStructure::SumoBaseObject* sumoBaseObject) const;
144
145
/// @brief update the from attributes
146
void updateFromAttributes(const CommonXMLStructure::SumoBaseObject* sumoBaseObject);
147
148
/// @brief reste all previous from attributes
149
void resetPreviousFromAttributes(const CommonXMLStructure::SumoBaseObject* previousPlanObj, const std::string& newType, const std::string& newId) const;
150
151
/// @brief write ignoring message
152
void writeIgnoringMessage(const CommonXMLStructure::SumoBaseObject* previousPlanObj, const std::string& oldType, const std::string& oldId,
153
const std::string& newType, const std::string& newId) const;
154
};
155
156
/// @brief SumoBaseObject
157
class SumoBaseObject {
158
159
public:
160
/// @brief constructor
161
SumoBaseObject(SumoBaseObject* sumoBaseObjectParent);
162
163
/// @brief destructor
164
~SumoBaseObject();
165
166
/// @brief clear SumoBaseObject
167
void clear();
168
169
/// @brief set SumoBaseObject tag
170
void setTag(const SumoXMLTag tag);
171
172
/// @brief mark as successfully created
173
void markAsCreated();
174
175
/// @name get functions
176
/// @{
177
178
/// @brief get XML myTag
179
SumoXMLTag getTag() const;
180
181
/// @brief check if the object was successfully created in build<...> function
182
bool wasCreated() const;
183
184
/// @brief get pointer to mySumoBaseObjectParent SumoBaseObject (if is null, then is the root)
185
SumoBaseObject* getParentSumoBaseObject() const;
186
187
/// @brief get all attributes in string format
188
std::map<std::string, std::string> getAllAttributes() const;
189
190
/// @brief get string attribute
191
const std::string& getStringAttribute(const SumoXMLAttr attr) const;
192
193
/// @brief get int attribute
194
int getIntAttribute(const SumoXMLAttr attr) const;
195
196
/// @brief get double attribute
197
double getDoubleAttribute(const SumoXMLAttr attr) const;
198
199
/// @brief get bool attribute
200
bool getBoolAttribute(const SumoXMLAttr attr) const;
201
202
/// @brief get Position attribute
203
const Position& getPositionAttribute(const SumoXMLAttr attr) const;
204
205
/// @brief get time attribute
206
SUMOTime getTimeAttribute(const SumoXMLAttr attr) const;
207
208
/// @brief get 'period' attribute
209
SUMOTime getPeriodAttribute() const;
210
211
/// @brief get color attribute
212
const RGBColor& getColorAttribute(const SumoXMLAttr attr) const;
213
214
/// @brief get string list attribute
215
const std::vector<std::string>& getStringListAttribute(const SumoXMLAttr attr) const;
216
217
/// @brief get double list attribute
218
const std::vector<double>& getDoubleListAttribute(const SumoXMLAttr attr) const;
219
220
/// @brief get PositionVector attribute
221
const PositionVector& getPositionVectorAttribute(const SumoXMLAttr attr) const;
222
223
/// @brief get parent ID
224
const std::string& getParentID(const SumoXMLTag tag) const;
225
226
/// @brief vehicle class
227
SUMOVehicleClass getVClass() const;
228
229
/// @brief get current vType
230
const SUMOVTypeParameter& getVehicleTypeParameter() const;
231
232
/// @brief get vehicle parameters
233
const SUMOVehicleParameter& getVehicleParameter() const;
234
235
/// @brief get stop parameters
236
const SUMOVehicleParameter::Stop& getStopParameter() const;
237
238
/// @brief get parameters
239
const std::map<std::string, std::string>& getParameters() const;
240
241
/// @brief get plan parameteres
242
const CommonXMLStructure::PlanParameters& getPlanParameters() const;
243
244
/// @brief get SumoBaseObject children
245
const std::vector<SumoBaseObject*>& getSumoBaseObjectChildren() const;
246
247
/// @}
248
249
/// @brief has function
250
/// @{
251
252
/// @brief check if current SumoBaseObject has the given string attribute
253
bool hasStringAttribute(const SumoXMLAttr attr) const;
254
255
/// @brief check if current SumoBaseObject has the given int attribute
256
bool hasIntAttribute(const SumoXMLAttr attr) const;
257
258
/// @brief check if current SumoBaseObject has the given double attribute
259
bool hasDoubleAttribute(const SumoXMLAttr attr) const;
260
261
/// @brief check if current SumoBaseObject has the given bool attribute
262
bool hasBoolAttribute(const SumoXMLAttr attr) const;
263
264
/// @brief check if current SumoBaseObject has the given bool attribute
265
bool hasPositionAttribute(const SumoXMLAttr attr) const;
266
267
/// @brief check if current SumoBaseObject has the given time attribute
268
bool hasTimeAttribute(const SumoXMLAttr attr) const;
269
270
/// @brief check if current SumoBaseObject has the given color attribute
271
bool hasColorAttribute(const SumoXMLAttr attr) const;
272
273
/// @brief check if current SumoBaseObject has the given string list attribute
274
bool hasStringListAttribute(const SumoXMLAttr attr) const;
275
276
/// @brief check if current SumoBaseObject has the given double list attribute
277
bool hasDoubleListAttribute(const SumoXMLAttr attr) const;
278
279
/// @brief check if current SumoBaseObject has the given positionVector attribute
280
bool hasPositionVectorAttribute(const SumoXMLAttr attr) const;
281
282
/// @brief check if current SumoBaseObject has the given parent ID
283
bool hasParentID(const SumoXMLTag tag) const;
284
285
/// @}
286
287
/// @name add functions
288
/// @{
289
290
/// @brief add string attribute into current SumoBaseObject node
291
void addStringAttribute(const SumoXMLAttr attr, const std::string& value);
292
293
/// @brief add int attribute into current SumoBaseObject node
294
void addIntAttribute(const SumoXMLAttr attr, const int value);
295
296
/// @brief add double attribute into current SumoBaseObject node
297
void addDoubleAttribute(const SumoXMLAttr attr, const double value);
298
299
/// @brief add bool attribute into current SumoBaseObject node
300
void addBoolAttribute(const SumoXMLAttr attr, const bool value);
301
302
/// @brief add Position attribute into current SumoBaseObject node
303
void addPositionAttribute(const SumoXMLAttr attr, const Position& value);
304
305
/// @brief add time attribute into current SumoBaseObject node
306
void addTimeAttribute(const SumoXMLAttr attr, const SUMOTime value);
307
308
/// @brief add color attribute into current SumoBaseObject node
309
void addColorAttribute(const SumoXMLAttr attr, const RGBColor& value);
310
311
/// @brief add string list attribute into current SumoBaseObject node
312
void addStringListAttribute(const SumoXMLAttr attr, const std::vector<std::string>& value);
313
314
/// @brief add double list attribute into current SumoBaseObject node
315
void addDoubleListAttribute(const SumoXMLAttr attr, const std::vector<double>& value);
316
317
/// @brief add PositionVector attribute into current SumoBaseObject node
318
void addPositionVectorAttribute(const SumoXMLAttr attr, const PositionVector& value);
319
320
/// @brief add parameters into current SumoBaseObject node (format: key=value1|key2=value2|....)
321
void addParameters(const std::string& value);
322
323
/// @brief add parameter into current SumoBaseObject node
324
void addParameter(const std::string& key, const std::string& value);
325
326
/// @brief add parent (string) attribute into current SumoBaseObject node
327
void addParentID(const SumoXMLTag tag, const std::string& ID);
328
329
/// @brief set vehicle class
330
void setVClass(SUMOVehicleClass vClass);
331
332
/// @brief set vehicle type parameters
333
void setVehicleTypeParameter(const SUMOVTypeParameter* vehicleTypeParameter);
334
335
/// @brief set vehicle parameters
336
void setVehicleParameter(const SUMOVehicleParameter* vehicleParameter);
337
338
/// @brief add stop parameters
339
void setStopParameter(const SUMOVehicleParameter::Stop& stopParameter);
340
341
/// @brief set plan parmeter
342
void setPlanParameters(const CommonXMLStructure::PlanParameters& planParameters);
343
344
/// @}
345
346
protected:
347
/// @brief pointer to SumoBaseObject parent (If is null, then is the root)
348
SumoBaseObject* mySumoBaseObjectParent;
349
350
/// @brief XML myTag
351
SumoXMLTag myTag = SUMO_TAG_NOTHING;
352
353
/// @brief flag to check if object was created in build<..> function (by default false)
354
bool myWasCreated = false;
355
356
/// @brief string attributes
357
std::map<const SumoXMLAttr, std::string> myStringAttributes;
358
359
/// @brief int attributes
360
std::map<const SumoXMLAttr, int> myIntAttributes;
361
362
/// @brief double attributes
363
std::map<const SumoXMLAttr, double> myDoubleAttributes;
364
365
/// @brief bool attributes
366
std::map<const SumoXMLAttr, bool> myBoolAttributes;
367
368
/// @brief Position attributes
369
std::map<const SumoXMLAttr, Position> myPositionAttributes;
370
371
/// @brief SUMOTime attributes
372
std::map<const SumoXMLAttr, SUMOTime> myTimeAttributes;
373
374
/// @brief RGBColor attributes
375
std::map<const SumoXMLAttr, RGBColor> myColorAttributes;
376
377
/// @brief stringList attributes
378
std::map<const SumoXMLAttr, std::vector<std::string> > myStringListAttributes;
379
380
/// @brief stringList attributes
381
std::map<const SumoXMLAttr, std::vector<double> > myDoubleListAttributes;
382
383
/// @brief PositionVector attributes
384
std::map<const SumoXMLAttr, PositionVector> myPositionVectorAttributes;
385
386
/// @brief myParameters
387
std::map<std::string, std::string> myParameters;
388
389
/// @brief parent IDs
390
std::map<const SumoXMLTag, std::string> myParentIDs;
391
392
/// @brief SumoBaseObject children
393
std::vector<SumoBaseObject*> mySumoBaseObjectChildren;
394
395
/// @brief vehicle class
396
SUMOVehicleClass myVClass = SVC_IGNORING;
397
398
/// @brief vehicle type parameter
399
SUMOVTypeParameter myVehicleTypeParameter;
400
401
/// @brief vehicle parameter
402
SUMOVehicleParameter myVehicleParameter;
403
404
/// @brief stop parameter
405
SUMOVehicleParameter::Stop myStopParameter;
406
407
/// @brief plan parameters
408
CommonXMLStructure::PlanParameters myPlanParameters;
409
410
/// @brief add SumoBaseObject child
411
void addSumoBaseObjectChild(SumoBaseObject* sumoBaseObject);
412
413
/// @brief remove SumoBaseObject child
414
void removeSumoBaseObjectChild(SumoBaseObject* sumoBaseObject);
415
416
private:
417
/// @brief flag for defined vehicle type parameter
418
bool myDefinedVehicleTypeParameter = false;
419
420
/// @brief @brief flag for defined vehicle parameter
421
bool myDefinedVehicleParameter = false;
422
423
/// @brief @brief flag for defined stop parameter
424
bool myDefinedStopParameter = false;
425
426
/// @brief handle attribute error
427
void handleAttributeError(const SumoXMLAttr attr, const std::string& type) const;
428
429
/// @brief invalidate copy constructor
430
SumoBaseObject(const SumoBaseObject& s) = delete;
431
432
/// @brief invalidate assignment operator
433
SumoBaseObject& operator=(const SumoBaseObject& s) = delete;
434
};
435
436
/// @brief Constructor
437
CommonXMLStructure();
438
439
/// @brief Destructor
440
~CommonXMLStructure();
441
442
/// @brief open SUMOBaseOBject
443
void openSUMOBaseOBject();
444
445
/// @brief close SUMOBaseOBject
446
void closeSUMOBaseOBject();
447
448
/// @brief abort SUMOBaseOBject
449
void abortSUMOBaseOBject();
450
451
/// @brief get SumoBaseObject root
452
CommonXMLStructure::SumoBaseObject* getSumoBaseObjectRoot() const;
453
454
/// @brief get current editedSumoBaseObject
455
CommonXMLStructure::SumoBaseObject* getCurrentSumoBaseObject() const;
456
457
protected:
458
/// @brief SumoBaseObject root
459
CommonXMLStructure::SumoBaseObject* mySumoBaseObjectRoot;
460
461
/// @brief last inserted SumoBaseObject
462
CommonXMLStructure::SumoBaseObject* myCurrentSumoBaseObject;
463
464
private:
465
/// @brief invalidate copy constructor
466
CommonXMLStructure(const CommonXMLStructure& s) = delete;
467
468
/// @brief invalidate assignment operator
469
CommonXMLStructure& operator=(const CommonXMLStructure& s) = delete;
470
};
471
472