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

Detailed Description

Outline

Purpose

Provide a mechanism for easily creating bdld::Datum objects.

Classes

See also

Description

This component defines a concrete mechanism, DatumMaker that allows bdld::Datum objects to be created with minimal syntax.

Usage

This section illustrates intended use of this component.

Example 1: Testing of a function

Suppose we want to test a function, numCount, that returns the number of numeric elements in a bdld::Datum array.

First we implement the function:

bdld::Datum numCount(const bdld::Datum arrray)
{
bdld::DatumArrayRef aRef = arrray.theArray();
int count = 0;
for (bdld::DatumArrayRef::SizeType i = 0; i < aRef.length(); ++i) {
if (aRef[i].isInteger() ||
aRef[i].isInteger64() ||
aRef[i].isDouble()) {
++count;
}
}
}
Definition bdld_datum.h:2461
size_type length() const
Return a const pointer to the length of the array.
Definition bdld_datum.h:4886
Datum::SizeType SizeType
Definition bdld_datum.h:2485
Definition bdld_datum.h:787
DatumArrayRef theArray() const
Definition bdld_datum.h:4257
static Datum createInteger(int value)
Return, by value, a datum having the specified int value.
Definition bdld_datum.h:3848

Then, within the test driver for numCount, we define a bdld::DatumMaker, and use it to initialize an array to test numCount:

Definition bdld_datummaker.h:158

Here, we create the array we want to use as an argument to numCount:

bdld::Datum array = m.a(
m(),
m.a(
m(true),
m(false)),
m(42.0),
m(false),
m(0),
m(true),
m(bsls::Types::Int64(424242)),
m.m(
"firstName", "Bart",
"lastName", "Simpson",
"age", 10
),
m(bdlt::Date(2016, 10, 14)),
m(bdlt::Time(13, 00, 00, 000)),
m(bdlt::Datetime(2016, 10, 14, 13, 01, 30, 87)),
m(bdlt::DatetimeInterval(280, 13, 41, 12, 321)),
m("foobar")
);
Definition bdld_datumerror.h:160
Definition bdlt_date.h:294
Definition bdlt_datetimeinterval.h:201
Definition bdlt_datetime.h:331
Definition bdlt_time.h:196
long long Int64
Definition bsls_types.h:132

Next we call the function with the array-Datum as its first argument:

bdld::Datum retVal = numCount(array);

Finally we verify the return value:

assert(retVal.theInteger() == 3);
int theInteger() const
Definition bdld_datum.h:4426