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-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 #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>
39 #include "GNEReferenceCounter.h"
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class GNENet;
46 class GNEUndoList;
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
59  friend class GNEChange_Attribute;
60 
61 public:
66 
68  virtual ~GNEAttributeCarrier() {};
69 
70  /* @brief method for getting the Attribute of an XML key
71  * @param[in] key The attribute key
72  * @return string with the value associated to key
73  */
74  virtual std::string getAttribute(SumoXMLAttr key) const = 0;
75 
76  /* @brief method for setting the attribute and letting the object perform additional changes
77  * @param[in] key The attribute key
78  * @param[in] value The new value
79  * @param[in] undoList The undoList on which to register changes
80  * @param[in] net optionally the GNENet to inform about gui updates
81  */
82  virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
83 
84  /* @brief method for checking if the key and their conrrespond attribute are valids
85  * @param[in] key The attribute key
86  * @param[in] value The value asociated to key key
87  * @return true if the value is valid, false in other case
88  */
89  virtual bool isValid(SumoXMLAttr key, const std::string& value);
90 
92  virtual std::string getDescription();
93 
95  SumoXMLTag getTag() const;
96 
98  std::vector<SumoXMLAttr> getAttrs() const;
99 
101  const std::string getID() const;
102 
104  static SumoXMLTag getParentType(SumoXMLTag tag);
105 
107  static const std::vector<std::pair <SumoXMLAttr, std::string> >& allowedAttributes(SumoXMLTag tag);
108 
110  static const std::vector<SumoXMLTag>& allowedTags();
111 
113  static const std::vector<SumoXMLTag>& allowedNetElementTags();
114 
116  static const std::vector<SumoXMLTag>& allowedAdditionalTags();
117 
119  static bool isNumerical(SumoXMLAttr attr);
120 
122  static bool isInt(SumoXMLAttr attr);
123 
125  static bool isFloat(SumoXMLAttr attr);
126 
128  static bool isBool(SumoXMLAttr attr);
129 
131  static bool isString(SumoXMLAttr attr);
132 
134  static bool isList(SumoXMLAttr attr);
135 
138  static bool isUnique(SumoXMLAttr attr);
139 
141  static bool isDiscrete(SumoXMLTag tag, SumoXMLAttr attr);
142 
144  static bool hasParent(SumoXMLTag tag);
145 
147  static bool hasAttribute(SumoXMLTag tag, SumoXMLAttr attr);
148 
150  static const std::vector<std::string>& discreteChoices(SumoXMLTag tag, SumoXMLAttr attr);
151 
153  static bool discreteCombinableChoices(SumoXMLTag tag, SumoXMLAttr attr);
154 
156  static std::string getDefinition(SumoXMLTag tag, SumoXMLAttr attr);
157 
159  static int getHigherNumberOfAttributes();
160 
163  template<typename T>
164  static T getDefaultValue(SumoXMLTag tag, SumoXMLAttr attr);
165 
167  template<typename T>
168  static bool canParse(const std::string& string) {
169  try {
170  parse<T>(string);
171  } catch (NumberFormatException&) {
172  return false;
173  } catch (EmptyData&) {
174  return false;
175  } catch (BoolFormatException&) {
176  return false;
177  }
178  return true;
179  }
180 
182  template<typename T>
183  static T parse(const std::string& string);
184 
186  template<typename T>
187  static bool isPositive(const std::string& string) {
188  return canParse<T>(string) && parse<T>(string) > 0;
189  }
190 
192  static bool isValidID(const std::string& value);
193 
195  static bool isValidFileValue(const std::string& value);
196 
198  static bool isValidStringVector(const std::string& value);
199 
201  static const std::string LOADED;
202 
204  static const std::string GUESSED;
205 
207  static const std::string MODIFIED;
208 
210  static const std::string APPROVED;
211 
212 private:
214  virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
215 
218 
220  static std::map<SumoXMLTag, std::vector<std::pair <SumoXMLAttr, std::string> > > _allowedAttributes;
221 
223  static std::vector<SumoXMLTag> myAllowedTags;
224 
226  static std::vector<SumoXMLTag> myAllowedNetElementTags;
227 
229  static std::vector<SumoXMLTag> myAllowedAdditionalTags;
230 
232  static std::set<SumoXMLAttr> myNumericalIntAttrs;
233 
235  static std::set<SumoXMLAttr> myNumericalFloatAttrs;
236 
238  static std::set<SumoXMLAttr> myListAttrs;
239 
241  static std::set<SumoXMLAttr> myUniqueAttrs;
242 
244  static std::map<SumoXMLTag, SumoXMLTag> myAllowedAdditionalWithParentTags;
245 
247  static std::map<SumoXMLTag, std::map<SumoXMLAttr, std::vector<std::string> > > myDiscreteChoices;
248 
250  static std::map<SumoXMLTag, std::map<SumoXMLAttr, std::string> > myAttrDefinitions;
251 
252 private:
255 };
256 
257 #endif
258 
259 /****************************************************************************/
260 
static bool isList(SumoXMLAttr attr)
whether an attribute is of type bool
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 std::set< SumoXMLAttr > myUniqueAttrs
set with the unique attributes (i.e. attributes without default values)
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 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 ...
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:86
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static std::map< SumoXMLTag, std::vector< std::pair< SumoXMLAttr, std::string > > > _allowedAttributes
map with the allowed attributes
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
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.
static std::vector< SumoXMLTag > myAllowedNetElementTags
vector with the allowed tags of netElements
static const std::vector< std::string > & discreteChoices(SumoXMLTag tag, SumoXMLAttr attr)
return a list of discrete choices for this attribute or an empty vector
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 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
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
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
const std::string getID() const
function to support debugging
virtual ~GNEAttributeCarrier()
Destructor.
static bool isFloat(SumoXMLAttr attr)
whether an attribute is numerical of type float
static bool canParse(const std::string &string)
true if a number of type T can be parsed from string
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
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 SumoXMLTag getParentType(SumoXMLTag tag)
get parent&#39;s tag of a certain additional element
SumoXMLTag getTag() const
get Tag assigned to this object
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)
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