blob: c7928bbdbf389000a1bd8549634311d2aa91e883 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#pragma once
#include <Common/Exception.h>
#include <map>
#include <memory>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
class Block;
/// Scalar results of subqueries
using Scalars = std::map<String, Block>;
class Context;
/// Most used types have shorter names
using ContextPtr = std::shared_ptr<const Context>;
using ContextMutablePtr = std::shared_ptr<Context>;
using ContextWeakPtr = std::weak_ptr<const Context>;
using ContextWeakMutablePtr = std::weak_ptr<Context>;
template <class Shared = ContextPtr>
struct WithContextImpl
{
using Weak = typename Shared::weak_type;
using ConstShared = std::shared_ptr<const typename Shared::element_type>;
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<ContextMutablePtr>;
}
|