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-2015 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>
38 #include "GNEReferenceCounter.h"
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class GNENet;
45 class GNEUndoList;
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
57 
58  friend class GNEChange_Attribute;
59 
60 public:
61 
65 
66 
68  virtual ~GNEAttributeCarrier() {};
69 
70  virtual std::string getAttribute(SumoXMLAttr key) const = 0;
71 
72  /* @brief method for setting the attribute and letting the object perform additional changes
73  * @param[in] key The attribute key
74  * @param[in] value The new value
75  * @param[in] undoList The undoList on which to register changes
76  * @param[in] net optionally the GNENet to inform about gui updates
77  */
78  virtual void setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) = 0;
79 
80  virtual bool isValid(SumoXMLAttr key, const std::string& value);
81 
83  virtual std::string getDescription() {
84  return toString(myTag);
85  }
86 
87  SumoXMLTag getTag() const {
88  return myTag;
89  }
90 
91  const std::vector<SumoXMLAttr>& getAttrs() const {
93  }
94 
96  const std::string getID() const {
97  return getAttribute(SUMO_ATTR_ID);
98  }
99 
101  static const std::vector<SumoXMLAttr>& allowedAttributes(SumoXMLTag tag);
102 
104  static const std::vector<SumoXMLTag>& allowedTags();
105 
107  static bool isNumerical(SumoXMLAttr attr);
108 
110  static bool isUnique(SumoXMLAttr attr);
111 
113  static const std::vector<std::string>& discreteChoices(SumoXMLTag tag, SumoXMLAttr attr);
114 
116  static bool discreteCombinableChoices(SumoXMLTag tag, SumoXMLAttr attr);
117 
119  template <class T>
120  static bool canParse(const std::string& string) {
121  T tmp;
122  std::istringstream buf(string);
123  buf >> tmp;
124  return !buf.fail() && (size_t)buf.tellg() == string.size();
125  }
126 
128  template <class T>
129  static T parse(const std::string& string) {
130  T result;
131  std::istringstream buf(string);
132  buf >> result;
133  return result;
134  }
135 
137  template <class T>
138  static bool isPositive(const std::string& string) {
139  if (canParse<T>(string)) {
140  return parse<T>(string) > 0;
141  } else {
142  return false;
143  }
144  }
145 
147  static bool isValidID(const std::string& value);
148 
150  static const std::string LOADED;
152  static const std::string GUESSED;
154  static const std::string MODIFIED;
156  static const std::string APPROVED;
157 
158 
159 private:
160  /* @brief method for setting the attribute and nothing else
161  * (used in GNEChange_Attribute)
162  * */
163  virtual void setAttribute(SumoXMLAttr key, const std::string& value) = 0;
164 
167 
168  static std::map<SumoXMLTag, std::vector<SumoXMLAttr> > _allowedAttributes;
169  static std::vector<SumoXMLTag> _allowedTags;
170  static std::set<SumoXMLAttr> _numericalAttrs;
171  static std::set<SumoXMLAttr> _uniqueAttrs;
172  static std::map<SumoXMLTag, std::map<SumoXMLAttr, std::vector<std::string> > > _discreteChoices;
173 
174 private:
177 
178 };
179 
180 #endif
181 
182 /****************************************************************************/
183 
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:53
virtual ~GNEAttributeCarrier()
Destructor.
static std::set< SumoXMLAttr > _uniqueAttrs
static bool canParse(const std::string &string)
true if an object 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 an object of type T from from string
static std::map< SumoXMLTag, std::map< SumoXMLAttr, std::vector< std::string > > > _discreteChoices