azure-core
Classes | Public Member Functions | Static Public Attributes | List of all members
Azure::Core::Context Class Referencefinal

A context is a node within a tree that represents deadlines and key/value pairs.

#include <context.hpp>

Classes

class  Key
 A key used to store and retrieve data in an Azure::Core::Context object. More...
 

Public Member Functions

 Context ()
 Constructs a new context with no deadline, and no value associated. More...
 
Contextoperator= (const Context &other)=default
 Assigns Context to another Context instance. More...
 
Context WithDeadline (DateTime const &deadline) const
 Creates a context with a deadline. More...
 
template<class T >
Context WithValue (Key const &key, T &&value) const
 Creates a context without a deadline, but with key and value associated with it. More...
 
DateTime GetDeadline () const
 Gets the deadline for this context or the branch of contexts this context belongs to. More...
 
template<class T >
bool TryGetValue (Key const &key, T &outputValue) const
 Gets the value associated with a key parameter within this context or the branch of contexts this context belongs to. More...
 
void Cancel ()
 Cancels the context. More...
 
bool IsCancelled () const
 Checks if the context is cancelled. More...
 
void ThrowIfCancelled () const
 Checks if the context is cancelled. More...
 
std::shared_ptr< Tracing::TracerProviderGetTracerProvider ()
 Returns the tracer provider for the current context.
 
void SetTracerProvider (std::shared_ptr< Tracing::TracerProvider > tracerProvider)
 Sets the tracer provider for the current context.
 

Static Public Attributes

static AZ_CORE_DLLEXPORT Context ApplicationContext
 The application context (root). More...
 

Constructor & Destructor Documentation

◆ Context()

Azure::Core::Context::Context ( )
inline

Member Function Documentation

◆ Cancel()

void Azure::Core::Context::Cancel ( )
inline

◆ GetDeadline()

Azure::DateTime Azure::Core::Context::GetDeadline ( ) const
Returns
The deadline associated with the context; Azure::DateTime::max() if no deadline is specified.

◆ IsCancelled()

bool Azure::Core::Context::IsCancelled ( ) const
inline
Returns
true if this context is cancelled; otherwise, false.

◆ operator=()

Context& Azure::Core::Context::operator= ( const Context other)
default
Parameters
otherAnother instance to copy.
Returns
A reference to this Context.

◆ ThrowIfCancelled()

void Azure::Core::Context::ThrowIfCancelled ( ) const
inline
Exceptions
Azure::Core::OperationCancelledExceptionif the context is cancelled.

◆ TryGetValue()

template<class T >
bool Azure::Core::Context::TryGetValue ( Key const &  key,
T &  outputValue 
) const
inline
Template Parameters
TThe type of the value to be retrieved.
Parameters
keyA key associated with a context to find.
outputValueA reference to the value corresponding to the key to be set, if found within the context tree.
Returns
true if key is found, with outputValue set to the value associated with the key found; otherwise, false.
Note
The outputValue is left unmodified if the key is not found.

◆ WithDeadline()

Context Azure::Core::Context::WithDeadline ( DateTime const &  deadline) const
inline
Parameters
deadlineA point in time after which a context expires.
Returns
A child context with deadline.

◆ WithValue()

template<class T >
Context Azure::Core::Context::WithValue ( Key const &  key,
T &&  value 
) const
inline
Template Parameters
TThe type of the value to be stored with the key.
Parameters
keyA key to associate with this context.
valueA value to associate with this context.
Returns
A child context with no deadline and the key and value associated with it.

Member Data Documentation

◆ ApplicationContext

Context Context::ApplicationContext
static

The documentation for this class was generated from the following files: