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>
33 #include "GNEAttributeCarrier.h"
34 #include "GNEUndoList.h"
35 
36 #ifdef CHECK_MEMORY_LEAKS
37 #include <foreign/nvwa/debug_new.h>
38 #endif // CHECK_MEMORY_LEAKS
39 
40 // ===========================================================================
41 // static members
42 // ===========================================================================
43 std::map<SumoXMLTag, std::vector<SumoXMLAttr> > GNEAttributeCarrier::_allowedAttributes;
44 std::vector<SumoXMLTag> GNEAttributeCarrier::_allowedTags;
45 std::set<SumoXMLAttr> GNEAttributeCarrier::_numericalAttrs;
46 std::set<SumoXMLAttr> GNEAttributeCarrier::_uniqueAttrs;
47 std::map<SumoXMLTag, std::map<SumoXMLAttr, std::vector<std::string> > > GNEAttributeCarrier::_discreteChoices;
48 
49 const std::string GNEAttributeCarrier::LOADED = "loaded";
50 const std::string GNEAttributeCarrier::GUESSED = "guessed";
51 const std::string GNEAttributeCarrier::MODIFIED = "modified";
52 const std::string GNEAttributeCarrier::APPROVED = "approved";
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58  myTag(tag) {
59 }
60 
61 
62 bool
63 GNEAttributeCarrier::isValid(SumoXMLAttr key, const std::string& value) {
64  UNUSED_PARAMETER(value);
65  return std::find(getAttrs().begin(), getAttrs().end(), key) != getAttrs().end();
66 }
67 
68 
69 bool
70 GNEAttributeCarrier::isValidID(const std::string& value) {
71  return value.find_first_of(" \t\n\r@$%^&/|\\{}*'\";:<>") == std::string::npos;
72 }
73 
74 
75 template<> int
76 GNEAttributeCarrier::parse(const std::string& string) {
77  return TplConvert::_str2int(string);
78 }
79 
80 
81 template<> SUMOReal
82 GNEAttributeCarrier::parse(const std::string& string) {
83  return TplConvert::_str2SUMOReal(string);
84 }
85 
86 // ===========================================================================
87 // static methods
88 // ===========================================================================
89 
90 const std::vector<SumoXMLAttr>&
92  // define on first access
93  if (!_allowedAttributes.count(tag)) {
94  std::vector<SumoXMLAttr>& attrs = _allowedAttributes[tag];
95  switch (tag) {
96  case SUMO_TAG_EDGE:
97  attrs.push_back(SUMO_ATTR_ID);
98  attrs.push_back(SUMO_ATTR_FROM);
99  attrs.push_back(SUMO_ATTR_TO);
100  attrs.push_back(SUMO_ATTR_SPEED);
101  attrs.push_back(SUMO_ATTR_PRIORITY);
102  attrs.push_back(SUMO_ATTR_NUMLANES);
103  attrs.push_back(SUMO_ATTR_TYPE);
104  attrs.push_back(SUMO_ATTR_ALLOW);
105  attrs.push_back(SUMO_ATTR_DISALLOW);
106  //attrs.push_back(SUMO_ATTR_PREFER);
107  attrs.push_back(SUMO_ATTR_SHAPE);
108  attrs.push_back(SUMO_ATTR_LENGTH);
109  attrs.push_back(SUMO_ATTR_SPREADTYPE);
110  attrs.push_back(SUMO_ATTR_NAME);
111  attrs.push_back(SUMO_ATTR_WIDTH);
112  attrs.push_back(SUMO_ATTR_ENDOFFSET);
113  break;
114  case SUMO_TAG_JUNCTION:
115  attrs.push_back(SUMO_ATTR_ID);
116  /* virtual attribute from the combination of the actuall
117  * attributes SUMO_ATTR_X, SUMO_ATTR_Y */
118  attrs.push_back(SUMO_ATTR_POSITION);
119  attrs.push_back(SUMO_ATTR_TYPE);
120  attrs.push_back(SUMO_ATTR_SHAPE);
121  attrs.push_back(SUMO_ATTR_RADIUS);
122  attrs.push_back(SUMO_ATTR_KEEP_CLEAR);
123  break;
124  case SUMO_TAG_LANE:
125  attrs.push_back(SUMO_ATTR_ID);
126  attrs.push_back(SUMO_ATTR_SPEED);
127  attrs.push_back(SUMO_ATTR_ALLOW);
128  attrs.push_back(SUMO_ATTR_DISALLOW);
129  //attrs.push_back(SUMO_ATTR_PREFER);
130  attrs.push_back(SUMO_ATTR_WIDTH);
131  attrs.push_back(SUMO_ATTR_ENDOFFSET);
132  attrs.push_back(SUMO_ATTR_INDEX); // read-only attribute
133  break;
134  case SUMO_TAG_POI:
135  attrs.push_back(SUMO_ATTR_ID);
136  /* virtual attribute from the combination of the actuall
137  * attributes SUMO_ATTR_X, SUMO_ATTR_Y */
138  attrs.push_back(SUMO_ATTR_POSITION);
139  attrs.push_back(SUMO_ATTR_TYPE);
140  break;
141  case SUMO_TAG_CROSSING:
142  attrs.push_back(SUMO_ATTR_ID);
143  attrs.push_back(SUMO_ATTR_PRIORITY);
144  attrs.push_back(SUMO_ATTR_WIDTH);
145  attrs.push_back(SUMO_ATTR_EDGES);
146  break;
147  default:
148  WRITE_WARNING("allowed attributes for tag '" +
149  toString(tag) + "' not defined");
150  }
151  }
152  return _allowedAttributes[tag];
153 }
154 
155 
156 const std::vector<SumoXMLTag>&
158  // define on first access
159  if (_allowedTags.empty()) {
160  _allowedTags.push_back(SUMO_TAG_JUNCTION);
161  _allowedTags.push_back(SUMO_TAG_EDGE);
162  _allowedTags.push_back(SUMO_TAG_LANE);
163  }
164  return _allowedTags;
165 }
166 
167 
168 bool
170  // define on first access
171  if (_numericalAttrs.empty()) {
180  }
181  return _numericalAttrs.count(attr) == 1;
182 }
183 
184 
185 bool
187  // define on first access
188  if (_uniqueAttrs.empty()) {
189  _uniqueAttrs.insert(SUMO_ATTR_ID);
191  _uniqueAttrs.insert(SUMO_ATTR_TO);
195  }
196  return _uniqueAttrs.count(attr) == 1;
197 }
198 
199 
200 const std::vector<std::string>&
202  // define on first access
203  if (_discreteChoices.empty()) {
204  std::vector<std::string> choices;
206  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
209  }
210  }
211 
214 
216  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
218  }
219 
220  choices = SumoVehicleClassStrings.getStrings();
221  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
226  }
227 
230  }
231  return _discreteChoices[tag][attr];
232 }
233 
234 
235 bool
237  return (attr == SUMO_ATTR_ALLOW || attr == SUMO_ATTR_DISALLOW);
238 }
239 
240 /****************************************************************************/
241 
The information about how to spread the lanes from the given position.
static std::set< SumoXMLAttr > _numericalAttrs
SumoXMLTag
Numbers representing SUMO-XML - element names.
static StringBijection< SumoXMLNodeType > NodeTypes
static SUMOReal _str2SUMOReal(const std::string &sData)
Definition: TplConvert.h:296
Whether vehicles must keep the junction clear.
static bool isNumerical(SumoXMLAttr attr)
whether an attribute is numerical
static StringBijection< LaneSpreadFunction > LaneSpreadFunctions
static const std::string LOADED
feature is still unchanged after being loaded (implies approval)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
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)
The turning radius at an intersection in m.
the edges of a route
static const std::vector< SumoXMLTag > & allowedTags()
get all editable attributes for tag.
static int _str2int(const std::string &sData)
Definition: TplConvert.h:128
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
static std::set< SumoXMLAttr > _uniqueAttrs
GNEAttributeCarrier(SumoXMLTag tag)
Constructor.
const std::vector< SumoXMLAttr > & getAttrs() const
static std::vector< SumoXMLTag > _allowedTags
static const std::string APPROVED
feature has been approved but not changed (i.e. after being reguessed)
static const std::vector< SumoXMLAttr > & allowedAttributes(SumoXMLTag tag)
get all editable attributes for tag.
static bool discreteCombinableChoices(SumoXMLTag tag, SumoXMLAttr attr)
return whether the given attribute allows for a combination of discrete values
#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 std::map< SumoXMLTag, std::vector< SumoXMLAttr > > _allowedAttributes
virtual bool isValid(SumoXMLAttr key, const std::string &value)
static T parse(const std::string &string)
parses a number of type T from string
static std::map< SumoXMLTag, std::map< SumoXMLAttr, std::vector< std::string > > > _discreteChoices