text
stringlengths 0
2.2M
|
---|
template <class TYPE>
|
int operator()(const TYPE& object, bdlat_TypeCategory::CustomizedType)
|
{
|
*d_stream_p << "CustomizedType" << ": ";
|
bdlb::PrintMethods::print(*d_stream_p, object, 0, -1);
|
return 0;
|
}
|
template <class TYPE>
|
int operator()(const TYPE& object, bdlat_TypeCategory::Enumeration)
|
{
|
*d_stream_p << "Enumeration" << ": ";
|
bdlb::PrintMethods::print(*d_stream_p, object, 0, -1);
|
return 0;
|
}
|
template <class TYPE>
|
int operator()(const TYPE& object, bdlat_TypeCategory::NullableValue)
|
{
|
*d_stream_p << "NullableValue" << ": ";
|
bdlb::PrintMethods::print(*d_stream_p, object, 0, -1);
|
return 0;
|
}
|
template <class TYPE>
|
int operator()(const TYPE& object, bdlat_TypeCategory::Sequence)
|
{
|
*d_stream_p << "Sequence" << ": ";
|
bdlb::PrintMethods::print(*d_stream_p, object, 0, -1);
|
return 0;
|
}
|
template <class TYPE>
|
int operator()(const TYPE& object, bdlat_TypeCategory::Simple)
|
{
|
*d_stream_p << "Simple" << ": ";
|
bdlb::PrintMethods::print(*d_stream_p, object, 0, -1);
|
return 0;
|
}
|
};
|
} // close package namespace
|
} // close enterprise namespace
|
//..
|
// Notice that this overload set for 'operator()' includes an overload for
|
// 'bslmf::Nil' (as required) but does *not* include an overload for
|
// 'bdlat_TypeCategory::DynamicType' which is never reported as a runtime type
|
// category.
|
//
|
// Now, we can simply use 'bdlat_TypeCategoryUtil' to determine the type of a
|
// given object dispatch control to the corresponding overload of the accessor
|
// functor:
|
//..
|
using namespace BloombergLP;
|
void runUsageExample2()
|
{
|
bsl::ostringstream oss;
|
mine::PrintAccessor accessor(&oss);
|
int intVal = 123;
|
bdlat_TypeCategoryUtil::accessByCategory(intVal, accessor);
|
ASSERT("Simple: 123" == oss.str());
|
oss.str("");
|
bdlb::NullableValue<int> nullableInt;
|
bdlat_TypeCategoryUtil::accessByCategory(nullableInt, accessor);
|
ASSERT("NullableValue: NULL" == oss.str());
|
oss.str("");
|
nullableInt = 321;
|
bdlat_TypeCategoryUtil::accessByCategory(nullableInt, accessor);
|
ASSERT("NullableValue: 321" == oss.str());
|
oss.str("");
|
bsl::vector<int> vec;
|
vec.push_back(123);
|
vec.push_back(345);
|
vec.push_back(987);
|
bdlat_TypeCategoryUtil::accessByCategory(vec, accessor);
|
LOOP_ASSERT(oss.str(), "Array: [ 123 345 987 ]" == oss.str());
|
oss.str("");
|
}
|
//..
|
//
|
///Example 3: Dynamic (Run-Time) Typing and Dispatch
|
///- - - - - - - - - - - - - - - - - - - - - - - - -
|
// In this example, we introduce a class that is the 'bdlat' "dyanmic" type
|
// category and show how its behavior is a generalization of what we have seen
|
// for the "static" 'bdlat' types.
|
//
|
// First, we define a class, 'mine::MyDynamicType', that can hold one of two
|
// value types: either a 'bsl::vector<char>' or a 'bsl::string'.
|
//..
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.