text
stringlengths
0
2.2M
return rv;
}
template <class TEST_DATA,
bsl::size_t NUM_DATA>
void printDefaultRoundTripTester(const TEST_DATA (&DATA)[NUM_DATA])
// Verify round trip of 'printDefault'/'parseDefault' for the values in the
// specified 'DATA' array of the deduced 'NUM_DATA' length. The deduced
// 'TEST_DATA' must provide a member 'Type' that will be printed from, and
// parsed into.
{
typedef typename TEST_DATA::Type Type;
typedef typename GetDecodeType<Type>::Type DecodeType;
// Some types we can print/encode from, but cannot parse/decode into.
// 'GetDecodeType' is the level of indirection that solves that issue.
for (bsl::size_t i = 0; i < NUM_DATA; ++i) {
const int LINE = DATA[i].d_line;
const Type INPUT = DATA[i].d_input;
bsl::stringstream ss;
Print::printDefault(ss, INPUT);
ASSERTV(LINE, ss.good());
const bsl::string ENCODED(replaceCharEntities(ss.str()));
DecodeType decoded;
int rc;
ASSERTV(LINE, 0 == (rc = Util::parseDefault(&decoded,
ENCODED.data(),
intLength(ENCODED))));
if (0 == rc) {
// To avoid a "reading uninitialized 'decode'" warning
ASSERTV(LINE, ENCODED, decoded, INPUT, INPUT == decoded);
}
}
}
template <class INPUT_TYPE>
struct RoundTripTestData {
// The non-local test data type that is required for test helper function
// templates to compile in C++03.
typedef INPUT_TYPE Type;
int d_line;
Type d_input;
};
} // close namespace TestMachinery
// ===============
// struct TestEnum
// ===============
namespace TestNamespace {
struct TestEnum {
enum Value {
VALUE1 = 1,
VALUE2 = 2,
VALUE3 = 3
};
};
bsl::ostream& operator<<(bsl::ostream& stream, TestEnum::Value rhs)
{
switch (rhs) {
case TestEnum::VALUE1:
return stream << "VALUE1"; // RETURN
case TestEnum::VALUE2:
return stream << "VALUE2"; // RETURN
case TestEnum::VALUE3:
return stream << "VALUE3"; // RETURN
default:
return stream << "(* UNKNOWN *)"; // RETURN
}
}
} // close namespace TestNamespace
using TestNamespace::TestEnum;
// ==========================================
// bdlat_EnumFunctions Overrides for TestEnum
// ==========================================
namespace BloombergLP {
namespace bdlat_EnumFunctions {
template <>
struct IsEnumeration<TestEnum::Value> : bslmf::MetaInt<1> {
};
template <>
int fromInt<TestEnum::Value>(TestEnum::Value *result, int number)
{
switch (number) {