#pragma once #include #include "common.hpp" #include "utils/concurrency.hpp" POLYBAR_NS template class cache { public: using map_type = std::unordered_map>; using safe_map_type = mutex_wrapper; bool check(const KeyType& key) { std::lock_guard guard(m_cache); return m_cache.find(key) == m_cache.end(); } template shared_ptr object(const KeyType& key, MakeArgs&&... make_args) { std::lock_guard guard(m_cache); auto ptr = m_cache[key].lock(); if (!ptr) { m_cache[key] = ptr = make_shared(forward(make_args)...); } return ptr; } private: safe_map_type m_cache; }; POLYBAR_NS_END