#ifndef __NCPP_INTERNAL_HELPERS_HH #define __NCPP_INTERNAL_HELPERS_HH #include #include #include namespace ncpp::internal { class Helpers { public: template static TValue lookup_map_entry (std::map *&_map, std::mutex &_mutex, TKey _key, std::function create_value) { std::lock_guard lock (_mutex); if (_map == nullptr) { _map = new std::map (); } TValue ret; auto entry = _map->find (_key); if (entry == _map->end ()) { ret = create_value (_key); } else { ret = entry->second; } return ret; } template static void remove_map_entry (std::map *&_map, std::mutex &_mutex, TKey _key) { std::lock_guard lock (_mutex); if (_map == nullptr) return; auto entry = _map->find (_key); if (entry == _map->end ()) return; _map->erase (entry); } }; } #endif