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 /****************************************************************************/
17 // Class passing values from a GUIGlObject to another object
18 /****************************************************************************/
19 #ifndef GLObjectValuePassConnector_h
20 #define GLObjectValuePassConnector_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <algorithm>
29 #include <vector>
30 #include <map>
31 #include <functional>
32 #include <fx.h>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class GUIGlObject;
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
58 template<typename T>
60 public:
67  : myObject(o), mySource(source), myRetriever(retriever) { /*, myIsInvalid(false) */
68  FXMutexLock locker(myLock);
69  myContainer.push_back(this);
70  }
71 
72 
75  myLock.lock();
76  typename std::vector< GLObjectValuePassConnector<T>* >::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
77  if (i != myContainer.end()) {
78  myContainer.erase(i);
79  }
80  myLock.unlock();
81  delete mySource;
82  }
83 
84 
87 
90  static void updateAll() {
91  FXMutexLock locker(myLock);
92  std::for_each(myContainer.begin(), myContainer.end(), std::mem_fun(&GLObjectValuePassConnector<T>::passValue));
93  }
94 
95 
98  static void clear() {
99  FXMutexLock locker(myLock);
100  while (!myContainer.empty()) {
101  delete (*myContainer.begin());
102  }
103  myContainer.clear();
104  }
105 
106 
112  static void removeObject(GUIGlObject& o) {
113  FXMutexLock locker(myLock);
114  for (typename std::vector< GLObjectValuePassConnector<T>* >::iterator i = myContainer.begin(); i != myContainer.end();) {
115  if ((*i)->myObject.getGlID() == o.getGlID()) {
116  i = myContainer.erase(i);
117  } else {
118  ++i;
119  }
120  }
121  }
123 
124 
125 protected:
132  virtual bool passValue() {
133  myRetriever->addValue(mySource->getValue());
134  return true;
135  }
136 
137 
138 protected:
141 
144 
147 
149  static FXMutex myLock;
150 
152  static std::vector< GLObjectValuePassConnector<T>* > myContainer;
153 
154 
155 private:
158 
161 
162 
163 };
164 
165 
166 template<typename T>
167 std::vector< GLObjectValuePassConnector<T>* > GLObjectValuePassConnector<T>::myContainer;
168 template<typename T>
170 
171 
172 #endif
173 
174 /****************************************************************************/
175 
GLObjectValuePassConnector::myLock
static FXMutex myLock
The mutex used to avoid concurrent updates of the connectors container.
Definition: GLObjectValuePassConnector.h:149
GUIGlObject.h
GLObjectValuePassConnector::myRetriever
ValueRetriever< T > * myRetriever
The destination for values.
Definition: GLObjectValuePassConnector.h:146
GLObjectValuePassConnector::~GLObjectValuePassConnector
virtual ~GLObjectValuePassConnector()
Destructor.
Definition: GLObjectValuePassConnector.h:74
GLObjectValuePassConnector::clear
static void clear()
Deletes all instances.
Definition: GLObjectValuePassConnector.h:98
GLObjectValuePassConnector::GLObjectValuePassConnector
GLObjectValuePassConnector(GUIGlObject &o, ValueSource< T > *source, ValueRetriever< T > *retriever)
Constructor.
Definition: GLObjectValuePassConnector.h:66
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:149
GLObjectValuePassConnector::updateAll
static void updateAll()
Updates all instances (passes values)
Definition: GLObjectValuePassConnector.h:90
GLObjectValuePassConnector
Class passing values from a GUIGlObject to another object.
Definition: GLObjectValuePassConnector.h:59
GUIGlObject
Definition: GUIGlObject.h:65
GLObjectValuePassConnector::mySource
ValueSource< T > * mySource
The source for values.
Definition: GLObjectValuePassConnector.h:143
ValueRetriever
Definition: ValueRetriever.h:32
GLObjectValuePassConnector::myContainer
static std::vector< GLObjectValuePassConnector< T > * > myContainer
The container of items that shall be updated.
Definition: GLObjectValuePassConnector.h:152
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:112
config.h
ValueSource
Definition: ValueSource.h:32
GLObjectValuePassConnector::myObject
GUIGlObject & myObject
The object to get the values of (the object that must be active)
Definition: GLObjectValuePassConnector.h:140
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:132