void MoveEvents::addEvent(MoveEvent* moveEvent, const int32_t& id, MoveListMap& map) { MoveListMap::iterator it = map.find(id); if (it == map.end()) { MoveEventList moveEventList; moveEventList.moveEvent[moveEvent->getEventType()].push_back(moveEvent); map[id] = moveEventList; } else { std::list<MoveEvent*>& moveEventList = it->second.moveEvent[moveEvent->getEventType()]; for (std::list<MoveEvent*>::iterator it = moveEventList.begin(); it != moveEventList.end(); ++it) { if ((*it)->getSlot() == moveEvent->getSlot()) { std::cout << "Warning: [MoveEvents::addEvent] Duplicate move event found: " << id << std::endl; } } moveEventList.push_back(moveEvent); } }
inline void MoveEvents::clearMap(MoveListMap& map) { for(MoveListMap::iterator it = map.begin(); it != map.end(); ++it) { for(int32_t i = MOVE_EVENT_FIRST; i <= MOVE_EVENT_LAST; ++i) { EventList& moveEventList = it->second.moveEvent[i]; for(EventList::iterator it = moveEventList.begin(); it != moveEventList.end(); ++it) delete (*it); moveEventList.clear(); } } map.clear(); }
void MoveEvents::addEvent(MoveEvent* moveEvent, int32_t id, MoveListMap& map) { auto it = map.find(id); if (it == map.end()) { MoveEventList moveEventList; moveEventList.moveEvent[moveEvent->getEventType()].push_back(moveEvent); map[id] = moveEventList; } else { std::list<MoveEvent*>& moveEventList = it->second.moveEvent[moveEvent->getEventType()]; for (MoveEvent* existingMoveEvent : moveEventList) { if (existingMoveEvent->getSlot() == moveEvent->getSlot()) { std::cout << "[Warning - MoveEvents::addEvent] Duplicate move event found: " << id << std::endl; } } moveEventList.push_back(moveEvent); } }
void MoveEvents::clearMap(MoveListMap& map) { std::unordered_set<MoveEvent*> set; for (const auto& it : map) { const MoveEventList& moveEventList = it.second; for (int32_t i = 0; i < MOVE_EVENT_LAST; ++i) { for (MoveEvent* moveEvent : moveEventList.moveEvent[i]) { set.insert(moveEvent); } } } map.clear(); for (MoveEvent* moveEvent : set) { delete moveEvent; } }
void MoveEvents::clearMap(MoveListMap& map) { std::unordered_set<MoveEvent*> set; for (const auto& it : map) { const MoveEventList& moveEventList = it.second; for (const auto& i : moveEventList.moveEvent) { for (MoveEvent* moveEvent : i) { set.insert(moveEvent); } } } map.clear(); for (MoveEvent* moveEvent : set) { delete moveEvent; } }