SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GNEAttributeCarrier.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // Abstract Base class for gui objects which carry attributes
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <algorithm>
34 #include "GNEAttributeCarrier.h"
35 #include "GNEUndoList.h"
36 
37 #ifdef CHECK_MEMORY_LEAKS
38 #include <foreign/nvwa/debug_new.h>
39 #endif // CHECK_MEMORY_LEAKS
40 
41 // ===========================================================================
42 // static members
43 // ===========================================================================
44 std::map<SumoXMLTag, std::vector<std::pair <SumoXMLAttr, std::string> > > GNEAttributeCarrier::_allowedAttributes;
45 std::vector<SumoXMLTag> GNEAttributeCarrier::myAllowedTags;
46 std::vector<SumoXMLTag> GNEAttributeCarrier::myAllowedNetElementTags;
47 std::vector<SumoXMLTag> GNEAttributeCarrier::myAllowedAdditionalTags;
48 std::set<SumoXMLAttr> GNEAttributeCarrier::myNumericalIntAttrs;
49 std::set<SumoXMLAttr> GNEAttributeCarrier::myNumericalFloatAttrs;
50 std::set<SumoXMLAttr> GNEAttributeCarrier::myListAttrs;
51 std::set<SumoXMLAttr> GNEAttributeCarrier::myUniqueAttrs;
52 std::map<SumoXMLTag, SumoXMLTag> GNEAttributeCarrier::myAllowedAdditionalWithParentTags;
53 std::map<SumoXMLTag, std::map<SumoXMLAttr, std::vector<std::string> > > GNEAttributeCarrier::myDiscreteChoices;
54 std::map<SumoXMLTag, std::map<SumoXMLAttr, std::string > > GNEAttributeCarrier::myAttrDefinitions;
55 
56 const std::string GNEAttributeCarrier::LOADED = "loaded";
57 const std::string GNEAttributeCarrier::GUESSED = "guessed";
58 const std::string GNEAttributeCarrier::MODIFIED = "modified";
59 const std::string GNEAttributeCarrier::APPROVED = "approved";
60 
61 // ===========================================================================
62 // method definitions
63 // ===========================================================================
65  myTag(tag) {
66 }
67 
68 
69 template<> int
70 GNEAttributeCarrier::parse(const std::string& string) {
71  return TplConvert::_str2int(string);
72 }
73 
74 
75 template<> SUMOReal
76 GNEAttributeCarrier::parse(const std::string& string) {
77  return TplConvert::_str2SUMOReal(string);
78 }
79 
80 
81 template<> bool
82 GNEAttributeCarrier::parse(const std::string& string) {
83  return TplConvert::_str2Bool(string);
84 }
85 
86 
87 bool
88 GNEAttributeCarrier::isValid(SumoXMLAttr key, const std::string& value) {
89  UNUSED_PARAMETER(value);
90  return std::find(getAttrs().begin(), getAttrs().end(), key) != getAttrs().end();
91 }
92 
93 
94 std::string
96  return toString(myTag);
97 }
98 
99 
102  return myTag;
103 }
104 
105 
106 std::vector<SumoXMLAttr>
108  std::vector<SumoXMLAttr> attr;
109  for (std::vector<std::pair <SumoXMLAttr, std::string> >::const_iterator i = allowedAttributes(myTag).begin(); i != allowedAttributes(myTag).end(); i++) {
110  attr.push_back(i->first);
111  }
112  return attr;
113 }
114 
115 
116 const std::string
118  return getAttribute(SUMO_ATTR_ID);
119 }
120 
121 
124  if (hasParent(tag)) {
126  } else {
127  return SUMO_TAG_NOTHING;
128  }
129 }
130 
131 
132 bool
133 GNEAttributeCarrier::isValidID(const std::string& value) {
134  return value.find_first_of(" \t\n\r@$%^&/|\\{}*'\";:<>") == std::string::npos;
135 }
136 
137 
138 bool
139 GNEAttributeCarrier::isValidFileValue(const std::string& value) {
140  // @note Only characteres that aren't permited in a file path or belong
141  // to XML sintax
142  return value.find_first_of("\t\n\r@$%^&|\\{}*'\";:<>") == std::string::npos;
143 }
144 
145 
146 bool
147 GNEAttributeCarrier::isValidStringVector(const std::string& value) {
148  // 1) check if value is empty
149  if (value.empty()) {
150  return true;
151  }
152  // 2) Check if there are duplicated spaces
153  for (int i = 1; i < (int)value.size(); i++) {
154  if (value.at(i - 1) == ' ' && value.at(i) == ' ') {
155  return false;
156  }
157  }
158  // 3) Check if the first and last character aren't spaces
159  if ((value.at(0) == ' ') || (value.at(value.size() - 1) == ' ')) {
160  return false;
161  }
162  // 4) Check if every sub-string is valid
163  int index = 0;
164  std::string subString;
165  while (index < (int)value.size()) {
166  if (value.at(index) == ' ') {
167  if (!isValidFileValue(subString)) {
168  return false;
169  } else {
170  subString.clear();
171  }
172  } else {
173  subString.push_back(value.at(index));
174  }
175  index++;
176  }
177  // 5) All right, then return true
178  return true;
179 }
180 
181 // ===========================================================================
182 // static methods
183 // ===========================================================================
184 
185 const std::vector<std::pair <SumoXMLAttr, std::string> >&
187  // define on first access
188  if (!_allowedAttributes.count(tag)) {
189  std::vector<std::pair<SumoXMLAttr, std::string> >& attrs = _allowedAttributes[tag];
190  switch (tag) {
191  case SUMO_TAG_EDGE:
192  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
193  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FROM, ""));
194  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TO, ""));
195  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_SPEED, ""));
196  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PRIORITY, ""));
197  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_NUMLANES, ""));
198  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TYPE, ""));
199  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ALLOW, ""));
200  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_DISALLOW, ""));
201  //attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PREFER, ));
202  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_SHAPE, ""));
203  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LENGTH, ""));
204  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_SPREADTYPE, ""));
205  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_NAME, ""));
206  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_WIDTH, ""));
207  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ENDOFFSET, ""));
208  break;
209  case SUMO_TAG_JUNCTION:
210  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
211  /* virtual attribute from the combination of the actuall
212  * attributes SUMO_ATTR_X, SUMO_ATTR_Y */
213  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
214  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TYPE, ""));
215  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_SHAPE, ""));
216  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_RADIUS, ""));
217  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_KEEP_CLEAR, ""));
218  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TLTYPE, ""));
219  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TLID, ""));
220  break;
221  case SUMO_TAG_LANE:
222  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
223  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_SPEED, ""));
224  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ALLOW, ""));
225  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_DISALLOW, ""));
226  //attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PREFER, ));
227  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_WIDTH, ""));
228  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ENDOFFSET, ""));
229  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_INDEX, "")); // read-only attribute
230  break;
231  case SUMO_TAG_POI:
232  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
233  /* virtual attribute from the combination of the actuall
234  * attributes SUMO_ATTR_X, SUMO_ATTR_Y */
235  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
236  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TYPE, ""));
237  break;
238  case SUMO_TAG_CROSSING:
239  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
240  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PRIORITY, ""));
241  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_WIDTH, ""));
242  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EDGES, ""));
243  break;
244  case SUMO_TAG_CONNECTION:
245  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FROM, ""));
246  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TO, ""));
247  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FROM_LANE, ""));
248  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TO_LANE, ""));
249  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PASS, "false"));
250  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_KEEP_CLEAR, "false"));
251  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CONTPOS, "0"));
252  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_UNCONTROLLED, "false"));
253  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_VISIBILITY_DISTANCE, "4.5"));
254  break;
255  case SUMO_TAG_BUS_STOP:
256  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
257  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
258  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_STARTPOS, ""));
259  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ENDPOS, "10"));
260  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LINES, ""));
261  break;
263  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
264  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
265  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_STARTPOS, ""));
266  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ENDPOS, "10"));
267  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LINES, ""));
268  break;
270  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
271  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
272  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_STARTPOS, ""));
273  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ENDPOS, "10"));
274  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CHARGINGPOWER, "22000"));
275  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EFFICIENCY, "0.95"));
276  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CHARGEINTRANSIT, "false"));
277  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CHARGEDELAY, "0"));
278  break;
279  case SUMO_TAG_E1DETECTOR:
280  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
281  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
282  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
283  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
284  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
285  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_SPLIT_VTYPE, "false"));
286  break;
287  case SUMO_TAG_E2DETECTOR:
288  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
289  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
290  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
291  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LENGTH, "10"));
292  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
293  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
294  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CONT, "false"));
295  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_HALTING_TIME_THRESHOLD, "1"));
296  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, "1.39"));
297  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_JAM_DIST_THRESHOLD, "10"));
298  break;
299  case SUMO_TAG_E3DETECTOR:
300  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
301  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
302  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
303  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_HALTING_TIME_THRESHOLD, "1"));
304  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, "1.39"));
305  break;
306  case SUMO_TAG_DET_ENTRY:
307  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
308  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
309  break;
310  case SUMO_TAG_DET_EXIT:
311  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
312  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
313  break;
314  case SUMO_TAG_VSS:
315  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
316  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANES, ""));
317  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
318  break;
319  case SUMO_TAG_CALIBRATOR:
320  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
321  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
322  // Currently unused attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
323  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
324  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ROUTEPROBE, ""));
325  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_OUTPUT, ""));
326  break;
327  case SUMO_TAG_REROUTER:
328  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
329  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EDGES, ""));
330  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
331  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PROB, "1"));
332  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_OFF, "false"));
333  break;
334  case SUMO_TAG_ROUTEPROBE:
335  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
336  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EDGE, ""));
337  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
338  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
339  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_BEGIN, "0"));
340  break;
341  case SUMO_TAG_VAPORIZER:
342  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EDGE, ""));
343  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_STARTTIME, "0"));
344  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_END, "10"));
345  break;
346  default:
347  WRITE_WARNING("allowed attributes for tag '" + toString(tag) + "' not defined");
348  }
349  }
350  return _allowedAttributes[tag];
351 }
352 
353 
354 const std::vector<SumoXMLTag>&
356  // define on first access
357  if (myAllowedTags.empty()) {
358  myAllowedTags.push_back(SUMO_TAG_JUNCTION);
359  myAllowedTags.push_back(SUMO_TAG_EDGE);
360  myAllowedTags.push_back(SUMO_TAG_LANE);
362  myAllowedTags.push_back(SUMO_TAG_BUS_STOP);
369  myAllowedTags.push_back(SUMO_TAG_DET_EXIT);
370  myAllowedTags.push_back(SUMO_TAG_VSS);
372  myAllowedTags.push_back(SUMO_TAG_REROUTER);
375  }
376  return myAllowedTags;
377 }
378 
379 
380 const std::vector<SumoXMLTag>&
382  // define on first access
383  if (myAllowedNetElementTags.empty()) {
388  }
390 }
391 
392 
393 const std::vector<SumoXMLTag>&
395  // define on first access
396  if (myAllowedAdditionalTags.empty()) {
410  }
412 }
413 
414 
415 bool
417  return (isInt(attr) || isFloat(attr));
418 }
419 
420 
421 bool
423  // define on first access
424  if (myNumericalIntAttrs.empty()) {
434  }
435  return myNumericalIntAttrs.count(attr) == 1;
436 }
437 
438 
439 bool
441  // define on first access
442  if (myNumericalFloatAttrs.empty()) {
458  }
459  return myNumericalFloatAttrs.count(attr) == 1;
460 }
461 
462 
463 bool
465  // Iterate over additional tags
466  for (std::vector<SumoXMLTag>::const_iterator i = allowedTags().begin(); i != allowedTags().end(); i++) {
467  // Obtain choices
468  std::vector<std::string> choices = discreteChoices(*i, attr);
469  // CHeck if choices are exactly "true" and "false"
470  if ((choices.size() == 2) && (choices.at(0) == "true") && (choices.at(1) == "false")) {
471  return true;
472  }
473  }
474  return false;
475 }
476 
477 
478 bool
480  return (!isNumerical(attr) && !isBool(attr) && !isFloat(attr));
481 }
482 
483 
484 bool
486  // define on first access
487  if (myListAttrs.empty()) {
491  }
492  return myListAttrs.count(attr) == 1;
493 }
494 
495 
496 bool
498  // define on first access
499  if (myUniqueAttrs.empty()) {
500  myUniqueAttrs.insert(SUMO_ATTR_ID);
502  myUniqueAttrs.insert(SUMO_ATTR_TO);
513  }
514  return myUniqueAttrs.count(attr) == 1;
515 }
516 
517 
518 bool
520  if (discreteChoices(tag, attr).size() > 0) {
521  return true;
522  } else {
523  return false;
524  }
525 }
526 
527 
528 bool
530  // define on first access
531  if (myAllowedAdditionalWithParentTags.empty()) {
534  }
535  return myAllowedAdditionalWithParentTags.count(tag) == 1;
536 }
537 
538 
539 bool
541  const std::vector<std::pair <SumoXMLAttr, std::string> >& attrs = allowedAttributes(tag);
542  for (std::vector<std::pair <SumoXMLAttr, std::string> >::const_iterator i = attrs.begin(); i != attrs.end(); i++) {
543  if (i->first == attr) {
544  return true;
545  }
546  }
547  return false;
548 }
549 
550 
551 const std::vector<std::string>&
553  // define on first access
554  if (myDiscreteChoices.empty()) {
555  std::vector<std::string> choices;
557  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
560  }
561  }
562 
564  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
565  if (*it != toString(TLTYPE_INVALID)) {
567  }
568  }
569 
572 
574  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
576  }
577 
578  choices = SumoVehicleClassStrings.getStrings();
579  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
584  }
585 
588 
591 
594 
597 
600 
603 
606 
609  }
610 
611  return myDiscreteChoices[tag][attr];
612 }
613 
614 
615 bool
617  return (attr == SUMO_ATTR_ALLOW || attr == SUMO_ATTR_DISALLOW);
618 }
619 
620 
621 std::string
623  // define on first access
624  if (myAttrDefinitions.empty()) {
625  // Edge
626  myAttrDefinitions[SUMO_TAG_EDGE][SUMO_ATTR_ID] = "ID (Must be unique)";
642  // Junction
643  myAttrDefinitions[SUMO_TAG_JUNCTION][SUMO_ATTR_ID] = "ID (Must be unique)";
651  // Lane
652  myAttrDefinitions[SUMO_TAG_LANE][SUMO_ATTR_ID] = "ID (Must be unique)";
660  // POI
661  myAttrDefinitions[SUMO_TAG_POI][SUMO_ATTR_ID] = "ID (Must be unique)";
664  // Crossing
665  myAttrDefinitions[SUMO_TAG_CROSSING][SUMO_ATTR_ID] = "ID (Must be unique)";
669  // Connection
670  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_FROM] = "The name of the edge the vehicles leave ";
671  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_TO] = "The name of the edge the vehicles may reach when leaving 'from'";
672  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_FROM_LANE] = "the lane index of the incoming lane (numbers starting with 0)";
673  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_TO_LANE] = "the lane index of the outgoing lane (numbers starting with 0)";
674  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_PASS] = "if set, vehicles which pass this (lane-2-lane) connection) will not wait";
675  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_KEEP_CLEAR] = "if set to false, vehicles which pass this (lane-2-lane) connection) will not worry about blocking the intersection.";
676  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_CONTPOS] = "If set to a more than 0 value, an internal junction will be built at this position (in m) from the start of the internal lane for this connection.";
677  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_UNCONTROLLED] = "if set to true, This connection will not be TLS-controlled despite its node being controlled.";
678  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_VISIBILITY_DISTANCE] = "sets the distance to the connection at which all relevant foes are visible.";
679  // Bus Stop
680  myAttrDefinitions[SUMO_TAG_BUS_STOP][SUMO_ATTR_ID] = "ID (Must be unique)";
681  myAttrDefinitions[SUMO_TAG_BUS_STOP][SUMO_ATTR_LANE] = "The name of the lane the bus stop shall be located at";
682  myAttrDefinitions[SUMO_TAG_BUS_STOP][SUMO_ATTR_STARTPOS] = "The begin position on the lane (the lower position on the lane) in meters";
683  myAttrDefinitions[SUMO_TAG_BUS_STOP][SUMO_ATTR_ENDPOS] = "The end position on the lane (the higher position on the lane) in meters, must be larger than startPos by more than 0.1m";
684  myAttrDefinitions[SUMO_TAG_BUS_STOP][SUMO_ATTR_LINES] = "meant to be the names of the bus lines that stop at this bus stop. This is only used for visualization purposes";
685  // container Stop
686  myAttrDefinitions[SUMO_TAG_CONTAINER_STOP][SUMO_ATTR_ID] = "ID (Must be unique)";
687  myAttrDefinitions[SUMO_TAG_CONTAINER_STOP][SUMO_ATTR_LANE] = "The name of the lane the container stop shall be located at";
688  myAttrDefinitions[SUMO_TAG_CONTAINER_STOP][SUMO_ATTR_STARTPOS] = "The begin position on the lane (the lower position on the lane) in meters";
689  myAttrDefinitions[SUMO_TAG_CONTAINER_STOP][SUMO_ATTR_ENDPOS] = "The end position on the lane (the higher position on the lane) in meters, must be larger than startPos by more than 0.1m";
690  myAttrDefinitions[SUMO_TAG_CONTAINER_STOP][SUMO_ATTR_LINES] = "meant to be the names of the bus lines that stop at this container stop. This is only used for visualization purposes";
691  // Charging Station
692  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_ID] = "ID (Must be unique)";
693  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_LANE] = "Lane of the charging station location";
694  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_STARTPOS] = "Begin position in the specified lane";
695  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_ENDPOS] = "End position in the specified lane";
697  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_EFFICIENCY] = "Charging efficiency [0,1]";
698  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_CHARGEINTRANSIT] = "Enable or disable charge in transit, i.e. vehicle must or must not to stop for charging";
699  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_CHARGEDELAY] = "Time delay after the vehicles has reached / stopped on the charging station, before the energy transfer (charging) begins";
700  // E1
701  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_ID] = "ID (Must be unique)";
702  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_LANE] = "The id of the lane the detector shall be laid on. The lane must be a part of the network used";
703  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_POSITION] = "The position on the lane the detector shall be laid on in meters. The position must be a value between -1*lane's length and the lane's length";
704  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_FREQUENCY] = "The aggregation period the values the detector collects shall be summed up";
705  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_FILE] = "The path to the output file";
706  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_SPLIT_VTYPE] = "If set, the collected values will be additionally reported on per-vehicle type base, see below";
707  // E2
708  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_ID] = "ID (Must be unique)";
709  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_LANE] = "The id of the lane the detector shall be laid on. The lane must be a part of the network used";
710  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_POSITION] = "The position on the lane the detector shall be laid on in meters";
711  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_LENGTH] = "The length of the detector in meters";
712  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_FREQUENCY] = "The aggregation period the values the detector collects shall be summed up";
713  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_FILE] = "The path to the output file";
714  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_CONT] = "Holds the information whether detectors longer than a lane shall be cut off or continued (set it to true for the second case); default: false";
715  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_HALTING_TIME_THRESHOLD] = "The time-based threshold that describes how much time has to pass until a vehicle is recognized as halting; in s, default: 1s";
716  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_HALTING_SPEED_THRESHOLD] = "The speed-based threshold that describes how slow a vehicle has to be to be recognized as halting; in m/s, default: 5/3.6m/s";
717  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_JAM_DIST_THRESHOLD] = "The minimum distance to the next standing vehicle in order to make this vehicle count as a participant to the jam; in m, default: 10m";
718  // E3
719  myAttrDefinitions[SUMO_TAG_E3DETECTOR][SUMO_ATTR_ID] = "ID (Must be unique)";
720  myAttrDefinitions[SUMO_TAG_E3DETECTOR][SUMO_ATTR_FREQUENCY] = "The aggregation period the values the detector collects shall be summed up";
721  myAttrDefinitions[SUMO_TAG_E3DETECTOR][SUMO_ATTR_FILE] = "The path to the output file";
722  // Entry
723  myAttrDefinitions[SUMO_TAG_DET_ENTRY][SUMO_ATTR_LANE] = "The id of the lane the detector shall be laid on. The lane must be a part of the network used";
724  myAttrDefinitions[SUMO_TAG_DET_ENTRY][SUMO_ATTR_POSITION] = "The position on the lane the detector shall be laid on in meters";
725  // Exit
726  myAttrDefinitions[SUMO_TAG_DET_EXIT][SUMO_ATTR_LANE] = "The id of the lane the detector shall be laid on. The lane must be a part of the network used";
727  myAttrDefinitions[SUMO_TAG_DET_EXIT][SUMO_ATTR_POSITION] = "The position on the lane the detector shall be laid on in meters";
728  // Variable Speed Signal
729  myAttrDefinitions[SUMO_TAG_VSS][SUMO_ATTR_ID] = "ID (Must be unique)";
730  myAttrDefinitions[SUMO_TAG_VSS][SUMO_ATTR_LANES] = "list of lanes of Variable Speed Signal";
731  myAttrDefinitions[SUMO_TAG_VSS][SUMO_ATTR_FILE] = "The path to the output file";
732  // Calibrator
733  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_ID] = "ID (Must be unique)";
734  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_LANE] = "List of lanes of calibrator";
735  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_POSITION] = "The position of the calibrator on the specified lane";
736  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_FREQUENCY] = "The aggregation interval in which to calibrate the flows. default is step-length";
737  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_ROUTEPROBE] = "The id of the routeProbe element from which to determine the route distribution for generated vehicles";
738  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_OUTPUT] = "The output file for writing calibrator information or NULL";
739  // Rerouter
740  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_ID] = "ID (Must be unique)";
741  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_EDGES] = "An edge id or a list of edge ids where vehicles shall be rerouted";
742  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_FILE] = "The path to the definition file (alternatively, the intervals may defined as children of the rerouter)";
743  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_PROB] = "The probability for vehicle rerouting (0-1), default 1";
744  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_OFF] = "Whether the router should be inactive initially (and switched on in the gui), default:false";
745  // SUMO_TAG_ROUTEPROBE
746  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_ID] = "ID (Must be unique)";
747  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_EDGE] = "The id of an edge in the simulation network";
748  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_FREQUENCY] = "The frequency in which to report the distribution";
749  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_FILE] = "The file for generated output";
750  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_BEGIN] = "The time at which to start generating output";
751  }
752  return myAttrDefinitions[tag][attr];
753 }
754 
755 
756 int
758  int higherNumber = 0;
759  for (std::vector<SumoXMLTag>::const_iterator i = allowedTags().begin(); i != allowedTags().end(); i++) {
760  if ((int)allowedAttributes(*i).size() > higherNumber) {
761  higherNumber = (int)allowedAttributes(*i).size();
762  }
763  }
764  return higherNumber;
765 }
766 
767 
768 template<> int
770  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
771  if ((*i).first == attr) {
772  return TplConvert::_str2int((*i).second);
773  }
774  }
775  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
776  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
777  return 0;
778 }
779 
780 
781 template<> SUMOReal
783  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
784  if ((*i).first == attr) {
785  return TplConvert::_str2SUMOReal((*i).second);
786  }
787  }
788  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
789  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
790  return 0;
791 }
792 
793 
794 template<> bool
796  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
797  if ((*i).first == attr) {
798  return TplConvert::_str2Bool((*i).second);
799  }
800  }
801  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
802  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
803  return false;
804 }
805 
806 
807 template<> std::string
809  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
810  if ((*i).first == attr) {
811  return (*i).second;
812  }
813  }
814  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
815  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
816  return "";
817 }
818 
819 
820 template<> std::vector<int>
822  std::cout << "FINISH" << std::endl;
823 
824  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
825  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
826  return std::vector<int>();
827 }
828 
829 
830 template<> std::vector<SUMOReal>
832  std::cout << "FINISH" << std::endl;
833 
834  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
835  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
836  return std::vector<SUMOReal>();
837 }
838 
839 
840 template<> std::vector<bool>
842  std::cout << "FINISH" << std::endl;
843 
844  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
845  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
846  return std::vector<bool>();
847 }
848 
849 
850 template<> std::vector<std::string>
852  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
853  if ((*i).first == attr) {
854  std::vector<std::string> myVectorString;
855  SUMOSAXAttributes::parseStringVector((*i).second, myVectorString);
856  return myVectorString;
857  }
858  }
859  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
860  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
861  return std::vector<std::string>();
862 }
863 
864 /****************************************************************************/
865 
static bool isList(SumoXMLAttr attr)
whether an attribute is of type bool
static bool _str2Bool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter ...
Definition: TplConvert.h:382
The information about how to spread the lanes from the given position.
SumoXMLTag
Numbers representing SUMO-XML - element names.
static std::set< SumoXMLAttr > myUniqueAttrs
set with the unique attributes (i.e. attributes without default values)
static StringBijection< SumoXMLNodeType > NodeTypes
static SUMOReal _str2SUMOReal(const std::string &sData)
converts a string into the SUMOReal value described by it by calling the char-type converter ...
Definition: TplConvert.h:341
Whether vehicles must keep the junction clear.
static bool isNumerical(SumoXMLAttr attr)
whether an attribute is numerical (int or float)
const SumoXMLTag myTag
the xml tag to which this carrier corresponds
std::vector< SumoXMLAttr > getAttrs() const
get vector of attributes
static std::map< SumoXMLTag, std::map< SumoXMLAttr, std::string > > myAttrDefinitions
map with the definition of attributes
static bool isDiscrete(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is Discrete
static StringBijection< LaneSpreadFunction > LaneSpreadFunctions
static std::map< SumoXMLTag, std::map< SumoXMLAttr, std::vector< std::string > > > myDiscreteChoices
map with the values of discrete choices
foe visibility distance of a link
static const std::string LOADED
feature is still unchanged after being loaded (implies approval)
static int getHigherNumberOfAttributes()
return the number of attributes of the tag with the most highter number of attributes ...
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static std::map< SumoXMLTag, std::vector< std::pair< SumoXMLAttr, std::string > > > _allowedAttributes
map with the allowed attributes
static std::set< SumoXMLAttr > myNumericalFloatAttrs
set with the numerical attributes of type Float
virtual std::string getAttribute(SumoXMLAttr key) const =0
static const std::vector< std::pair< SumoXMLAttr, std::string > > & allowedAttributes(SumoXMLTag tag)
get all editable attributes for tag and their default values.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static std::vector< SumoXMLTag > myAllowedNetElementTags
vector with the allowed tags of netElements
std::vector< std::string > getStrings() const
static const std::vector< std::string > & discreteChoices(SumoXMLTag tag, SumoXMLAttr attr)
return a list of discrete choices for this attribute or an empty vector
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
static const std::string MODIFIED
feature has been manually modified (implies approval)
static void parseStringVector(const std::string &def, std::vector< std::string > &into)
Splits the given string.
The turning radius at an intersection in m.
static bool isValidFileValue(const std::string &value)
true if value is a valid file value
static std::vector< SumoXMLTag > myAllowedAdditionalTags
vector with the allowed tags of additionals
static std::vector< SumoXMLTag > myAllowedTags
vector with the allowed tags
the edges of a route
static bool hasAttribute(SumoXMLTag tag, SumoXMLAttr attr)
check if a element with certain tag has a certain attribute
static const std::vector< SumoXMLTag > & allowedTags()
get all editable for tag.
static StringBijection< TrafficLightType > TrafficLightTypes
static bool hasParent(SumoXMLTag tag)
check if a element with certain tag has another additional element as parent
static int _str2int(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
Definition: TplConvert.h:160
virtual std::string getDescription()
how should this attribute carrier be called
static T getDefaultValue(SumoXMLTag tag, SumoXMLAttr attr)
return the default value of the attribute of an element
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
const std::string getID() const
function to support debugging
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
static bool isFloat(SumoXMLAttr attr)
whether an attribute is numerical of type float
GNEAttributeCarrier(SumoXMLTag tag)
Constructor.
static bool isValidStringVector(const std::string &value)
true if value is a valid string vector
static const std::vector< SumoXMLTag > & allowedAdditionalTags()
get all editable tags for additionals
static bool isInt(SumoXMLAttr attr)
whether an attribute is numerical or type int
static const std::string APPROVED
feature has been approved but not changed (i.e. after being reguessed)
static const std::vector< SumoXMLTag > & allowedNetElementTags()
get all editable tags for netElements
static std::string getDefinition(SumoXMLTag tag, SumoXMLAttr attr)
return definition of a certain SumoXMLAttr
static bool discreteCombinableChoices(SumoXMLTag tag, SumoXMLAttr attr)
return whether the given attribute allows for a combination of discrete values
static SumoXMLTag getParentType(SumoXMLTag tag)
get parent's tag of a certain additional element
SumoXMLTag getTag() const
get Tag assigned to this object
A variable speed sign.
#define SUMOReal
Definition: config.h:214
static const std::string GUESSED
feature has been reguessed (may still be unchanged be we can't tell (yet)
static bool isUnique(SumoXMLAttr attr)
whether an attribute is unique (may not be edited for a multi-selection)
static bool isString(SumoXMLAttr attr)
whether an attribute is of type string
virtual bool isValid(SumoXMLAttr key, const std::string &value)
Information whether the detector shall be continued on the folowing lanes.
static T parse(const std::string &string)
parses a number of type T from string
static bool isBool(SumoXMLAttr attr)
whether an attribute is of type bool
static std::set< SumoXMLAttr > myListAttrs
set with the attributes of type list
static std::map< SumoXMLTag, SumoXMLTag > myAllowedAdditionalWithParentTags
map with the allowed tags of additionals with parent and their parent
static std::set< SumoXMLAttr > myNumericalIntAttrs
set with the numerical attributes of type Int