Provide utilities for operating on bdlat
"nullable value" types.
More...
Namespaces |
namespace | bdlat |
Detailed Description
- Outline
-
-
- Purpose:
- Provide utilities for operating on
bdlat
"nullable value" types.
-
- Classes:
-
- See also:
- Component bdlat_nullablevaluefunctions, Component bdlat_typecategory
-
- Description:
- This component provides a utility
struct
, bdlat::NullableValueUtil
, which serves as a namespace for a collection of function templates providing derived operations for "nullable value" types. See bdlat_nullablevaluefunctions
for the set of requirements of "nullable value" types in the bdlat
framework. See bdlat_typecategory
for more general information about this framework.
-
- Primitive and Derived Functions of Nullable Values:
- In order to be "plugged in" to the
bdlat
framework as a "nullable value", a type must meet a set of requirements including providing certain function overloads (customization points) and specifying certain type traits, as specified by the bdlat_nullablevaluefunctions
component. We call the required function overloads the "primitive" operations of "nullable value" types. This component provides "derived" operations, which are operations that are exclusively defined in terms of primitive operations, and as such can be used with any "nullable value" type.
-
- Usage:
- In this section we show intended usage of this component.
-
- Example 1: Accessing the Held Value And Its Category:
- Suppose we would like to define a function that detects whether the value held by a nullable value is an array.
- First, we need to define an accessor functor per
bdlat_typecategory'|'ACCESSOR
Functors that will be used to detect whether the held value is an array: class MyArrayDetector {
bool d_didVisitArray;
public:
MyArrayDetector()
: d_didVisitArray(false)
{
}
template <class TYPE>
int operator()(const TYPE& object, bdlat_TypeCategory::Array)
{
d_didVisitArray = true;
return 0;
}
template <class TYPE, class OTHER_CATEGORY>
int operator()(const TYPE&, OTHER_CATEGORY)
{
d_didVisitArray = false;
return 0;
}
bool didVisitArray()
{
return d_didVisitArray;
}
};
Then, we can define a utility struct
, MyNullableValueUtil
, that provides a function for detecting whether or not the held value of a nullable value is an array: Finally, we can use this utility to detect whether nullable values are arrays: