Debian Codegraph @

LspCpp/src/jsonrpc/Context.cpp

raw
1 //===--- Context.cpp ---------------------------------------------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "LibLsp/JsonRpc/Context.h"
10 #include <cassert>
11
12 namespace lsp
13 {
14
15 Context Context::empty()
16 {
17 return Context(/*dataPtr=*/nullptr);
18 }
19
20 Context::Context(std::shared_ptr<Data const> DataPtr) : dataPtr(std::move(DataPtr))
21 {
22 }
23
24 Context Context::clone() const
25 {
26 return Context(dataPtr);
27 }
28
29 static Context& currentContext()
30 {
31 static thread_local auto c = Context::empty();
32 return c;
33 }
34
35 Context const& Context::current()
36 {
37 return currentContext();
38 }
39
40 Context Context::swapCurrent(Context Replacement)
41 {
42 std::swap(Replacement, currentContext());
43 return Replacement;
44 }
45
46 } // namespace lsp