Skip to content

Commit f38870a

Browse files
committed
Rename variables in Messenger
1 parent cba953f commit f38870a

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

render_pipeline/rppanda/showbase/messenger.hpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class RENDER_PIPELINE_DECL Messenger : public TypedObject
6363

6464
using AcceptorType = std::pair<EventFunction, bool>; // { function, persistent }
6565
using AcceptorMap = std::unordered_map<const DirectObject*, AcceptorType>;
66-
using HooksType = std::unordered_map<EventName, AcceptorMap>;
66+
using CallbacksType = std::unordered_map<EventName, AcceptorMap>;
6767

6868
public:
6969
static Messenger* get_global_instance();
@@ -136,7 +136,7 @@ class RENDER_PIPELINE_DECL Messenger : public TypedObject
136136
void remove_hook(const EventName& event_name);
137137

138138
EventHandler* handler_;
139-
HooksType hooks_;
139+
CallbacksType callbacks_;
140140

141141
static const AcceptorMap empty_acceptor_;
142142

@@ -155,15 +155,15 @@ class RENDER_PIPELINE_DECL Messenger : public TypedObject
155155
inline size_t Messenger::get_num_listners() const
156156
{
157157
size_t count = 0;
158-
for (const auto& hook: hooks_)
159-
count += hook.second.size();
158+
for (const auto& callback: callbacks_)
159+
count += callback.second.size();
160160
return count;
161161
}
162162

163163
inline size_t Messenger::get_num_listners(const EventName& event_name) const
164164
{
165-
const auto found = hooks_.find(event_name);
166-
if (found != hooks_.end())
165+
const auto found = callbacks_.find(event_name);
166+
if (found != callbacks_.end())
167167
return found->second.size();
168168
else
169169
return 0;
@@ -176,38 +176,38 @@ inline AsyncFuture* Messenger::get_future(const EventName& event_name) const
176176

177177
inline void Messenger::ignore(const EventName& event_name, const DirectObject* object)
178178
{
179-
auto found = hooks_.find(event_name);
180-
if (found == hooks_.end())
179+
auto found = callbacks_.find(event_name);
180+
if (found == callbacks_.end())
181181
return;
182182

183-
auto& hook = found->second;
184-
auto hook_found = hook.find(object);
185-
if (hook_found != hook.end())
186-
hook.erase(hook_found);
183+
auto& acceptor_map = found->second;
184+
auto acceptor_map_found = acceptor_map.find(object);
185+
if (acceptor_map_found != acceptor_map.end())
186+
acceptor_map.erase(acceptor_map_found);
187187

188-
if (hook.empty())
188+
if (acceptor_map.empty())
189189
remove_hook(event_name);
190190
}
191191

192192
inline void Messenger::ignore_all(const EventName& event_name)
193193
{
194-
auto found = hooks_.find(event_name);
195-
if (found == hooks_.end())
194+
auto found = callbacks_.find(event_name);
195+
if (found == callbacks_.end())
196196
return;
197197

198198
remove_hook(event_name);
199199
}
200200

201201
inline void Messenger::ignore_all(const DirectObject* object)
202202
{
203-
auto iter = hooks_.begin();
204-
const auto iter_end = hooks_.end();
203+
auto iter = callbacks_.begin();
204+
const auto iter_end = callbacks_.end();
205205
while (iter != iter_end)
206206
{
207-
auto& hook = iter->second;
208-
auto found = hook.find(object);
209-
if (found != hook.end())
210-
hook.erase(found);
207+
auto& acceptor_map = iter->second;
208+
auto found = acceptor_map.find(object);
209+
if (found != acceptor_map.end())
210+
acceptor_map.erase(found);
211211

212212
// iterator becomes invalidated after erase.
213213
auto iter_tmp = iter;
@@ -220,19 +220,19 @@ inline void Messenger::ignore_all(const DirectObject* object)
220220
inline auto Messenger::get_all_accepting(const DirectObject* object) const -> std::vector<EventName>
221221
{
222222
std::vector<EventName> events;
223-
for (const auto& kv : hooks_)
223+
for (const auto& kv : callbacks_)
224224
{
225-
const auto& hook = kv.second;
226-
if (hook.find(object) != hook.end())
225+
const auto& acceptor_map = kv.second;
226+
if (acceptor_map.find(object) != acceptor_map.end())
227227
events.push_back(kv.first);
228228
}
229229
return events;
230230
}
231231

232232
inline bool Messenger::is_accepting(const EventName& event_name, const DirectObject* object) const
233233
{
234-
auto found = hooks_.find(event_name);
235-
if (found != hooks_.end())
234+
auto found = callbacks_.find(event_name);
235+
if (found != callbacks_.end())
236236
{
237237
if (found->second.find(object) != found->second.end())
238238
return true;
@@ -290,14 +290,14 @@ inline void Messenger::add_hook(const EventName& event_name)
290290
inline void Messenger::remove_hook(const EventName& event_name)
291291
{
292292
handler_->remove_hook(event_name, process_event, this);
293-
hooks_.erase(event_name);
293+
callbacks_.erase(event_name);
294294
}
295295

296296
inline void Messenger::clear()
297297
{
298-
for (auto&& hook : hooks_)
299-
handler_->remove_hook(hook.first, process_event, this);
300-
hooks_.clear();
298+
for (auto&& kv : callbacks_)
299+
handler_->remove_hook(kv.first, process_event, this);
300+
callbacks_.clear();
301301
}
302302

303303
inline bool Messenger::is_empty() const
@@ -308,8 +308,8 @@ inline bool Messenger::is_empty() const
308308
inline auto Messenger::get_events() const -> std::vector<EventName>
309309
{
310310
std::vector<EventName> events;
311-
events.reserve(hooks_.size());
312-
for (const auto& kv: hooks_)
311+
events.reserve(callbacks_.size());
312+
for (const auto& kv: callbacks_)
313313
events.push_back(kv.first);
314314
return events;
315315
}

src/rppanda/showbase/messenger.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void Messenger::accept(const EventName& event_name, const EventFunction& method,
7171

7272
add_hook(event_name);
7373

74-
auto& object_callbacks = hooks_[event_name];
74+
auto& object_callbacks = callbacks_[event_name];
7575

7676
auto found = object_callbacks.find(object);
7777
if (found == object_callbacks.end())
@@ -89,8 +89,8 @@ void Messenger::accept(const EventName& event_name, const EventFunction& method,
8989

9090
auto Messenger::who_accepts(const EventName& event_name) const -> const AcceptorMap&
9191
{
92-
auto found = hooks_.find(event_name);
93-
if (found != hooks_.end())
92+
auto found = callbacks_.find(event_name);
93+
if (found != callbacks_.end())
9494
return found->second;
9595
else
9696
return empty_acceptor_;
@@ -101,23 +101,23 @@ void Messenger::process_event(const Event* ev, void* user_data)
101101
const auto& event_name = ev->get_name();
102102

103103
auto self = reinterpret_cast<Messenger*>(user_data);
104-
auto& hook = self->hooks_.at(event_name);
104+
auto& acceptor_map = self->callbacks_.at(event_name);
105105

106106
// call in object_callbacks
107107
{
108-
auto iter = hook.cbegin();
109-
auto iter_end = hook.cend();
108+
auto iter = acceptor_map.cbegin();
109+
auto iter_end = acceptor_map.cend();
110110
for (; iter != iter_end; ++iter)
111111
{
112112
iter->second.first(ev);
113113

114114
// NOTE: the erased element is only invalidated, so we can use the iterator.
115115
if (!iter->second.second)
116-
hook.erase(iter);
116+
acceptor_map.erase(iter);
117117
}
118118
}
119119

120-
if (hook.empty())
120+
if (acceptor_map.empty())
121121
self->remove_hook(event_name);
122122
}
123123

0 commit comments

Comments
 (0)