clang-tools
10.0.0git
|
A context is an immutable container for per-request data that must be propagated through layers that don't care about it. More...
#include <Context.h>
Public Member Functions | |
Context ()=default | |
Same as Context::empty(), please use Context::empty() instead. More... | |
Context (Context const &)=delete | |
Copy operations for this class are deleted, use an explicit clone() method when you need a copy of the context instead. More... | |
Context & | operator= (const Context &)=delete |
Context (Context &&)=default | |
Context & | operator= (Context &&)=default |
template<class Type > | |
const Type * | get (const Key< Type > &Key) const |
Get data stored for a typed Key . More... | |
template<class Type > | |
const Type & | getExisting (const Key< Type > &Key) const |
A helper to get a reference to a Key that must exist in the map. More... | |
template<class Type > | |
Context | derive (const Key< Type > &Key, typename std::decay< Type >::type Value) const & |
Derives a child context It is safe to move or destroy a parent context after calling derive(). More... | |
template<class Type > | |
Context | derive (const Key< Type > &Key, typename std::decay< Type >::type Value) && |
template<class Type > | |
Context | derive (Type &&Value) const & |
Derives a child context, using an anonymous key. More... | |
template<class Type > | |
Context | derive (Type &&Value) && |
Context | clone () const |
Clone this context object. More... | |
Static Public Member Functions | |
static Context | empty () |
Returns an empty root context that contains no data. More... | |
static const Context & | current () |
Returns the context for the current thread, creating it if needed. More... | |
static Context | swapCurrent (Context Replacement) |
A context is an immutable container for per-request data that must be propagated through layers that don't care about it.
An example is a request ID that we may want to use when logging.
Conceptually, a context is a heterogeneous map<Key<T>, T>. Each key has an associated value type, which allows the map to be typesafe.
There is an "ambient" context for each thread, Context::current(). Most functions should read from this, and use WithContextValue or WithContext to extend or replace the context within a block scope. Only code dealing with threads and extension points should need to use other Context objects.
You can't add data to an existing context, instead you create a new immutable context derived from it with extra data added. When you retrieve data, the context will walk up the parent chain until the key is found.
|
default |
Same as Context::empty(), please use Context::empty() instead.
Constructor is defined to workaround a bug in MSVC's version of STL. (arguments of std::future<> must be default-constructible in MSVC).
|
delete |
Copy operations for this class are deleted, use an explicit clone() method when you need a copy of the context instead.
|
default |
Context clang::clangd::Context::clone | ( | ) | const |
Clone this context object.
Definition at line 20 of file Context.cpp.
References Context().
Referenced by clang::clangd::runAsync().
|
static |
Returns the context for the current thread, creating it if needed.
Definition at line 27 of file Context.cpp.
References clang::clangd::currentContext().
Referenced by clang::clangd::cancelableTask(), clang::clangd::TUScheduler::getFileBeingProcessedInContext(), clang::clangd::lspEncoding(), clang::clangd::TUScheduler::run(), and clang::clangd::runAsync().
|
inline |
Derives a child context It is safe to move or destroy a parent context after calling derive().
The child will keep its parent alive, and its data remains accessible.
Definition at line 121 of file Context.h.
Referenced by clang::clangd::cancelableTask(), and clang::clangd::TEST().
Derives a child context, using an anonymous key.
Intended for objects stored only for their destructor's side-effect.
Definition at line 141 of file Context.h.
References clang::clangd::Value.
Definition at line 146 of file Context.h.
References Parent, and clang::clangd::Value.
|
static |
Returns an empty root context that contains no data.
Definition at line 15 of file Context.cpp.
References Context().
Referenced by clang::clangd::currentContext(), and clang::clangd::TEST().
|
inline |
Get data stored for a typed Key
.
If values are not found
Definition at line 100 of file Context.h.
References Type.
Referenced by clang::clangd::isCancelled(), clang::clangd::lspEncoding(), and clang::clangd::TEST().
|
inline |
A helper to get a reference to a Key
that must exist in the map.
Must not be called for keys that are not in the map.
Definition at line 111 of file Context.h.
References clang::clangd::Key< Type >::Key().
Definition at line 29 of file Context.cpp.
References clang::clangd::currentContext().
Referenced by clang::clangd::WithContext::~WithContext().