C++ Server-Side SDK
LaunchDarkly SDK
Public Member Functions | List of all members
launchdarkly::server_side::hooks::HookContext Class Reference

#include <hook.hpp>

Public Member Functions

 HookContext ()=default
 
HookContextSet (std::string key, std::shared_ptr< std::any > value)
 
std::optional< std::shared_ptr< std::any > > Get (std::string const &key) const
 
bool Has (std::string const &key) const
 

Detailed Description

HookContext allows passing arbitrary data from the caller through to hooks.

Example use case:

// Caller creates context with span parent
ctx.Set("otel_span_parent", std::make_shared<std::any>(span_context));
// Pass to variation method
client.BoolVariation(context, "flag-key", false, ctx);
// Hook accesses the span parent
auto span_parent = hook_context.Get("otel_span_parent");

Constructor & Destructor Documentation

◆ HookContext()

launchdarkly::server_side::hooks::HookContext::HookContext ( )
default

Constructs an empty HookContext.

Member Function Documentation

◆ Get()

std::optional< std::shared_ptr< std::any > > launchdarkly::server_side::hooks::HookContext::Get ( std::string const &  key) const

Retrieves a value from the context.

Parameters
keyThe key to look up.
Returns
The shared_ptr if present, or std::nullopt if not found.

◆ Has()

bool launchdarkly::server_side::hooks::HookContext::Has ( std::string const &  key) const

Checks if a key exists in the context.

Parameters
keyThe key to check.
Returns
True if the key exists, false otherwise.

◆ Set()

HookContext & launchdarkly::server_side::hooks::HookContext::Set ( std::string  key,
std::shared_ptr< std::any >  value 
)

Sets a value in the context.

Parameters
keyThe key to set.
valueThe shared_ptr to any type to associate with the key.
Returns
Reference to this context for chaining.

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