Eclipse SUMO - Simulation of Urban MObility
GLObjectValuePassConnector.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // Class passing values from a GUIGlObject to another object
19 /****************************************************************************/
20 #ifndef GLObjectValuePassConnector_h
21 #define GLObjectValuePassConnector_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <algorithm>
30 #include <vector>
31 #include <map>
32 #include <functional>
33 #include <fx.h>
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class GUIGlObject;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
59 template<typename T>
61 public:
68  : myObject(o), mySource(source), myRetriever(retriever) { /*, myIsInvalid(false) */
69  FXMutexLock locker(myLock);
70  myContainer.push_back(this);
71  }
72 
73 
76  myLock.lock();
77  typename std::vector< GLObjectValuePassConnector<T>* >::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
78  if (i != myContainer.end()) {
79  myContainer.erase(i);
80  }
81  myLock.unlock();
82  delete mySource;
83  }
84 
85 
88 
91  static void updateAll() {
92  FXMutexLock locker(myLock);
93  std::for_each(myContainer.begin(), myContainer.end(), std::mem_fun(&GLObjectValuePassConnector<T>::passValue));
94  }
95 
96 
99  static void clear() {
100  FXMutexLock locker(myLock);
101  while (!myContainer.empty()) {
102  delete (*myContainer.begin());
103  }
104  myContainer.clear();
105  }
106 
107 
113  static void removeObject(GUIGlObject& o) {
114  FXMutexLock locker(myLock);
115  for (typename std::vector< GLObjectValuePassConnector<T>* >::iterator i = myContainer.begin(); i != myContainer.end();) {
116  if ((*i)->myObject.getGlID() == o.getGlID()) {
117  i = myContainer.erase(i);
118  } else {
119  ++i;
120  }
121  }
122  }
124 
125 
126 protected:
133  virtual bool passValue() {
134  myRetriever->addValue(mySource->getValue());
135  return true;
136  }
137 
138 
139 protected:
142 
145 
148 
150  static FXMutex myLock;
151 
153  static std::vector< GLObjectValuePassConnector<T>* > myContainer;
154 
155 
156 private:
159 
162 
163 
164 };
165 
166 
167 template<typename T>
168 std::vector< GLObjectValuePassConnector<T>* > GLObjectValuePassConnector<T>::myContainer;
169 template<typename T>
171 
172 
173 #endif
174 
175 /****************************************************************************/
176 
GLObjectValuePassConnector::myLock
static FXMutex myLock
The mutex used to avoid concurrent updates of the connectors container.
Definition: GLObjectValuePassConnector.h:150
GUIGlObject.h
GLObjectValuePassConnector::myRetriever
ValueRetriever< T > * myRetriever
The destination for values.
Definition: GLObjectValuePassConnector.h:147
GLObjectValuePassConnector::~GLObjectValuePassConnector
virtual ~GLObjectValuePassConnector()
Destructor.
Definition: GLObjectValuePassConnector.h:75
GLObjectValuePassConnector::clear
static void clear()
Deletes all instances.
Definition: GLObjectValuePassConnector.h:99
GLObjectValuePassConnector::GLObjectValuePassConnector
GLObjectValuePassConnector(GUIGlObject &o, ValueSource< T > *source, ValueRetriever< T > *retriever)
Constructor.
Definition: GLObjectValuePassConnector.h:67
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
GLObjectValuePassConnector::updateAll
static void updateAll()
Updates all instances (passes values)
Definition: GLObjectValuePassConnector.h:91
GLObjectValuePassConnector
Class passing values from a GUIGlObject to another object.
Definition: GLObjectValuePassConnector.h:60
GUIGlObject
Definition: GUIGlObject.h:66
GLObjectValuePassConnector::mySource
ValueSource< T > * mySource
The source for values.
Definition: GLObjectValuePassConnector.h:144
ValueRetriever
Definition: ValueRetriever.h:33
GLObjectValuePassConnector::myContainer
static std::vector< GLObjectValuePassConnector< T > * > myContainer
The container of items that shall be updated.
Definition: GLObjectValuePassConnector.h:153
ValueRetriever.h
ValueSource.h
GLObjectValuePassConnector::removeObject
static void removeObject(GUIGlObject &o)
Removes all instances that pass values from the object with the given id.
Definition: GLObjectValuePassConnector.h:113
config.h
ValueSource
Definition: ValueSource.h:33
GLObjectValuePassConnector::myObject
GUIGlObject & myObject
The object to get the values of (the object that must be active)
Definition: GLObjectValuePassConnector.h:141
GLObjectValuePassConnector::operator=
GLObjectValuePassConnector< T > & operator=(const GLObjectValuePassConnector< T > &)
Invalidated assignment operator.
GLObjectValuePassConnector::passValue
virtual bool passValue()
Passes the value to the retriever.
Definition: GLObjectValuePassConnector.h:133