SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLObjectValuePassConnector.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // Class passing values from a GUIGlObject to another object
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef GLObjectValuePassConnector_h
24 #define GLObjectValuePassConnector_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <algorithm>
37 #include <vector>
38 #include <map>
43 
44 
45 // ===========================================================================
46 // class declarations
47 // ===========================================================================
48 class GUIGlObject;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
65 template<typename T>
67 public:
74  : myObject(o), mySource(source), myRetriever(retriever) { /*, myIsInvalid(false) */
76  myContainer.push_back(this);
77  }
78 
79 
82  myLock.lock();
83  typename std::vector< GLObjectValuePassConnector<T>* >::iterator i = std::find(myContainer.begin(), myContainer.end(), this);
84  if (i != myContainer.end()) {
85  myContainer.erase(i);
86  }
87  myLock.unlock();
88  delete mySource;
89  }
90 
91 
94 
97  static void updateAll() {
99  std::for_each(myContainer.begin(), myContainer.end(), std::mem_fun(&GLObjectValuePassConnector<T>::passValue));
100  }
101 
102 
105  static void clear() {
107  while (!myContainer.empty()) {
108  delete(*myContainer.begin());
109  }
110  myContainer.clear();
111  }
112 
113 
119  static void removeObject(GUIGlObject& o) {
121  for (typename std::vector< GLObjectValuePassConnector<T>* >::iterator i = myContainer.begin(); i != myContainer.end();) {
122  if ((*i)->myObject.getGlID() == o.getGlID()) {
123  i = myContainer.erase(i);
124  } else {
125  ++i;
126  }
127  }
128  }
130 
131 
132 protected:
139  virtual bool passValue() {
140  myRetriever->addValue(mySource->getValue());
141  return true;
142  }
143 
144 
145 protected:
148 
151 
154 
156  static MFXMutex myLock;
157 
159  static std::vector< GLObjectValuePassConnector<T>* > myContainer;
160 
161 
162 private:
165 
168 
169 
170 };
171 
172 
173 template<typename T>
174 std::vector< GLObjectValuePassConnector<T>* > GLObjectValuePassConnector<T>::myContainer;
175 template<typename T>
177 
178 
179 #endif
180 
181 /****************************************************************************/
182