BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlat_typename

Classes

struct  bdlat_TypeName
 
struct  bdlat_TypeName_Imp
 Private class providing implementation of bdlat_TypeName. More...
 

Functions

template<class TYPE >
static const char * bdlat_TypeName_Imp::className (const TYPE *)
 Overloads for basic class types.
 
template<class TYPE >
static const char * bdlat_TypeName_Imp::name (const TYPE *)
 Generic implementation for non-fundamental types.
 
static const char * bdlat_TypeName_Imp::name (const bool *)
 Overloads for fundamental types and char pointers.
 
static const char * bdlat_TypeName_Imp::name (const char *)
 
static const char * bdlat_TypeName_Imp::name (const unsigned char *)
 
static const char * bdlat_TypeName_Imp::name (const signed char *)
 
static const char * bdlat_TypeName_Imp::name (const short *)
 
static const char * bdlat_TypeName_Imp::name (const unsigned short *)
 
static const char * bdlat_TypeName_Imp::name (const int *)
 
static const char * bdlat_TypeName_Imp::name (const unsigned int *)
 
static const char * bdlat_TypeName_Imp::name (const long *)
 
static const char * bdlat_TypeName_Imp::name (const unsigned long *)
 
static const char * bdlat_TypeName_Imp::name (const bsls::Types::Int64 *)
 
static const char * bdlat_TypeName_Imp::name (const bsls::Types::Uint64 *)
 
static const char * bdlat_TypeName_Imp::name (const float *)
 
static const char * bdlat_TypeName_Imp::name (const double *)
 
static const char * bdlat_TypeName_Imp::name (const bdldfp::Decimal64 *)
 
static const char * bdlat_TypeName_Imp::name (const char *const *)
 
static const char * bdlat_TypeName_Imp::name (const signed char *const *)
 
static const char * bdlat_TypeName_Imp::name (const unsigned char *const *)
 
static const char * bdlat_TypeName_Imp::name (const bsl::string *)
 
static const char * bdlat_TypeName_Imp::name (const bdlt::Date *)
 
static const char * bdlat_TypeName_Imp::name (const bdlt::DateTz *)
 
static const char * bdlat_TypeName_Imp::name (const bdlt::Datetime *)
 
static const char * bdlat_TypeName_Imp::name (const bdlt::DatetimeTz *)
 
static const char * bdlat_TypeName_Imp::name (const bdlt::Time *)
 
static const char * bdlat_TypeName_Imp::name (const bdlt::TimeTz *)
 
template<class TYPE >
static const char * bdlat_TypeName_Imp::name (const bsl::vector< TYPE > *)
 
template<class TYPE >
static const char * bdlat_TypeName_Imp::xsdName (const TYPE *object, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const bool *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const char *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const unsigned short *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const int *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const unsigned int *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const long *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const unsigned long *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const bsls::Types::Int64 *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const bsls::Types::Uint64 *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const char *const *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const signed char *const *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const unsigned char *const *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const bdlt::Date *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const bdlt::DateTz *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const bdlt::Datetime *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const bdlt::DatetimeTz *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const bdlt::Time *, int format)
 
static const char * bdlat_TypeName_Imp::xsdName (const bdlt::TimeTz *, int format)
 
template<class TYPE >
static const char * bdlat_TypeName::className (const TYPE &object)
 
template<class TYPE >
static const char * bdlat_TypeName::name (const TYPE &object)
 
template<class TYPE >
static const char * bdlat_TypeName::xsdName (const TYPE &object, int format)
 

Detailed Description

Outline

Purpose

Provide string representations for data type names.

Classes

See also
http://www.w3.org/TR/xmlschema-2/#built-in-datatypes

Description

This component defines a structure bdlat_TypeName which provides a namespace for functions returning information about the object types. Functions in this namespace allow users to get access to three categories of information:

Class Name Information

The template function className returns the object class name from the metadata associated with given object type. Metadata is available for the C++ types that have one the following traits:

'bdlat_TypeTraitBasicChoice'
'bdlat_TypeTraitBasicSequence'
'bdlat_TypeTraitBasicCustomizedType'
'bdlat_TypeTraitBasicEnumeration'

If metadata is not available for the object type, the function className returns 0 unless the function bdlat_TypeName_className is overloaded by developer.

Overloable Class Name Functions For User Defined Classes

To provide the custom name for the given user-defined C++ class, the developer should overload the template function bdlat_TypeName_className for this type in the namespace where the type is defined.

WARNING! Do not extend bdlat_TypeName_Overloadable namespace.

Generic Type Name Information

The template functions name returns the generic type name for the given object. The generic type name is one of the following:

o predefined name for fundamental types
o class name from 'bdlat_TypeName_className', if such function returns a
non-null value
o name obtained from 'type_info' object provided by C++ runtime, if no
class name is available

XSD Type Name Information

The template functions xsdName returns the XML/XSD type name, based on the object type and formatting mode. The returned value is one of the following:

o predefined name for built-in XSD types
o class name from 'bdlat_TypeName_className', if such function returns
a non-null value
o the "anyType" string, if no class name is available

This component also defines the XSD names for the following C++ types and formatting modes:

C++ Type Formatting Mode XML Name
-------- --------------- --------
bool DEFAULT/DEC/TEXT boolean
char DEFAULT/DEC byte
char TEXT string
unsigned char DEFAULT/DEC unsignedByte
short DEFAULT/DEC short
short TEXT string
unsigned short DEFAULT/DEC unsignedShort
int DEFAULT/DEC int
unsigned int DEFAULT/DEC unsignedInt
bsls::Types::Int64 DEFAULT/DEC long
bsls::Types::Uint64 DEFAULT/DEC unsignedLong
float DEFAULT float
float DEC decimal
double DEFAULT double
double DEC decimal
bdldflp::Decimal64 DEFAULT Decimal64
bsl::string DEFAULT/TEXT string
bsl::string BASE64 base64Binary
bsl::string HEX hexBinary
bdlt::Date DEFAULT date
bdlt::DateTz DEFAULT date
bdlt::Datetime DEFAULT dateTime
bdlt::DatetimeTz DEFAULT dateTime
bdlt::Time DEFAULT time
bdlt::TimeTz DEFAULT time
bsl::vector<char> DEFAULT/BASE64 base64Binary
bsl::vector<char> HEX hexBinary
bsl::vector<char> TEXT string
bsl::vector<short> TEXT string
Definition bdlt_datetz.h:162
Definition bdlt_date.h:294
Definition bdlt_datetimetz.h:308
Definition bdlt_datetime.h:331
Definition bdlt_timetz.h:190
Definition bdlt_time.h:196
Definition bslstl_string.h:1281
Definition bslstl_vector.h:1025
unsigned long long Uint64
Definition bsls_types.h:137
long long Int64
Definition bsls_types.h:132

Usage

This section illustrates intended use of this component.

Example 1: Basic Usage

We begin by creating abbreviations for formatting modes and by declaring objects of a number of types:

int main() {
static const int DEFAULT = bdlat_FormattingMode::DEFAULT;
static const int DEC = bdlat_FormattingMode::DEC;
static const int HEX = bdlat_FormattingMode::HEX;
static const int BASE64 = bdlat_FormattingMode::BASE64;
static const int TEXT = bdlat_FormattingMode::TEXT;
short theShort;
unsigned theUint;
float theFloat;
const char *theCharPtr;
bsl::string theString;
bdlt::Date theDate;
bdlt::DatetimeTz theDatetime;
bsl::vector<char> theCharVector;
@ TEXT
Definition bdlat_formattingmode.h:130
@ BASE64
Definition bdlat_formattingmode.h:129
@ DEC
Definition bdlat_formattingmode.h:127
@ DEFAULT
Definition bdlat_formattingmode.h:126
@ HEX
Definition bdlat_formattingmode.h:128

None of these types are generated types with metadata, so className will return a null pointer for each of them:

assert(0 == bdlat_TypeName::className(theShort));
assert(0 == bdlat_TypeName::className(theUint));
assert(0 == bdlat_TypeName::className(theFloat));
assert(0 == bdlat_TypeName::className(theCharPtr));
assert(0 == bdlat_TypeName::className(theString));
assert(0 == bdlat_TypeName::className(theDate));
assert(0 == bdlat_TypeName::className(theDatetime));
assert(0 == bdlat_TypeName::className(theCharVector));
assert(0 == bdlat_TypeName::className(theStrVector));
static const char * className(const TYPE &object)
Definition bdlat_typename.h:1017

The name function will never return a null pointer. For each of the fundamental and vocabulary types, it returns the known type name. For vector types, it returns the appropriate "vector<X>" string:

assert(0 == bsl::strcmp("short", bdlat_TypeName::name(theShort)));
assert(0 == bsl::strcmp("unsigned int",
assert(0 == bsl::strcmp("float", bdlat_TypeName::name(theFloat)));
assert(0 == bsl::strcmp("const char*",
bdlat_TypeName::name(theCharPtr)));
assert(0 == bsl::strcmp("string", bdlat_TypeName::name(theString)));
assert(0 == bsl::strcmp("bdlt::Date", bdlat_TypeName::name(theDate)));
assert(0 == bsl::strcmp("bdlt::DatetimeTz",
bdlat_TypeName::name(theDatetime)));
assert(0 == bsl::strcmp("vector<char>",
bdlat_TypeName::name(theCharVector)));
assert(0 == bsl::strcmp("vector<string>",
bdlat_TypeName::name(theStrVector)));
static const char * name(const TYPE &object)
Definition bdlat_typename.h:1028

Each of the above types except vector<string> has one or more corresponding XSD types. The XSD type is affected by a formatting mode so that, for example, a vector<char> can be represented as a text string (formatting mode TEXT) or as a sequence of binary bytes (formatting mode HEX or BASE64).

assert(0 == bsl::strcmp("short",
bdlat_TypeName::xsdName(theShort, DEFAULT)));
assert(0 == bsl::strcmp("unsignedInt",
bdlat_TypeName::xsdName(theUint, DEFAULT)));
assert(0 == bsl::strcmp("float",
bdlat_TypeName::xsdName(theFloat, DEFAULT)));
assert(0 == bsl::strcmp("decimal",
bdlat_TypeName::xsdName(theFloat, DEC)));
assert(0 == bsl::strcmp("base64Binary",
bdlat_TypeName::xsdName(theCharVector, DEFAULT)));
assert(0 == bsl::strcmp("string",
bdlat_TypeName::xsdName(theCharVector, TEXT)));
static const char * xsdName(const TYPE &object, int format)
Definition bdlat_typename.h:1039

For types that have not corresponding XSD type, xsdName returns "anyType", regardless of formatting mode:

assert(0 == bsl::strcmp("anyType",
bdlat_TypeName::xsdName(theStrVector, DEFAULT)));
return 0;
}

If we create our own class:

namespace MyNamespace {
class MyClass {
//...
};

Then we can assign it a printable name by overloading the bdlat_TypeName_className function in the class's namespace:

const char *bdlat_TypeName_className(const MyClass&) {
return "MyClass";
}
} // Close MyNamespace

Note that bdlat_TypeName_className must return a string that is valid and does not change for remaining duration the program. The overloaded bdlat_TypeName_className function is automatically used for name and xsdName, as well as for className:

int main()
{
static const int DEFAULT = bdlat_FormattingMode::DEFAULT;
MyNamespace::MyClass myClassObj;
assert(0 == bsl::strcmp("MyClass",
assert(0 == bsl::strcmp("MyClass", bdlat_TypeName::name(myClassObj)));
assert(0 == bsl::strcmp("MyClass",
bdlat_TypeName::xsdName(myClassObj, DEFAULT)));
return 0;
}

Function Documentation

◆ className() [1/2]

template<class TYPE >
const char * bdlat_TypeName::className ( const TYPE &  object)
inlinestatic

Return a null-terminated string containing the exported name for the specified TYPE, or a 0 pointer if TYPE does not export a name. A type exports a name by overloading the function bdlat_TypeName_className(const TYPE&) in TYPE's namespace. The default implementation of bdlat_TypeName_className will automatically return the CLASS_NAME value for types that have the bdlat_TypeTraitBasicChoice, bdlat_TypeTraitBasicSequence, bdlat_TypeTraitBasicCustomizedType, or bdlat_TypeTraitBasicEnumeration trait (i.e., types generated using bas_codegen.pl).

◆ className() [2/2]

template<class TYPE >
const char * bdlat_TypeName_Imp::className ( const TYPE *  object)
inlinestatic

◆ name() [1/28]

const char * bdlat_TypeName_Imp::name ( const bdldfp::Decimal64 )
inlinestatic

◆ name() [2/28]

const char * bdlat_TypeName_Imp::name ( const bdlt::Date )
inlinestatic

◆ name() [3/28]

const char * bdlat_TypeName_Imp::name ( const bdlt::Datetime )
inlinestatic

◆ name() [4/28]

const char * bdlat_TypeName_Imp::name ( const bdlt::DatetimeTz )
inlinestatic

◆ name() [5/28]

const char * bdlat_TypeName_Imp::name ( const bdlt::DateTz )
inlinestatic

◆ name() [6/28]

const char * bdlat_TypeName_Imp::name ( const bdlt::Time )
inlinestatic

◆ name() [7/28]

const char * bdlat_TypeName_Imp::name ( const bdlt::TimeTz )
inlinestatic

◆ name() [8/28]

const char * bdlat_TypeName_Imp::name ( const bool *  )
inlinestatic

◆ name() [9/28]

const char * bdlat_TypeName_Imp::name ( const bsl::string )
inlinestatic

◆ name() [10/28]

template<class TYPE >
const char * bdlat_TypeName_Imp::name ( const bsl::vector< TYPE > *  )
static

Specialization for vectors. Return the null-terminated string constructed by replacing the "X" in the string "vector<X>" with the result of calling name on an object of the specified TYPE. If the constructed string exceeds 100 characters, then truncate to 100 characters. Note that TYPE may itself be a vector, leading to a recursive call to this function.

◆ name() [11/28]

const char * bdlat_TypeName_Imp::name ( const bsls::Types::Int64 )
inlinestatic

◆ name() [12/28]

const char * bdlat_TypeName_Imp::name ( const bsls::Types::Uint64 )
inlinestatic

◆ name() [13/28]

const char * bdlat_TypeName_Imp::name ( const char *  )
inlinestatic

◆ name() [14/28]

const char * bdlat_TypeName_Imp::name ( const char *const *  )
inlinestatic

◆ name() [15/28]

const char * bdlat_TypeName_Imp::name ( const double *  )
inlinestatic

◆ name() [16/28]

const char * bdlat_TypeName_Imp::name ( const float *  )
inlinestatic

◆ name() [17/28]

const char * bdlat_TypeName_Imp::name ( const int *  )
inlinestatic

◆ name() [18/28]

const char * bdlat_TypeName_Imp::name ( const long *  )
inlinestatic

◆ name() [19/28]

const char * bdlat_TypeName_Imp::name ( const short *  )
inlinestatic

◆ name() [20/28]

const char * bdlat_TypeName_Imp::name ( const signed char *  )
inlinestatic

◆ name() [21/28]

const char * bdlat_TypeName_Imp::name ( const signed char *const *  )
inlinestatic

◆ name() [22/28]

template<class TYPE >
const char * bdlat_TypeName::name ( const TYPE &  object)
inlinestatic

Return a null-terminated string containing the name of the specified TYPE. If TYPE is a fundamental type, string, date, time, or datetime, then return a canonical representation of the type's name. Otherwise, if className applied to the specified object returns a non-null value, then return that value. Otherwise, return typeid(TYPE).name(). Note that the returned name refers to the static TYPE, not to the dynamic type of object.

◆ name() [23/28]

template<class TYPE >
const char * bdlat_TypeName_Imp::name ( const TYPE *  type_p)
inlinestatic

◆ name() [24/28]

const char * bdlat_TypeName_Imp::name ( const unsigned char *  )
inlinestatic

◆ name() [25/28]

const char * bdlat_TypeName_Imp::name ( const unsigned char *const *  )
inlinestatic

◆ name() [26/28]

const char * bdlat_TypeName_Imp::name ( const unsigned int *  )
inlinestatic

◆ name() [27/28]

const char * bdlat_TypeName_Imp::name ( const unsigned long *  )
inlinestatic

◆ name() [28/28]

const char * bdlat_TypeName_Imp::name ( const unsigned short *  )
inlinestatic

◆ xsdName() [1/20]

const char * bdlat_TypeName_Imp::xsdName ( const bdlt::Date ,
int  format 
)
inlinestatic

◆ xsdName() [2/20]

const char * bdlat_TypeName_Imp::xsdName ( const bdlt::Datetime ,
int  format 
)
inlinestatic

◆ xsdName() [3/20]

const char * bdlat_TypeName_Imp::xsdName ( const bdlt::DatetimeTz ,
int  format 
)
inlinestatic

◆ xsdName() [4/20]

const char * bdlat_TypeName_Imp::xsdName ( const bdlt::DateTz ,
int  format 
)
inlinestatic

◆ xsdName() [5/20]

const char * bdlat_TypeName_Imp::xsdName ( const bdlt::Time ,
int  format 
)
inlinestatic

◆ xsdName() [6/20]

const char * bdlat_TypeName_Imp::xsdName ( const bdlt::TimeTz ,
int  format 
)
inlinestatic

◆ xsdName() [7/20]

const char * bdlat_TypeName_Imp::xsdName ( const bool *  ,
int  format 
)
inlinestatic

Overloads for fundamental types and some predefined types using the specified format.

◆ xsdName() [8/20]

const char * bdlat_TypeName_Imp::xsdName ( const bsls::Types::Int64 ,
int  format 
)
inlinestatic

◆ xsdName() [9/20]

const char * bdlat_TypeName_Imp::xsdName ( const bsls::Types::Uint64 ,
int  format 
)
inlinestatic

◆ xsdName() [10/20]

const char * bdlat_TypeName_Imp::xsdName ( const char *  ,
int  format 
)
inlinestatic

◆ xsdName() [11/20]

const char * bdlat_TypeName_Imp::xsdName ( const char *const *  ,
int  format 
)
inlinestatic

◆ xsdName() [12/20]

const char * bdlat_TypeName_Imp::xsdName ( const int *  ,
int  format 
)
inlinestatic

◆ xsdName() [13/20]

const char * bdlat_TypeName_Imp::xsdName ( const long *  ,
int  format 
)
inlinestatic

◆ xsdName() [14/20]

const char * bdlat_TypeName_Imp::xsdName ( const signed char *const *  ,
int  format 
)
inlinestatic

◆ xsdName() [15/20]

template<class TYPE >
const char * bdlat_TypeName::xsdName ( const TYPE &  object,
int  format 
)
inlinestatic

Return a null-terminated text string containing the name of the specified TYPE with the specified format as it would appear in an XML Schema (XSD) element declaration. The format is interpreted as the bit-wise OR of one or more of the values defined in the bdlat_formattingmode component. Formatting mode bits outside of bdlat_FormattingMode::TYPE_MASK are ignored. If the specified object corresponds to one of the XSD built-in types, then return the XSD type's name. Otherwise, if className(object) returns a non-null value, then return that value. Otherwise, return "anyType". The behavior is undefined unless the format is valid for the specified TYPE.

◆ xsdName() [16/20]

template<class TYPE >
const char * bdlat_TypeName_Imp::xsdName ( const TYPE *  object,
int  format 
)
inlinestatic

Generic implementation for non-fundamental and not predefined types using the specified object and format.

◆ xsdName() [17/20]

const char * bdlat_TypeName_Imp::xsdName ( const unsigned char *const *  ,
int  format 
)
inlinestatic

◆ xsdName() [18/20]

const char * bdlat_TypeName_Imp::xsdName ( const unsigned int *  ,
int  format 
)
inlinestatic

◆ xsdName() [19/20]

const char * bdlat_TypeName_Imp::xsdName ( const unsigned long *  ,
int  format 
)
inlinestatic

◆ xsdName() [20/20]

const char * bdlat_TypeName_Imp::xsdName ( const unsigned short *  ,
int  format 
)
inlinestatic