SUMO - Simulation of Urban MObility
GUIGlObject_AbstractAdd.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Base class for additional objects (detectors etc.)
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
33 #include <cassert>
34 #include <iostream>
35 #include <algorithm>
36 #include <utils/gui/div/GLHelper.h>
37 
38 
39 // ===========================================================================
40 // static member definitions
41 // ===========================================================================
42 std::map<std::string, GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjects;
43 std::vector<GUIGlObject_AbstractAdd*> GUIGlObject_AbstractAdd::myObjectList;
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 GUIGlObject_AbstractAdd::GUIGlObject_AbstractAdd(const std::string& prefix, GUIGlObjectType type, const std::string& id) :
50  GUIGlObject(prefix, type, id) {
51  myObjects[getFullName()] = this;
52  myObjectList.push_back(this);
53 }
54 
55 
57 
58 
59 void
61  std::map<std::string, GUIGlObject_AbstractAdd*>::iterator i;
62  for (i = myObjects.begin(); i != myObjects.end(); i++) {
64  }
65  myObjects.clear();
66  myObjectList.clear();
67 }
68 
69 
71 GUIGlObject_AbstractAdd::get(const std::string& name) {
72  std::map<std::string, GUIGlObject_AbstractAdd*>::iterator i = myObjects.find(name);
73  if (i == myObjects.end()) {
74  return 0;
75  }
76  return (*i).second;
77 }
78 
79 
80 void
82  myObjects.erase(o->getFullName());
83  myObjectList.erase(std::remove(myObjectList.begin(), myObjectList.end(), o), myObjectList.end());
84 }
85 
86 
87 const std::vector<GUIGlObject_AbstractAdd*>&
89  return myObjectList;
90 }
91 
92 
93 std::vector<GUIGlID>
95  std::vector<GUIGlID> ret;
96  for (std::vector<GUIGlObject_AbstractAdd*>::iterator i = myObjectList.begin(); i != myObjectList.end(); ++i) {
97  if (((*i)->getType() & typeFilter) != 0) {
98  ret.push_back((*i)->getGlID());
99  }
100  }
101  return ret;
102 }
103 
104 /****************************************************************************/
105 
static std::map< std::string, GUIGlObject_AbstractAdd * > myObjects
Map from names of loaded additional objects to the objects themselves.
static void remove(GUIGlObject_AbstractAdd *o)
Removes an object.
GUIGlObjectType
static GUIGlObject_AbstractAdd * get(const std::string &name)
Returns a named object.
GUIGlObject_AbstractAdd(const std::string &prefix, GUIGlObjectType type, const std::string &id)
static std::vector< GUIGlObject_AbstractAdd * > myObjectList
The list of all addtional objects currently loaded.
static void clearDictionary()
Clears the dictionary (the objects will not be deleted)
static const std::vector< GUIGlObject_AbstractAdd * > & getObjectList()
Returns the list of all additional objects.
const std::string & getFullName() const
static std::vector< GUIGlID > getIDList(int typeFilter)
Returns the list of gl-ids of all additional objects that match the given type.