BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball_userfields

Detailed Description

Outline

Purpose

Provide a container of user supplied field values.

Classes

See also
ball_userfieldvalue

Description

This component provides a value-semantic container-type, ball::UserFields, that represents a (randomly accessible) sequence of ball::UserFieldValue objects. Each user field value contained in the sequence functions as a discriminated union of the types described by ball::UserFieldType::Enum (integer, double, string, etc). Values can be added to the sequence using the append* manipulators, and can be manipulated and accessed using operator[]. Additionally, ball::UserFields exposes a random-access iterator providing non-modifiable access to the sequence through the begin and end methods.

Usage

This section illustrates intended use of this component.

Example 1: Basic Use of ball::UserFields

In the following example we demonstrate populating a ball::UserFields object with a sequence of field values.

First, we define the signature for a callback, populateUserFields. Most often ball::UserFields objects are populated by a callback, such as the one described by the ball::LoggerManagerConfiguration UserFieldsPopulatorCallback.

/// Populate the specified `fields` with the username and current task
/// identifier. The behavior is undefined unless `fields` is empty.
void populateLoggingFields(ball::UserFields *fields)
{
Definition ball_userfields.h:136

Next, we assert the precondition that fields is empty:

BSLS_ASSERT(0 == fields->length());
int length() const
Return the number of user field values in this object.
Definition ball_userfields.h:406
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804

Now, we populate the fields object with the username and current task identifier (for the purpose of illustration, these are simply constants):

static const char *TEST_USER = "testUser";
static const bsls::Types::Int64 TEST_TASK = 4315;
fields->appendString(TEST_USER);
fields->appendInt64(TEST_TASK);
void appendInt64(bsls::Types::Int64 value)
Definition ball_userfields.h:337
void appendString(const bsl::string_view &value)
Definition ball_userfields.h:349
long long Int64
Definition bsls_types.h:132

Finally, for the purposes of illustration, we verify that fields has been set correctly:

assert(2 == fields->length());
assert(Type::e_STRING == fields->value(0).type());
assert(TEST_USER == fields->value(0).theString());
assert(Type::e_INT64 == fields->value(1).type());
assert(TEST_TASK == fields->value(1).theInt64());
}
const bsl::string & theString() const
Definition ball_userfieldvalue.h:476
const bsls::Types::Int64 & theInt64() const
Definition ball_userfieldvalue.h:460
ball::UserFieldType::Enum type() const
ball::UserFieldValue & value(int index)
Definition ball_userfields.h:373