SUMO - Simulation of Urban MObility
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  break;
219  case SUMO_TAG_LANE:
220  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
221  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_SPEED, ""));
222  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ALLOW, ""));
223  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_DISALLOW, ""));
224  //attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PREFER, ));
225  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_WIDTH, ""));
226  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ENDOFFSET, ""));
227  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_INDEX, "")); // read-only attribute
228  break;
229  case SUMO_TAG_POI:
230  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
231  /* virtual attribute from the combination of the actuall
232  * attributes SUMO_ATTR_X, SUMO_ATTR_Y */
233  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
234  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TYPE, ""));
235  break;
236  case SUMO_TAG_CROSSING:
237  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
238  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PRIORITY, ""));
239  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_WIDTH, ""));
240  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EDGES, ""));
241  break;
242  case SUMO_TAG_CONNECTION:
243  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FROM, ""));
244  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TO, ""));
245  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FROM_LANE, ""));
246  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_TO_LANE, ""));
247  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PASS, "false"));
248  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_KEEP_CLEAR, "false"));
249  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CONTPOS, "0"));
250  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_UNCONTROLLED, "false"));
251  break;
252  case SUMO_TAG_BUS_STOP:
253  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
254  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
255  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_STARTPOS, ""));
256  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ENDPOS, "10"));
257  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LINES, ""));
258  break;
260  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
261  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
262  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_STARTPOS, ""));
263  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ENDPOS, "10"));
264  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LINES, ""));
265  break;
267  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
268  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
269  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_STARTPOS, ""));
270  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ENDPOS, "10"));
271  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CHARGINGPOWER, "22000"));
272  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EFFICIENCY, "0.95"));
273  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CHARGEINTRANSIT, "false"));
274  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CHARGEDELAY, "0"));
275  break;
276  case SUMO_TAG_E1DETECTOR:
277  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
278  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
279  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
280  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
281  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
282  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_SPLIT_VTYPE, "false"));
283  break;
284  case SUMO_TAG_E2DETECTOR:
285  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
286  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
287  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
288  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LENGTH, "10"));
289  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
290  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
291  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_CONT, "false"));
292  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_HALTING_TIME_THRESHOLD, "1"));
293  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, "1.39"));
294  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_JAM_DIST_THRESHOLD, "10"));
295  break;
296  case SUMO_TAG_E3DETECTOR:
297  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
298  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
299  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
300  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_HALTING_TIME_THRESHOLD, "1"));
301  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_HALTING_SPEED_THRESHOLD, "1.39"));
302  break;
303  case SUMO_TAG_DET_ENTRY:
304  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
305  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
306  break;
307  case SUMO_TAG_DET_EXIT:
308  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
309  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
310  break;
311  case SUMO_TAG_VSS:
312  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
313  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANES, ""));
314  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
315  break;
316  case SUMO_TAG_CALIBRATOR:
317  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
318  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_LANE, ""));
319  // Currently unused attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_POSITION, ""));
320  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
321  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ROUTEPROBE, ""));
322  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_OUTPUT, ""));
323  break;
324  case SUMO_TAG_REROUTER:
325  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
326  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EDGES, ""));
327  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
328  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_PROB, "1"));
329  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_OFF, "false"));
330  break;
331  case SUMO_TAG_ROUTEPROBE:
332  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_ID, ""));
333  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EDGE, ""));
334  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FREQUENCY, "100"));
335  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_FILE, ""));
336  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_BEGIN, "0"));
337  break;
338  case SUMO_TAG_VAPORIZER:
339  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_EDGE, ""));
340  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_STARTTIME, "0"));
341  attrs.push_back(std::pair<SumoXMLAttr, std::string>(SUMO_ATTR_END, "10"));
342  break;
343  default:
344  WRITE_WARNING("allowed attributes for tag '" + toString(tag) + "' not defined");
345  }
346  }
347  return _allowedAttributes[tag];
348 }
349 
350 
351 const std::vector<SumoXMLTag>&
353  // define on first access
354  if (myAllowedTags.empty()) {
355  myAllowedTags.push_back(SUMO_TAG_JUNCTION);
356  myAllowedTags.push_back(SUMO_TAG_EDGE);
357  myAllowedTags.push_back(SUMO_TAG_LANE);
359  myAllowedTags.push_back(SUMO_TAG_BUS_STOP);
366  myAllowedTags.push_back(SUMO_TAG_DET_EXIT);
367  myAllowedTags.push_back(SUMO_TAG_VSS);
369  myAllowedTags.push_back(SUMO_TAG_REROUTER);
372  }
373  return myAllowedTags;
374 }
375 
376 
377 const std::vector<SumoXMLTag>&
379  // define on first access
380  if (myAllowedNetElementTags.empty()) {
385  }
387 }
388 
389 
390 const std::vector<SumoXMLTag>&
392  // define on first access
393  if (myAllowedAdditionalTags.empty()) {
407  }
409 }
410 
411 
412 bool
414  return (isInt(attr) || isFloat(attr));
415 }
416 
417 
418 bool
420  // define on first access
421  if (myNumericalIntAttrs.empty()) {
431  }
432  return myNumericalIntAttrs.count(attr) == 1;
433 }
434 
435 
436 bool
438  // define on first access
439  if (myNumericalFloatAttrs.empty()) {
454  }
455  return myNumericalFloatAttrs.count(attr) == 1;
456 }
457 
458 
459 bool
461  // Iterate over additional tags
462  for (std::vector<SumoXMLTag>::const_iterator i = allowedTags().begin(); i != allowedTags().end(); i++) {
463  // Obtain choices
464  std::vector<std::string> choices = discreteChoices(*i, attr);
465  // CHeck if choices are exactly "true" and "false"
466  if ((choices.size() == 2) && (choices.at(0) == "true") && (choices.at(1) == "false")) {
467  return true;
468  }
469  }
470  return false;
471 }
472 
473 
474 bool
476  return (!isNumerical(attr) && !isBool(attr) && !isFloat(attr));
477 }
478 
479 
480 bool
482  // define on first access
483  if (myListAttrs.empty()) {
487  }
488  return myListAttrs.count(attr) == 1;
489 }
490 
491 
492 bool
494  // define on first access
495  if (myUniqueAttrs.empty()) {
496  myUniqueAttrs.insert(SUMO_ATTR_ID);
498  myUniqueAttrs.insert(SUMO_ATTR_TO);
509  }
510  return myUniqueAttrs.count(attr) == 1;
511 }
512 
513 
514 bool
516  if (discreteChoices(tag, attr).size() > 0) {
517  return true;
518  } else {
519  return false;
520  }
521 }
522 
523 
524 bool
526  // define on first access
527  if (myAllowedAdditionalWithParentTags.empty()) {
530  }
531  return myAllowedAdditionalWithParentTags.count(tag) == 1;
532 }
533 
534 
535 bool
537  const std::vector<std::pair <SumoXMLAttr, std::string> >& attrs = allowedAttributes(tag);
538  for (std::vector<std::pair <SumoXMLAttr, std::string> >::const_iterator i = attrs.begin(); i != attrs.end(); i++) {
539  if (i->first == attr) {
540  return true;
541  }
542  }
543  return false;
544 }
545 
546 
547 const std::vector<std::string>&
549  // define on first access
550  if (myDiscreteChoices.empty()) {
551  std::vector<std::string> choices;
553  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
556  }
557  }
558 
561 
563  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
565  }
566 
567  choices = SumoVehicleClassStrings.getStrings();
568  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
573  }
574 
577 
580 
583 
586 
589 
592 
595  }
596 
597  return myDiscreteChoices[tag][attr];
598 }
599 
600 
601 bool
603  return (attr == SUMO_ATTR_ALLOW || attr == SUMO_ATTR_DISALLOW);
604 }
605 
606 
607 std::string
609  // define on first access
610  if (myAttrDefinitions.empty()) {
611  // Edge
612  myAttrDefinitions[SUMO_TAG_EDGE][SUMO_ATTR_ID] = "ID (Must be unique)";
628  // Junction
629  myAttrDefinitions[SUMO_TAG_JUNCTION][SUMO_ATTR_ID] = "ID (Must be unique)";
635  // Lane
636  myAttrDefinitions[SUMO_TAG_LANE][SUMO_ATTR_ID] = "ID (Must be unique)";
644  // POI
645  myAttrDefinitions[SUMO_TAG_POI][SUMO_ATTR_ID] = "ID (Must be unique)";
648  // Crossing
649  myAttrDefinitions[SUMO_TAG_CROSSING][SUMO_ATTR_ID] = "ID (Must be unique)";
653  // Connection
654  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_FROM] = "The name of the edge the vehicles leave ";
655  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_TO] = "The name of the edge the vehicles may reach when leaving 'from'";
656  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_FROM_LANE] = "the lane index of the incoming lane (numbers starting with 0)";
657  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_TO_LANE] = "the lane index of the outgoing lane (numbers starting with 0)";
658  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_PASS] = "if set, vehicles which pass this (lane-2-lane) connection) will not wait";
659  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.";
660  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.";
661  myAttrDefinitions[SUMO_TAG_CONNECTION][SUMO_ATTR_UNCONTROLLED] = "if set to true, This connection will not be TLS-controlled despite its node being controlled.";
662  // Bus Stop
663  myAttrDefinitions[SUMO_TAG_BUS_STOP][SUMO_ATTR_ID] = "ID (Must be unique)";
664  myAttrDefinitions[SUMO_TAG_BUS_STOP][SUMO_ATTR_LANE] = "The name of the lane the bus stop shall be located at";
665  myAttrDefinitions[SUMO_TAG_BUS_STOP][SUMO_ATTR_STARTPOS] = "The begin position on the lane (the lower position on the lane) in meters";
666  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";
667  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";
668  // container Stop
669  myAttrDefinitions[SUMO_TAG_CONTAINER_STOP][SUMO_ATTR_ID] = "ID (Must be unique)";
670  myAttrDefinitions[SUMO_TAG_CONTAINER_STOP][SUMO_ATTR_LANE] = "The name of the lane the container stop shall be located at";
671  myAttrDefinitions[SUMO_TAG_CONTAINER_STOP][SUMO_ATTR_STARTPOS] = "The begin position on the lane (the lower position on the lane) in meters";
672  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";
673  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";
674  // Charging Station
675  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_ID] = "ID (Must be unique)";
676  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_LANE] = "Lane of the charging station location";
677  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_STARTPOS] = "Begin position in the specified lane";
678  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_ENDPOS] = "End position in the specified lane";
680  myAttrDefinitions[SUMO_TAG_CHARGING_STATION][SUMO_ATTR_EFFICIENCY] = "Charging efficiency [0,1]";
681  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";
682  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";
683  // E1
684  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_ID] = "ID (Must be unique)";
685  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";
686  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";
687  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_FREQUENCY] = "The aggregation period the values the detector collects shall be summed up";
688  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_FILE] = "The path to the output file";
689  myAttrDefinitions[SUMO_TAG_E1DETECTOR][SUMO_ATTR_SPLIT_VTYPE] = "If set, the collected values will be additionally reported on per-vehicle type base, see below";
690  // E2
691  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_ID] = "ID (Must be unique)";
692  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";
693  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_POSITION] = "The position on the lane the detector shall be laid on in meters";
694  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_LENGTH] = "The length of the detector in meters";
695  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_FREQUENCY] = "The aggregation period the values the detector collects shall be summed up";
696  myAttrDefinitions[SUMO_TAG_E2DETECTOR][SUMO_ATTR_FILE] = "The path to the output file";
697  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";
698  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";
699  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";
700  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";
701  // E3
702  myAttrDefinitions[SUMO_TAG_E3DETECTOR][SUMO_ATTR_ID] = "ID (Must be unique)";
703  myAttrDefinitions[SUMO_TAG_E3DETECTOR][SUMO_ATTR_FREQUENCY] = "The aggregation period the values the detector collects shall be summed up";
704  myAttrDefinitions[SUMO_TAG_E3DETECTOR][SUMO_ATTR_FILE] = "The path to the output file";
705  // Entry
706  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";
707  myAttrDefinitions[SUMO_TAG_DET_ENTRY][SUMO_ATTR_POSITION] = "The position on the lane the detector shall be laid on in meters";
708  // Exit
709  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";
710  myAttrDefinitions[SUMO_TAG_DET_EXIT][SUMO_ATTR_POSITION] = "The position on the lane the detector shall be laid on in meters";
711  // Variable Speed Signal
712  myAttrDefinitions[SUMO_TAG_VSS][SUMO_ATTR_ID] = "ID (Must be unique)";
713  myAttrDefinitions[SUMO_TAG_VSS][SUMO_ATTR_LANES] = "list of lanes of Variable Speed Signal";
714  myAttrDefinitions[SUMO_TAG_VSS][SUMO_ATTR_FILE] = "The path to the output file";
715  // Calibrator
716  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_ID] = "ID (Must be unique)";
717  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_LANE] = "List of lanes of calibrator";
718  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_POSITION] = "The position of the calibrator on the specified lane";
719  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_FREQUENCY] = "The aggregation interval in which to calibrate the flows. default is step-length";
720  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_ROUTEPROBE] = "The id of the routeProbe element from which to determine the route distribution for generated vehicles";
721  myAttrDefinitions[SUMO_TAG_CALIBRATOR][SUMO_ATTR_OUTPUT] = "The output file for writing calibrator information or NULL";
722  // Rerouter
723  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_ID] = "ID (Must be unique)";
724  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_EDGES] = "An edge id or a list of edge ids where vehicles shall be rerouted";
725  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_FILE] = "The path to the definition file (alternatively, the intervals may defined as children of the rerouter)";
726  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_PROB] = "The probability for vehicle rerouting (0-1), default 1";
727  myAttrDefinitions[SUMO_TAG_REROUTER][SUMO_ATTR_OFF] = "Whether the router should be inactive initially (and switched on in the gui), default:false";
728  // SUMO_TAG_ROUTEPROBE
729  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_ID] = "ID (Must be unique)";
730  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_EDGE] = "The id of an edge in the simulation network";
731  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_FREQUENCY] = "The frequency in which to report the distribution";
732  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_FILE] = "The file for generated output";
733  myAttrDefinitions[SUMO_TAG_ROUTEPROBE][SUMO_ATTR_BEGIN] = "The time at which to start generating output";
734  }
735  return myAttrDefinitions[tag][attr];
736 }
737 
738 
739 int
741  int higherNumber = 0;
742  for (std::vector<SumoXMLTag>::const_iterator i = allowedTags().begin(); i != allowedTags().end(); i++) {
743  if ((int)allowedAttributes(*i).size() > higherNumber) {
744  higherNumber = (int)allowedAttributes(*i).size();
745  }
746  }
747  return higherNumber;
748 }
749 
750 
751 template<> int
753  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
754  if ((*i).first == attr) {
755  return TplConvert::_str2int((*i).second);
756  }
757  }
758  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
759  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
760  return 0;
761 }
762 
763 
764 template<> SUMOReal
766  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
767  if ((*i).first == attr) {
768  return TplConvert::_str2SUMOReal((*i).second);
769  }
770  }
771  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
772  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
773  return 0;
774 }
775 
776 
777 template<> bool
779  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
780  if ((*i).first == attr) {
781  return TplConvert::_str2Bool((*i).second);
782  }
783  }
784  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
785  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
786  return false;
787 }
788 
789 
790 template<> std::string
792  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
793  if ((*i).first == attr) {
794  return (*i).second;
795  }
796  }
797  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
798  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
799  return "";
800 }
801 
802 
803 template<> std::vector<int>
805  std::cout << "FINISH" << std::endl;
806 
807  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
808  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
809  return std::vector<int>();
810 }
811 
812 
813 template<> std::vector<SUMOReal>
815  std::cout << "FINISH" << std::endl;
816 
817  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
818  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
819  return std::vector<SUMOReal>();
820 }
821 
822 
823 template<> std::vector<bool>
825  std::cout << "FINISH" << std::endl;
826 
827  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
828  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
829  return std::vector<bool>();
830 }
831 
832 
833 template<> std::vector<std::string>
835  for (std::vector<std::pair<SumoXMLAttr, std::string> >::iterator i = _allowedAttributes.at(tag).begin(); i != _allowedAttributes.at(tag).end(); i++) {
836  if ((*i).first == attr) {
837  std::vector<std::string> myVectorString;
838  SUMOSAXAttributes::parseStringVector((*i).second, myVectorString);
839  return myVectorString;
840  }
841  }
842  // Write warning if attribute don't have a default value and return a empty value to avoid warnings
843  WRITE_WARNING("attribute '" + toString(attr) + "' for tag '" + toString(tag) + "' don't have a default value");
844  return std::vector<std::string>();
845 }
846 
847 /****************************************************************************/
848 
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
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 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&#39;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:213
static const std::string GUESSED
feature has been reguessed (may still be unchanged be we can&#39;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