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 // ===========================================================================
58 
59  friend class GNEChange_Attribute;
60 
61 public:
62 
66 
67 
69  virtual ~GNEAttributeCarrier() {};
70 
71  virtual std::string getAttribute(SumoXMLAttr key) const = 0;
72 
73  /* @brief method for setting the attribute and letting the object perform additional changes
74  * @param[in] key The attribute key
75  * @param[in] value The new value
76  * @param[in] undoList The undoList on which to register changes
77  * @param[in] net optionally the GNENet to inform about gui updates
78  */
79  virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
80 
81  virtual bool isValid(SumoXMLAttr key, const std::string& value);
82 
84  virtual std::string getDescription() {
85  return toString(myTag);
86  }
87 
88  SumoXMLTag getTag() const {
89  return myTag;
90  }
91 
92  const std::vector<SumoXMLAttr>& getAttrs() const {
94  }
95 
97  const std::string getID() const {
98  return getAttribute(SUMO_ATTR_ID);
99  }
100 
102  static const std::vector<SumoXMLAttr>& allowedAttributes(SumoXMLTag tag);
103 
105  static const std::vector<SumoXMLTag>& allowedTags();
106 
108  static bool isNumerical(SumoXMLAttr attr);
109 
111  static bool isUnique(SumoXMLAttr attr);
112 
114  static const std::vector<std::string>& discreteChoices(SumoXMLTag tag, SumoXMLAttr attr);
115 
117  static bool discreteCombinableChoices(SumoXMLTag tag, SumoXMLAttr attr);
118 
120  template<typename T>
121  static bool canParse(const std::string& string) {
122  try {
123  parse<T>(string);
124  } catch (NumberFormatException&) {
125  return false;
126  } catch (EmptyData&) {
127  return false;
128  }
129  return true;
130  }
131 
133  template<typename T>
134  static T parse(const std::string& string);
135 
137  template<typename T>
138  static bool isPositive(const std::string& string) {
139  return canParse<T>(string) && parse<T>(string) > 0;
140  }
141 
143  static bool isValidID(const std::string& value);
144 
146  static const std::string LOADED;
148  static const std::string GUESSED;
150  static const std::string MODIFIED;
152  static const std::string APPROVED;
153 
154 
155 private:
156  /* @brief method for setting the attribute and nothing else
157  * (used in GNEChange_Attribute)
158  * */
159  virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
160 
163 
164  static std::map<SumoXMLTag, std::vector<SumoXMLAttr> > _allowedAttributes;
165  static std::vector<SumoXMLTag> _allowedTags;
166  static std::set<SumoXMLAttr> _numericalAttrs;
167  static std::set<SumoXMLAttr> _uniqueAttrs;
168  static std::map<SumoXMLTag, std::map<SumoXMLAttr, std::vector<std::string> > > _discreteChoices;
169 
170 private:
173 
174 };
175 
176 #endif
177 
178 /****************************************************************************/
179 
static std::set< SumoXMLAttr > _numericalAttrs
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 isNumerical(SumoXMLAttr attr)
whether an attribute is numerical
const SumoXMLTag myTag
the xml tag to which this carrier corresponds
static const std::string LOADED
feature is still unchanged after being loaded (implies approval)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:77
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
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::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 const std::vector< SumoXMLTag > & allowedTags()
get all editable attributes for tag.
const std::string getID() const
function to support debugging
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
virtual ~GNEAttributeCarrier()
Destructor.
static std::set< SumoXMLAttr > _uniqueAttrs
static bool canParse(const std::string &string)
true if a number of type T can be parsed from string
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.
GNEAttributeCarrier & operator=(const GNEAttributeCarrier &src)
Invalidated assignment operator.
virtual std::string getDescription()
how should this attribute carrier be called
static bool discreteCombinableChoices(SumoXMLTag tag, SumoXMLAttr attr)
return whether the given attribute allows for a combination of discrete values
SumoXMLTag getTag() const
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