/* Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura */ #pragma once #include #include "library/type_context.h" namespace lean { /** \brief Helper class for making sure we have a cache that is compatible with a given environment and transparency mode. */ template class cache_compatibility_helper { std::unique_ptr m_cache_ptr[LEAN_NUM_TRANSPARENCY_MODES]; public: Cache & get_cache_for(environment const & env, transparency_mode m) { unsigned midx = static_cast(m); if (!m_cache_ptr[midx] || !is_eqp(env, m_cache_ptr[midx]->env())) { m_cache_ptr[midx].reset(new Cache(env)); } return *m_cache_ptr[midx].get(); } Cache & get_cache_for(type_context const & ctx) { return get_cache_for(ctx.env(), ctx.mode()); } void clear() { for (unsigned i = 0; i < 4; i++) m_cache_ptr[i].reset(); } }; /** \brief Helper class for making sure we have a cache that is compatible with a given environment. */ template class transparencyless_cache_compatibility_helper { std::unique_ptr m_cache_ptr; public: Cache & get_cache_for(environment const & env) { if (!m_cache_ptr || !is_eqp(env, m_cache_ptr->env())) { m_cache_ptr.reset(new Cache(env)); } return *m_cache_ptr.get(); } Cache & get_cache_for(type_context const & ctx) { return get_cache_for(ctx.env()); } void clear() { m_cache_ptr.reset(); } }; }