Mar 14, 2017 at 9:25pm UTC
So when I do this
1 2 3 4 5 6 7 8 9 10 11 12 13
auto iterator = listeners_[event->type].begin();
while (iterator != listeners_[event->type].end()) {
iterator->function(event);
updateEvents(event->type, &iterator);//this will ++it
}
std::list<Listener>::iterator* iterator_point = &iterator;
iterator_point->//there is no Listener's memembers (name, id...)
Pointer to iterator doesn't shows any of the Listener's members.
Last edited on Mar 14, 2017 at 9:25pm UTC
Mar 15, 2017 at 11:30pm UTC
And also how can I increment iterator's pointer?
iterator++ and (*iterator)++ doesn't work.
Mar 15, 2017 at 11:40pm UTC
The iterator is already pointing to the end so it is not possible to go any further.
Mar 15, 2017 at 11:52pm UTC
I don't understand. My iterator is stuck at first element.
In 'updateEvents' method, is this code that doesn't work:
*iterator++
Mar 15, 2017 at 11:56pm UTC
OK, I thought it was after the loop as it appears in the code.
If the pointer is called iterator_point you can increment the iterator by doing (*iterator_point)++
.
Mar 16, 2017 at 12:03am UTC
I already tried that and nothing. Btw your first answer works for Listener's members.
Mar 16, 2017 at 12:05am UTC
Nothing what? It's difficult guess what the problem is without seeing the code.
Mar 16, 2017 at 12:09am UTC
I know iterator is stuck at first element because cout is printing the first initialized element over and over. And just ignore logical code, we are focusing on incrementing iterator.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
void EventManager::updateEvents(sf::Event::EventType event_type, std::list<Listener>::iterator* iterator) {
initializeListenerUpdates(event_type, iterator);
}
void EventManager::initializeListenerUpdates(sf::Event::EventType event_type, std::list<Listener>::iterator* iterator) {
std::cout << (*iterator)->name << std::endl;
for (auto & listener_update : listener_updates_) {
if (listener_update.to_remove_ && containsListener(listener_update.event_type, listener_update.name)) {
bool match = false ;
if (listener_update.event_type == event_type && (*iterator)->name == listener_update.name) {
match = true ;
(*iterator)++;
}
if (listeners_[listener_update.event_type].size() <= 1) {
listeners_.erase(listener_update.event_type);
continue ;
}
deleteListener(listener_update.event_type, listener_update.name);
if (!match) (*iterator)++;
} else if (!listener_update.to_remove_ && !containsListener(listener_update.event_type, listener_update.name)) {
(*iterator)++;
if (listeners_.find(listener_update.event_type) == listeners_.end()) {
std::list<Listener> event_type_functions_list;
event_type_functions_list.push_back(Listener(listener_update.name, listener_update.function));
listeners_[listener_update.event_type] = event_type_functions_list;
} else {
if (containsListener(listener_update.event_type, listener_update.name)) return ;
listeners_[listener_update.event_type].push_back(Listener(listener_update.name, listener_update.function));
}
}
}
listener_updates_.clear();
}
Last edited on Mar 16, 2017 at 12:26am UTC
Mar 16, 2017 at 12:26am UTC
If the iterator is not incremented it's probably because none of the (*iterator)++;
statements are being executed.
Last edited on Mar 16, 2017 at 12:27am UTC
Mar 16, 2017 at 12:36am UTC
You are right, the problem is somewhere in logic. Thank you very much! I wish this site had an like button or something like that.