SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
GUIGlObjectStorage.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// A storage for displayed objects via their numerical id
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13
/****************************************************************************/
14
//
15
// This file is part of SUMO.
16
// SUMO is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU General Public License as published by
18
// the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
/****************************************************************************/
22
23
24
// ===========================================================================
25
// included modules
26
// ===========================================================================
27
#ifdef _MSC_VER
28
#include <
windows_config.h
>
29
#else
30
#include <
config.h
>
31
#endif
32
33
#include <map>
34
#include <iostream>
35
#include <cassert>
36
#include <
utils/foxtools/MFXMutex.h
>
37
#include "
GUIGlObject.h
"
38
#include "
GUIGlObjectStorage.h
"
39
40
#ifdef CHECK_MEMORY_LEAKS
41
#include <
foreign/nvwa/debug_new.h
>
42
#endif // CHECK_MEMORY_LEAKS
43
44
45
// ===========================================================================
46
// static variables (instances in this case)
47
// ===========================================================================
48
GUIGlObjectStorage
GUIGlObjectStorage::gIDStorage
;
49
50
51
// ===========================================================================
52
// method definitions
53
// ===========================================================================
54
GUIGlObjectStorage::GUIGlObjectStorage
()
55
: myAktID(0) {}
56
57
58
GUIGlObjectStorage::~GUIGlObjectStorage
() {}
59
60
61
GUIGlID
62
GUIGlObjectStorage::registerObject
(
GUIGlObject
*
object
,
const
std::string& fullName) {
63
AbstractMutex::ScopedLocker
locker(
myLock
);
64
GUIGlID
id
=
myAktID
++;
65
myMap
[id] = object;
66
myFullNameMap
[fullName] = object;
67
return
id;
68
}
69
70
71
GUIGlObject
*
72
GUIGlObjectStorage::getObjectBlocking
(
GUIGlID
id
) {
73
AbstractMutex::ScopedLocker
locker(
myLock
);
74
ObjectMap::iterator i =
myMap
.find(
id
);
75
if
(i ==
myMap
.end()) {
76
i =
myBlocked
.find(
id
);
77
if
(i !=
myBlocked
.end()) {
78
GUIGlObject
* o = (*i).second;
79
return
o;
80
}
81
return
0;
82
}
83
GUIGlObject
* o = (*i).second;
84
myMap
.erase(
id
);
85
myBlocked
[id] = o;
86
return
o;
87
}
88
89
90
GUIGlObject
*
91
GUIGlObjectStorage::getObjectBlocking
(
const
std::string& fullName) {
92
AbstractMutex::ScopedLocker
locker(
myLock
);
93
if
(
myFullNameMap
.count(fullName)) {
94
GUIGlID
id
=
myFullNameMap
[fullName]->getGlID();
95
return
getObjectBlocking
(
id
);
96
}
97
return
0;
98
}
99
100
101
bool
102
GUIGlObjectStorage::remove
(
GUIGlID
id
) {
103
AbstractMutex::ScopedLocker
locker(
myLock
);
104
ObjectMap::iterator i =
myMap
.find(
id
);
105
if
(i ==
myMap
.end()) {
106
i =
myBlocked
.find(
id
);
107
assert(i !=
myBlocked
.end());
108
GUIGlObject
* o = (*i).second;
109
myFullNameMap
.erase(o->getFullName());
110
myBlocked
.erase(
id
);
111
my2Delete
[id] = o;
112
return
false
;
113
}
114
myFullNameMap
.erase(i->second->getFullName());
115
myMap
.erase(
id
);
116
return
true
;
117
}
118
119
120
void
121
GUIGlObjectStorage::clear
() {
122
AbstractMutex::ScopedLocker
locker(
myLock
);
123
myMap
.clear();
124
myAktID
= 0;
125
}
126
127
128
void
129
GUIGlObjectStorage::unblockObject
(
GUIGlID
id
) {
130
AbstractMutex::ScopedLocker
locker(
myLock
);
131
ObjectMap::iterator i =
myBlocked
.find(
id
);
132
if
(i ==
myBlocked
.end()) {
133
return
;
134
}
135
GUIGlObject
* o = (*i).second;
136
myBlocked
.erase(
id
);
137
myMap
[id] = o;
138
}
139
140
141
std::set<GUIGlID>
142
GUIGlObjectStorage::getAllIDs
()
const
{
143
AbstractMutex::ScopedLocker
locker(
myLock
);
144
std::set<GUIGlID> result;
145
for
(ObjectMap::const_iterator it =
myMap
.begin(); it !=
myMap
.end(); it++) {
146
result.insert(it->first);
147
}
148
return
result;
149
}
150
151
152
/****************************************************************************/
153
home
gladk
tmp
05
sumo-0.17.1~dfsg
src
utils
gui
globjects
GUIGlObjectStorage.cpp
Generated on Sun Jun 16 2013 07:07:14 for SUMO - Simulation of Urban MObility by
1.8.1.2