Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GLObjectValuePassConnector.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// Class passing values from a GUIGlObject to another object
22/****************************************************************************/
23#pragma once
24#include <config.h>
25
26#include <algorithm>
27#include <vector>
28#include <map>
29#include <functional>
34
35
36// ===========================================================================
37// class declarations
38// ===========================================================================
39class GUIGlObject;
40
41
42// ===========================================================================
43// class definitions
44// ===========================================================================
56template<typename T>
58public:
65 : myObject(o), mySource(source), myRetriever(retriever) { /*, myIsInvalid(false) */
66 FXMutexLock locker(myLock);
67 myContainer.push_back(this);
68 }
69
70
73 myLock.lock();
74 typename std::vector< GLObjectValuePassConnector<T>* >::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
75 if (i != myContainer.end()) {
76 myContainer.erase(i);
77 }
78 myLock.unlock();
79 delete mySource;
80 }
81
82
85
88 static void updateAll() {
89 FXMutexLock locker(myLock);
90 for (GLObjectValuePassConnector<T>* const connector : myContainer) {
91 connector->passValue();
92 }
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
125protected:
132 virtual bool passValue() {
133 myRetriever->addValue(mySource->getValue());
134 return true;
135 }
136
137
138protected:
141
144
147
149 static FXMutex myLock;
150
152 static std::vector< GLObjectValuePassConnector<T>* > myContainer;
153
154
155private:
158
161
162
163};
164
165
166template<typename T>
167std::vector< GLObjectValuePassConnector<T>* > GLObjectValuePassConnector<T>::myContainer;
168template<typename T>
Class passing values from a GUIGlObject to another object.
static void clear()
Deletes all instances.
GUIGlObject & myObject
The object to get the values of (the object that must be active)
static std::vector< GLObjectValuePassConnector< T > * > myContainer
The container of items that shall be updated.
static void removeObject(GUIGlObject &o)
Removes all instances that pass values from the object with the given id.
static void updateAll()
Updates all instances (passes values)
ValueRetriever< T > * myRetriever
The destination for values.
GLObjectValuePassConnector< T > & operator=(const GLObjectValuePassConnector< T > &)
Invalidated assignment operator.
virtual ~GLObjectValuePassConnector()
Destructor.
static FXMutex myLock
The mutex used to avoid concurrent updates of the connectors container.
virtual bool passValue()
Passes the value to the retriever.
GLObjectValuePassConnector(GUIGlObject &o, ValueSource< T > *source, ValueRetriever< T > *retriever)
Constructor.
ValueSource< T > * mySource
The source for values.
GUIGlID getGlID() const
Returns the numerical id of the object.