#ifndef CONTAINERS_MANAGER_H #define CONTAINERS_MANAGER_H namespace fw { class ContainersManager : public Singleton<ContainersManager> { public: template<typename T, typename C> void MapDeleteAllFirst(std::map<T, C> map) { for (auto it = map.begin(); it != map.end(); it++) { T* p = it->first; SAFE_DELETE(p); } map.clear(); } template<typename T, typename C> void MapDeleteAllSecond(std::map<T, C> map) { for (auto it = map.begin(); it != map.end(); it++) { C* p = it->Second; SAFE_DELETE(p); } map.clear(); } template<typename C> bool Contains(const std::vector<C> vec, C value) { for (uint32 i = 0; i < vec.size(); i++) { if (vec[i] == value) { return true; } } return false; } // Renvois une entrée au hasard d'une std::map template<typename T, typename C> std::pair<T, C> PickOnePairAtRandom(const std::map<T, C>& vMapContainer) { std::pair<T, C> randomPair; if (!vMapContainer.empty()) { int iRandomStopIterationNum = (rand() % vMapContainer.size()); int iCount = 0; for (auto it = vMapContainer.begin(); it != vMapContainer.end(); it++) { if (iCount == iRandomStopIterationNum) return *it; ++iCount; } } return randomPair; } template<typename T> static bool ContainsVEC(std::vector<T>& vec, T v) { return std::find(vec.begin(), vec.end(), v) != vec.end(); } template<typename T> static void RemoveVEC(std::vector<T>& vec, T v) { vec.erase(std::remove(vec.begin(), vec.end(), v), vec.end()); } private: }; template<> ContainersManager* Singleton<ContainersManager>::ms_instance = nullptr; } #endif