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.
 
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.
 
bool IsCancelled () const
 Checks if the context is cancelled. More...
 
void ThrowIfCancelled () const
 Checks if the context is cancelled. More...
 

Static Public Attributes

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

Member Function Documentation

◆ 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.

◆ 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.

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