clang-tools 20.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. | |
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. | |
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 . | |
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. | |
template<class Type > | |
Context | derive (const Key< Type > &Key, std::decay_t< Type > Value) const & |
Derives a child context It is safe to move or destroy a parent context after calling derive(). | |
template<class Type > | |
Context | derive (const Key< Type > &Key, std::decay_t< Type > Value) && |
template<class Type > | |
Context | derive (Type &&Value) const & |
Derives a child context, using an anonymous key. | |
template<class Type > | |
Context | derive (Type &&Value) && |
Context | clone () const |
Clone this context object. | |
Static Public Member Functions | |
static Context | empty () |
Returns an empty root context that contains no data. | |
static const Context & | current () |
Returns the context for the current thread, creating it if needed. | |
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.
|
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::trace::EventTracer::beginSpan(), clang::clangd::ClangdServer::createConfiguredContextProvider(), clang::clangd::DirectoryBasedGlobalCompilationDatabase::DirectoryBasedGlobalCompilationDatabase(), clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::enqueue(), clang::clangd::runAsync(), and clang::clangd::TUScheduler::TUScheduler().
|
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::trace::EventTracer::beginSpan(), clang::clangd::cancelableTask(), clang::clangd::ClangdServer::createConfiguredContextProvider(), clang::clangd::Config::current(), clang::clangd::DirectoryBasedGlobalCompilationDatabase::DirectoryBasedGlobalCompilationDatabase(), clang::clangd::DirectoryBasedGlobalCompilationDatabase::BroadcastThread::enqueue(), clang::clangd::TUScheduler::getFileBeingProcessedInContext(), clang::clangd::lspEncoding(), clang::clangd::trace::makeSpanContext(), clang::clangd::LSPBinder::UntypedOutgoingMethod::operator OutgoingMethod< Request, Response >(), clang::clangd::runAsync(), clang::clangd::TUScheduler::runWithPreamble(), clang::clangd::TEST_F(), and clang::clangd::TUScheduler::TUScheduler().
|
inline |
Definition at line 127 of file Context.h.
References Context(), and clang::clangd::Value.
|
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 119 of file Context.h.
References Context(), and clang::clangd::Value.
Referenced by clang::clangd::cancelableTask(), derive(), clang::clangd::TUScheduler::runWithPreamble(), clang::clangd::TEST(), and clang::clangd::TEST_F().
Definition at line 142 of file Context.h.
References clang::clangd::Value.
Derives a child context, using an anonymous key.
Intended for objects stored only for their destructor's side-effect.
Definition at line 137 of file Context.h.
References derive(), 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 98 of file Context.h.
References clang::clangd::Type.
Referenced by clang::clangd::cancelableTask(), clang::clangd::fromJSON(), getExisting(), clang::clangd::lspEncoding(), and clang::clangd::TEST().
Definition at line 29 of file Context.cpp.
References clang::clangd::currentContext().