Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bdld_datumudt
[Package bdld]

Provide a type to represent a user-defined type. More...

Namespaces

namespace  bdld

Detailed Description

Outline
Purpose:
Provide a type to represent a user-defined type.
Classes:
bdld::DatumUdt a value-semantic type representing user-defined type
See also:
Component bdld_datum, Component bdld_datumerror, bdld_binaryref
Description:
This component provides a single, simply-constrained (in-core value-semantic) attribute class, bdld::DatumUdt, that is used to extend the set of possible types that can be held by Datum objects.
Attributes:
  Name                Type         Simple Constraints
  ------------------  -----------  ------------------
  data_p              void *       none
  type                int          [0 .. 65355]
  • data_p: pointer to an external object/memory.
  • type: user type associated with the pointer.
This component provides a way to extend the set of data types that are natively supported by the Datum mechanism by allowing the client associate an opaque pointer to user data with the data type information. Note that the bdld::DatumUdt does not access the pointer nor it interpret the type information supplied at construction time. The client code is responsible for interpretation of the type information and casting the pointer back to the pointer to the actual type.
Accessors inside Datum class that need to return a user-defined object, return an instance of DatumUdt.
Usage:
This section illustrates intended use of this component.
Example 1: Basic DatumUdt usage:
Imagine we are using Datum within an expression evaluation subsystem. Within that subsystem, along with the set of types defined by Datum::DataType we also need to hold Sequence and Choice types within Datum values (which are not natively represented by Datum). First, we define the set of types used by our subsystem that are an extension to the types in DatumType:
  struct Sequence {
      struct Sequence *d_next_p;
      int              d_value;
  };

  enum ExtraExpressionTypes {
      e_SEQUENCE = 5,
      e_CHOICE = 6
  };
Notice that the numeric values will be provided as the type attribute to DatumUdt.
Then we create a Sequence object, and create a DatumUdt to hold it (note that we've created the object on the stack for clarity):
  Sequence sequence;
  {
      const bdld::DatumUdt udt(&sequence, e_SEQUENCE);
      assert(e_SEQUENCE == udt.type());
      assert(&sequence  == udt.data());
  }