#pragma once #include #include #include namespace DB { namespace ErrorCodes { extern const int LOGICAL_ERROR; } class Block; /// Scalar results of subqueries using Scalars = std::map; class Context; /// Most used types have shorter names using ContextPtr = std::shared_ptr; using ContextMutablePtr = std::shared_ptr; using ContextWeakPtr = std::weak_ptr; using ContextWeakMutablePtr = std::weak_ptr; template struct WithContextImpl { using Weak = typename Shared::weak_type; using ConstShared = std::shared_ptr; using ConstWeak = typename ConstShared::weak_type; WithContextImpl() = default; explicit WithContextImpl(Weak context_) : context(context_) {} inline Shared getContext() const { auto ptr = context.lock(); if (!ptr) throw Exception(ErrorCodes::LOGICAL_ERROR, "Context has expired"); return ptr; } protected: Weak context; }; using WithContext = WithContextImpl<>; using WithConstContext = WithContext; /// For compatibility. Use WithContext. using WithMutableContext = WithContextImpl; }