C++ Server-Side SDK
LaunchDarkly SDK
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
launchdarkly::AttributeReference Class Reference

#include <attribute_reference.hpp>

Public Types

using SetType = std::set< AttributeReference >
 

Public Member Functions

std::string const & Component (std::size_t depth) const
 
std::size_t Depth () const
 
bool IsKind () const
 
bool Valid () const
 
std::string const & RedactionName () const
 
 AttributeReference (std::string ref_str)
 
 AttributeReference (char const *ref_str)
 
 AttributeReference ()
 
bool operator== (AttributeReference const &other) const
 
bool operator== (std::vector< std::string_view > const &path) const
 
bool operator!= (AttributeReference const &other) const
 
bool operator!= (std::vector< std::string_view > const &path) const
 
bool operator< (AttributeReference const &rhs) const
 

Static Public Member Functions

static AttributeReference FromReferenceStr (std::string ref_str)
 
static AttributeReference FromLiteralStr (std::string lit_str)
 
static std::string PathToStringReference (std::vector< std::string_view > path)
 

Friends

std::ostream & operator<< (std::ostream &os, AttributeReference const &ref)
 

Detailed Description

Represents an attribute name or path expression identifying a value within a launchdarkly::Context. This can be used to retrieve a value with launchdarkly::Context::Get, or to identify an attribute or nested value that should be considered private with launchdarkly::AttributesBuilder<BuilderReturn, BuildType>::SetPrivate or launchdarkly::AttributesBuilder<BuilderReturn,BuildType>::AddPrivateAttribute (the SDK configuration can also have a list of private attribute references).

This is represented as a separate type, rather than just a string, so that validation and parsing can be done ahead of time if an attribute reference will be used repeatedly later (such as in flag evaluations).

If the string starts with '/', then this is treated as a slash-delimited path reference where the first component is the name of an attribute, and subsequent components are the names of nested JSON object properties. In this syntax, the escape sequences "~0" and "~1" represent '~' and '/' respectively within a path component.

If the string does not start with '/', then it is treated as the literal name of an attribute.

Constructor & Destructor Documentation

◆ AttributeReference() [1/3]

launchdarkly::AttributeReference::AttributeReference ( std::string  ref_str)

Construct an attribute reference from a string.

Parameters
ref_strThe string to make an attribute reference from.

◆ AttributeReference() [2/3]

launchdarkly::AttributeReference::AttributeReference ( char const *  ref_str)

Construct an attribute reference from a constant string.

Parameters
ref_strThe string to make an attribute reference from.

◆ AttributeReference() [3/3]

launchdarkly::AttributeReference::AttributeReference ( )

Default constructs an invalid attribute reference.

Member Function Documentation

◆ Component()

std::string const & launchdarkly::AttributeReference::Component ( std::size_t  depth) const

Get the component of the attribute reference at the specified depth.

For example, Component(1) on the reference /a/b/c would return b.

Parameters
depthThe depth to get a component for.
Returns
The component at the specified depth or an empty string if the depth is out of bounds.

◆ Depth()

std::size_t launchdarkly::AttributeReference::Depth ( ) const

Get the total depth of the reference.

For example, Depth() on the reference /a/b/c would return 3.

Returns

◆ FromLiteralStr()

AttributeReference launchdarkly::AttributeReference::FromLiteralStr ( std::string  lit_str)
static

Create a string from an attribute that is known to be a literal.

This allows escaping literals that contained special characters.

Parameters
lit_strThe literal attribute name.
Returns
A new AttributeReference based on the literal name.

◆ FromReferenceStr()

AttributeReference launchdarkly::AttributeReference::FromReferenceStr ( std::string  ref_str)
static

Create an attribute from a string that is known to be an attribute reference string.

Parameters
ref_strThe reference string.
Returns
A new AttributeReference based on the reference string.

◆ IsKind()

bool launchdarkly::AttributeReference::IsKind ( ) const

Check if the reference is a "kind" reference. Either /kind or kind.

Returns
True if it is a kind reference.

◆ PathToStringReference()

std::string launchdarkly::AttributeReference::PathToStringReference ( std::vector< std::string_view >  path)
static

For a path, a series of names to address an attribute, create a name suitable for including in event meta data.

Parameters
pathThe path to get a name for.
Returns
The path as a reference string.

◆ RedactionName()

std::string const & launchdarkly::AttributeReference::RedactionName ( ) const

The redaction name will always be an attribute reference compatible string. So, for instance, a literal that contained /attr would be converted to /~1attr.

Returns
String to use in redacted attributes.

◆ Valid()

bool launchdarkly::AttributeReference::Valid ( ) const

Check if the reference is valid.

Returns
True if the reference is valid.

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