SUMO - Simulation of Urban MObility
GNEAttributeCarrier.h
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-2017 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 #ifndef GNEAttributeCarrier_h
21 #define GNEAttributeCarrier_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <vector>
35 #include <map>
37 #include <utils/common/ToString.h>
40 #include "GNEReferenceCounter.h"
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class GNENet;
47 class GNEUndoList;
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
60  friend class GNEChange_Attribute;
61 
62 public:
68 
70  virtual ~GNEAttributeCarrier() {};
71 
72  /* @brief method for getting the Attribute of an XML key
73  * @param[in] key The attribute key
74  * @return string with the value associated to key
75  */
76  virtual std::string getAttribute(SumoXMLAttr key) const = 0;
77 
78  /* @brief method for setting the attribute and letting the object perform additional changes
79  * @param[in] key The attribute key
80  * @param[in] value The new value
81  * @param[in] undoList The undoList on which to register changes
82  * @param[in] net optionally the GNENet to inform about gui updates
83  */
84  virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
85 
86  /* @brief method for checking if the key and their conrrespond attribute are valids
87  * @param[in] key The attribute key
88  * @param[in] value The value asociated to key key
89  * @return true if the value is valid, false in other case
90  */
91  virtual bool isValid(SumoXMLAttr key, const std::string& value);
92 
94  virtual std::string getDescription();
95 
97  SumoXMLTag getTag() const;
98 
100  FXIcon* getIcon() const;
101 
103  GUIIcon getGUIIcon() const;
104 
106  std::vector<SumoXMLAttr> getAttrs() const;
107 
109  const std::string getID() const;
110 
112  static std::string getAttributeType(SumoXMLTag tag, SumoXMLAttr attr);
113 
115  static const std::vector<std::pair<SumoXMLAttr, std::string> >& allowedAttributes(SumoXMLTag tag);
116 
118  static const std::vector<SumoXMLTag>& allowedTags(bool net);
119 
121  static bool isNumerical(SumoXMLTag tag, SumoXMLAttr attr);
122 
124  static bool isInt(SumoXMLTag tag, SumoXMLAttr attr);
125 
127  static bool isFloat(SumoXMLTag tag, SumoXMLAttr attr);
128 
130  static bool isTime(SumoXMLTag tag, SumoXMLAttr attr);
131 
133  static bool isBool(SumoXMLTag tag, SumoXMLAttr attr);
134 
136  static bool isString(SumoXMLTag tag, SumoXMLAttr attr);
137 
139  static bool isList(SumoXMLTag tag, SumoXMLAttr attr);
140 
142  static bool isUnique(SumoXMLTag tag, SumoXMLAttr attr);
143 
145  static bool isDiscrete(SumoXMLTag tag, SumoXMLAttr attr);
146 
148  static bool isPositive(SumoXMLTag tag, SumoXMLAttr attr);
149 
151  static bool isProbability(SumoXMLTag tag, SumoXMLAttr attr);
152 
154  static bool isFilename(SumoXMLTag tag, SumoXMLAttr attr);
155 
157  static bool isNonEditable(SumoXMLTag tag, SumoXMLAttr attr);
158 
160  static bool hasAttribute(SumoXMLTag tag, SumoXMLAttr attr);
161 
163  static bool hasDefaultValue(SumoXMLTag tag, SumoXMLAttr attr);
164 
166  static const std::vector<std::string>& discreteChoices(SumoXMLTag tag, SumoXMLAttr attr);
167 
169  static bool discreteCombinableChoices(SumoXMLTag tag, SumoXMLAttr attr);
170 
172  static std::string getDefinition(SumoXMLTag tag, SumoXMLAttr attr);
173 
175  static int getHigherNumberOfAttributes();
176 
179  template<typename T>
180  static T getDefaultValue(SumoXMLTag tag, SumoXMLAttr attr);
181 
183  template<typename T>
184  static bool canParse(const std::string& string) {
185  try {
186  parse<T>(string);
187  } catch (NumberFormatException&) {
188  return false;
189  } catch (EmptyData&) {
190  return false;
191  } catch (BoolFormatException&) {
192  return false;
193  }
194  return true;
195  }
196 
198  template<typename T>
199  static T parse(const std::string& string);
200 
202  template<typename T>
203  static bool isPositive(const std::string& string) {
204  return canParse<T>(string) && parse<T>(string) > 0;
205  }
206 
208  static bool isValidID(const std::string& value);
209 
211  static bool isValidFilename(const std::string& value);
212 
214  static const std::string LOADED;
215 
217  static const std::string GUESSED;
218 
220  static const std::string MODIFIED;
221 
223  static const std::string APPROVED;
224 
225 private:
227  virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
228 
231 
234 
236  static std::map<SumoXMLTag, std::vector<std::pair <SumoXMLAttr, std::string> > > _allowedAttributes;
237 
239  static std::vector<SumoXMLTag> myAllowedNetElementTags;
240 
242  static std::vector<SumoXMLTag> myAllowedAdditionalTags;
243 
245  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myNumericalIntAttrs;
246 
248  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myNumericalFloatAttrs;
249 
251  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myTimeAttrs;
252 
254  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myBoolAttrs;
255 
257  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myListAttrs;
258 
260  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myUniqueAttrs;
261 
263  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myNonEditableAttrs;
264 
266  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myPositiveAttrs;
267 
269  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myProbabilityAttrs;
270 
272  static std::map<SumoXMLTag, std::set<SumoXMLAttr> > myFileAttrs;
273 
275  static std::map<SumoXMLTag, SumoXMLTag> myAllowedAdditionalWithParentTags;
276 
278  static std::map<SumoXMLTag, std::map<SumoXMLAttr, std::vector<std::string> > > myDiscreteChoices;
279 
281  static std::map<SumoXMLTag, std::map<SumoXMLAttr, std::string> > myAttrDefinitions;
282 
284  static int myMaxNumAttribute;
285 
286 private:
289 };
290 
291 #endif
292 
293 /****************************************************************************/
294 
SumoXMLTag
Numbers representing SUMO-XML - element names.
static bool isPositive(const std::string &string)
true if a positive number of type T can be parsed from string
static bool isFloat(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is numerical of type float
static std::string getAttributeType(SumoXMLTag tag, SumoXMLAttr attr)
get type of attribute
GNEAttributeCarrier(SumoXMLTag tag, GUIIcon icon)
Constructor.
const SumoXMLTag myTag
the xml tag to which this attribute carrier corresponds
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
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:43
static std::map< SumoXMLTag, std::set< SumoXMLAttr > > myPositiveAttrs
map with the positive attributes
static std::map< SumoXMLTag, std::set< SumoXMLAttr > > myUniqueAttrs
map with the unique attributes (i.e. attributes without default values)
static std::map< SumoXMLTag, std::map< SumoXMLAttr, std::vector< std::string > > > myDiscreteChoices
map with the values of discrete choices
static std::map< SumoXMLTag, std::set< SumoXMLAttr > > myBoolAttrs
map with the boolean attributes
static const std::string LOADED
feature is still unchanged after being loaded (implies approval)
static std::map< SumoXMLTag, std::set< SumoXMLAttr > > myProbabilityAttrs
map with the probability attributes
static int getHigherNumberOfAttributes()
return the number of attributes of the tag with the most highter number of attributes ...
GUIIcon myIcon
icon associated to this AC
static std::map< SumoXMLTag, std::set< SumoXMLAttr > > myTimeAttrs
map with the attributes of type time
static bool isPositive(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is only Positive (i.e. cannot take negative values)
FXIcon * getIcon() const
get FXIcon assigned to this object
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:88
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static std::map< SumoXMLTag, std::vector< std::pair< SumoXMLAttr, std::string > > > _allowedAttributes
map with the allowed attributes and their default values
static bool isValidFilename(const std::string &value)
true if value is a valid file value
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
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.
static std::vector< SumoXMLTag > myAllowedNetElementTags
vector with the allowed tags of netElements
static bool isString(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is of type string
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 std::map< SumoXMLTag, std::set< SumoXMLAttr > > myListAttrs
map with the attributes of type list
static bool isInt(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is numerical or type int
the function-object for an editing operation (abstract base)
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 bool isTime(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is time
static bool isNonEditable(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is non editable
static std::vector< SumoXMLTag > myAllowedAdditionalTags
vector with the allowed tags of additionals
static bool hasAttribute(SumoXMLTag tag, SumoXMLAttr attr)
check if an element with certain tag has a certain attribute
static bool hasDefaultValue(SumoXMLTag tag, SumoXMLAttr attr)
check if attribute of an element has a default avlue
static bool isFilename(SumoXMLTag tag, SumoXMLAttr attr)
whether a string attribute is a filename
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
static const std::vector< SumoXMLTag > & allowedTags(bool net)
get all editable for tag (net or additional).
std::vector< SumoXMLAttr > getAttrs() const
get vector of attributes
const std::string getID() const
function to support debugging
static std::map< SumoXMLTag, std::set< SumoXMLAttr > > myNonEditableAttrs
map with the non-editable attributes
virtual ~GNEAttributeCarrier()
Destructor.
static bool isUnique(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is unique (may not be edited for a multi-selection and don&#39;t have a default valu...
static bool canParse(const std::string &string)
true if a number of type T can be parsed from string
static int myMaxNumAttribute
maximum number of attributes of all tags
static bool isProbability(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is a probability (i.e. oly can values between [0, 1])
static const std::string APPROVED
feature has been approved but not changed (i.e. after being reguessed)
static bool isBool(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is of type bool for a certain tag
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)
Invalidated assignment operator.
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 const std::string GUESSED
feature has been reguessed (may still be unchanged be we can&#39;t tell (yet)
GUIIcon getGUIIcon() const
get GUI icon assigned to this object
static bool isNumerical(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is numerical (int or float)
virtual bool isValid(SumoXMLAttr key, const std::string &value)
static std::map< SumoXMLTag, std::set< SumoXMLAttr > > myNumericalIntAttrs
map with the numerical attributes of type Int
static T parse(const std::string &string)
parses a number of type T from string
static std::map< SumoXMLTag, std::set< SumoXMLAttr > > myNumericalFloatAttrs
map with the numerical attributes of type Float
static std::map< SumoXMLTag, SumoXMLTag > myAllowedAdditionalWithParentTags
map with the allowed tags of additionals with parent and their parent
static bool isList(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is of type bool
SumoXMLTag getTag() const
get XML Tag assigned to this object
static std::map< SumoXMLTag, std::set< SumoXMLAttr > > myFileAttrs
map with the empty attributes