Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bdld_datummaker
[Package bdld]

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

Namespaces

namespace  bdld

Detailed Description

Outline
Purpose:
Provide a mechanism for easily creating bdld::Datum objects.
Classes:
bdld::DatumMaker a mechanism for easily creating bdld::Datum objects
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;
          }
      }

      return bdld::Datum::createInteger(count);
  }
Then, within the test driver for numCount, we define a bdld::DatumMaker, and use it to initialize an array to test numCount: Here, we create the array we want to use as an argument to numCount:
  bdld::Datum array = m.a(
      m(),
      m(bdld::DatumError(-1)),
      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")
  );
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);