|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, bool value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, int value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, char value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, short value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, bsls::Types::Int64 value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, unsigned int value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, unsigned char value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, unsigned short value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, bsls::Types::Uint64 value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, float value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, double value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, const bdlt::Date &value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, const bdlt::DateTz &value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, const bdlt::Datetime &value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, const bdlt::DatetimeTz &value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, const bdlt::Time &value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, const bdlt::TimeTz &value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, const bsl::string &value) |
|
template<class TYPE > |
static int | bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType (TYPE *object, const bsl::vector< char > &value) |
|
template<class TYPE > |
static const bool & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bool *) |
|
template<class TYPE > |
static const int & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, int *) |
|
template<class TYPE > |
static const char & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, char *) |
|
template<class TYPE > |
static const short & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, short *) |
|
template<class TYPE > |
static const bsls::Types::Int64 & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bsls::Types::Int64 *) |
|
template<class TYPE > |
static const unsigned int & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, unsigned int *) |
|
template<class TYPE > |
static const unsigned char & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, unsigned char *) |
|
template<class TYPE > |
static const unsigned short & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, unsigned short *) |
|
template<class TYPE > |
static const bsls::Types::Uint64 & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bsls::Types::Uint64 *) |
|
template<class TYPE > |
static const float & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, float *) |
|
template<class TYPE > |
static const double & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, double *) |
|
template<class TYPE > |
static const bdlt::Date & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bdlt::Date *) |
|
template<class TYPE > |
static const bdlt::DateTz & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bdlt::DateTz *) |
|
template<class TYPE > |
static const bdlt::Datetime & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bdlt::Datetime *) |
|
template<class TYPE > |
static const bdlt::DatetimeTz & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bdlt::DatetimeTz *) |
|
template<class TYPE > |
static const bdlt::Time & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bdlt::Time *) |
|
template<class TYPE > |
static const bdlt::TimeTz & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bdlt::TimeTz *) |
|
template<class TYPE > |
static const bsl::string & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bsl::string *) |
|
template<class TYPE > |
static const bsl::vector< char > & | bdlat_CustomizedTypeFunctions_Imp::convertToBaseType (const TYPE &object, bsl::vector< char > *) |
|
Outline
Purpose
Provide a namespace defining customized type functions.
Classes
- See also
Description
The bdlat_CustomizedTypeFunctions
namespace
provided in this component defines parameterized functions that expose "customized type" behavior for "customized type" types. See the package-level documentation for a full description of "customized type" types. The functions in this namespace allow users to:
o convert from base type to customized type ('convertFromBaseType').
o convert from customized type to base type ('convertToBaseType').
Also, the meta-function IsCustomizedType
contains a compile-time constant value
that is non-zero if the parameterized TYPE
exposes "customized type" behavior through the bdlat_CustomizedTypeFunctions
namespace
.
The BaseType
meta-function contains a typedef Type
that specifies the base type of the value for the parameterized "customized type" type.
This component specializes all of these functions for types that have the bdlat_TypeTraitBasicCustomizedType
trait.
Types that do not have the bdlat_TypeTraitBasicCustomizedType
trait can be plugged into the bdlat
framework. This is done by overloading the bdlat_choice*
functions inside the namespace of the plugged in type. For example, suppose there is a type called mine::Cusip
(defined in the example below). In order to plug this type into the bdlat
framework as a "CustomizedType", the following functions must be declared and implemented in the mine
namespace:
template <typename TYPE, typename BASE_TYPE>
int bdlat_customizedTypeConvertFromBaseType(TYPE *object,
const BASE_TYPE& value);
template <typename TYPE>
const typename BaseType<TYPE>::Type&
bdlat_customizedTypeConvertToBaseType(const TYPE& object);
Also, the IsCustomizedType
meta-function must be specialized for the mine::Cusip
type in the bdlat_CustomizedTypeFunctions
namespace.
Usage
This section illustrates intended use of this component.
Example 1: Basic Usage
Suppose we have a customized type called Cusip
, holding an object of type bsl::string
with a restriction that the length of the string cannot be longer than nine characters. We can obtain the value of the string using the following code:
Cusip myCusip = "281C82UE";
myCusip);
assert("281C82UE" == base);
Definition bslstl_string.h:1281
const BaseType< TYPE >::Type & convertToBaseType(const TYPE &object)
Attempting to assign a string longer than nine characters will not succeed:
&myCusip,
invalidCusip);
assert(0 != retCode);
int convertFromBaseType(TYPE *object, const BASE_TYPE &value)
For the purpose of this example, the class definition is as follows:
#include <sstream>
#include <string>
namespace BloombergLP {
namespace mine {
class Cusip {
private:
friend bool operator==(const Cusip& lhs, const Cusip& rhs);
friend bool operator!=(const Cusip& lhs, const Cusip& rhs);
public:
~Cusip();
Cusip& operator=(const Cusip& rhs);
void reset();
bsl::ostream& print(bsl::ostream& stream,
int level = 0,
int spacesPerLevel = 4) const;
};
inline
bool operator==(const Cusip& lhs, const Cusip& rhs);
inline
bool operator!=(const Cusip& lhs, const Cusip& rhs);
inline
bsl::ostream&
operator<<(bsl::ostream& stream,
const Cusip& rhs);
Definition bslma_allocator.h:457
bsl::ostream & operator<<(bsl::ostream &stream, const bdlat_AttributeInfo &attributeInfo)
The class implementation is straightforward and is deferred to the end of this usage example.
We can now make Cusip
expose "customized type" behavior by implementing bdlat_CustomizedTypeFunctions
for Cusip
. The first method (the longer one) overloads all the bdlat_customizedType*
functions. In the second method, we show how to bypass this by simply declaring the class mine::Cusip
to have the bdlat_TypeTraitBasicCustomizedType
trait.
Longer Usage
First, we should forward declare all the functions that we will implement inside the mine
namespace:
template <typename TYPE, typename BASE_TYPE>
int bdlat_customizedTypeConvertFromBaseType(TYPE *object,
const BASE_TYPE& value);
template <typename TYPE>
const typename BaseType<TYPE>::Type&
bdlat_customizedTypeConvertToBaseType(const TYPE& object);
}
Next, we provide the definitions for each of these functions:
template <typename TYPE, typename BASE_TYPE>
int mine::bdlat_customizedTypeConvertFromBaseType(TYPE *object,
const BASE_TYPE& value);
{
return object->fromString(value);
}
template <typename TYPE>
const typename BaseType<TYPE>::Type&
mine::bdlat_customizedTypeConvertToBaseType(const TYPE& object);
{
return object.toString();
}
Finally, we need to specialize the IsCustomizedType
meta-function in the bdlat_CustomizedTypeFunctions
namespace for the mine::Cusip
type. This makes the bdlat
infrastructure recognize mine::Cusip
as a customized type abstraction:
template <>
};
}
}
Definition bdlat_customizedtypefunctions.h:511
The bdlat
infrastructure (and any component that uses this infrastructure) will now recognize mine::Cusip
as a "customized" type.
Shorter Usage
We can bypass all the code from the longer usage example by simply declaring mine::Cusip
to have the bdlat_TypeTraitBasicCustomizedType
trait as follows:
#define BDLAT_DECL_CUSTOMIZEDTYPE_WITH_ALLOCATOR_TRAITS(ClassName)
Definition bdlat_typetraits.h:318
Again, the bdlat
infrastructure (and any component that uses this infrastructure) will now recognize mine::Cusip
as a "customized" type.
For example, suppose we have the following XML data:
<?xml version='1.0' encoding='UTF-8' ?>
<Cusip>
<value>"281C82UE"</value>
</Cusip>
Using the balxml_decoder component, we can load this XML data into a mine::Cusip
object:
void decodeMyCustomizedTypeFromXML(bsl::istream& inputData)
{
using namespace BloombergLP;
Cusip object;
int result = decoder.decode(inputData, &object);
assert(0 == result);
assert("281C82UE" == object.toString());
}
Definition balxml_decoderoptions.h:72
Definition balxml_decoder.h:402
Definition balxml_errorinfo.h:353
Definition balxml_minireader.h:343
Note that the bdlat
framework can be used for functionality other than encoding/decoding into XML. When mine::Cusip
is plugged into the framework, then it will be automatically usable within the framework. For example, the following snippets of code will convert a string from a stream and load it into a Cusip
object:
template <typename TYPE>
int readCusip(bsl::istream& stream, TYPE *object)
{
stream >> value;
return bdlat_CustomizedType::convertFromBaseType(cusip, value);
}
Now we have a generic function that takes an input stream and a Cusip
object, and inputs its value. We can use this generic function as follows:
void usageExample()
{
using namespace BloombergLP;
mine::Cusip object;
ss << "281C82UE\n1234567890\n";
assert(0 == readCusip(ss, &object));
assert("281C82UE" == object.toString());
assert(0 != readCusip(ss, &object));
}
Definition bslstl_stringstream.h:184
This concludes the usage example.
For completeness, we finish by providing the straightforward details of the implementation of the class Cusip
:
inline
: d_value(basicAllocator)
{
}
inline
: d_value(original.d_value, basicAllocator)
{
}
inline
: d_value(value, basicAllocator)
{
}
inline
Cusip::~Cusip()
{
}
inline
Cusip& Cusip::operator=(const Cusip& rhs)
{
d_value = rhs.d_value;
return *this;
}
inline
void Cusip::reset()
{
d_value.erase();
}
inline
{
enum { SUCCESS = 0, FAILURE = -1 };
globalFlag = 1;
return FAILURE;
}
d_value = value;
return SUCCESS;
}
inline
bsl::ostream& Cusip::print(bsl::ostream& stream,
int level,
int spacesPerLevel) const
{
d_value,
level,
spacesPerLevel);
}
inline
{
globalFlag = 2;
return d_value;
}
inline
bool geom::operator==(const geom::Cusip& lhs,
const geom::Cusip& rhs)
{
return lhs.d_value == rhs.d_value;
}
inline
bool geom::operator!=(const geom::Cusip& lhs,
const geom::Cusip& rhs)
{
return lhs.d_value != rhs.d_value;
}
inline
bsl::ostream& geom::operator<<(bsl::ostream& stream,
const geom::Cusip& rhs)
{
return rhs.print(stream, 0, -1);
}
size_type size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6592
bsl::ostream & print(bsl::ostream &stream, const TYPE &object, int level=0, int spacesPerLevel=4)
Definition bdlb_printmethods.h:719
◆ convertFromBaseType() [1/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
bool |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [2/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
bsls::Types::Int64 |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [3/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
bsls::Types::Uint64 |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [4/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
char |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [5/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
const bdlt::Date & |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [6/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
const bdlt::Datetime & |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [7/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
const bdlt::DatetimeTz & |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [8/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
const bdlt::DateTz & |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [9/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
const bdlt::Time & |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [10/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
const bdlt::TimeTz & |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [11/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
const bsl::string & |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [12/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
const bsl::vector< char > & |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [13/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
double |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [14/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
float |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [15/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
int |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [16/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
short |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [17/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
unsigned char |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [18/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
unsigned int |
value |
|
) |
| |
|
inlinestatic |
◆ convertFromBaseType() [19/19]
template<class TYPE >
int bdlat_CustomizedTypeFunctions_Imp::convertFromBaseType |
( |
TYPE * |
object, |
|
|
unsigned short |
value |
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [1/19]
template<class TYPE >
const bdlt::Date & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
bdlt::Date * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [2/19]
◆ convertToBaseType() [3/19]
◆ convertToBaseType() [4/19]
◆ convertToBaseType() [5/19]
template<class TYPE >
const bdlt::Time & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
bdlt::Time * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [6/19]
◆ convertToBaseType() [7/19]
template<class TYPE >
const bool & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
bool * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [8/19]
template<class TYPE >
const bsl::string & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
bsl::string * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [9/19]
template<class TYPE >
const bsl::vector< char > & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
bsl::vector< char > * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [10/19]
◆ convertToBaseType() [11/19]
◆ convertToBaseType() [12/19]
template<class TYPE >
const char & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
char * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [13/19]
template<class TYPE >
const double & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
double * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [14/19]
template<class TYPE >
const float & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
float * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [15/19]
template<class TYPE >
const int & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
int * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [16/19]
template<class TYPE >
const short & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
short * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [17/19]
template<class TYPE >
const unsigned char & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
unsigned char * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [18/19]
template<class TYPE >
const unsigned int & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
unsigned int * |
|
|
) |
| |
|
inlinestatic |
◆ convertToBaseType() [19/19]
template<class TYPE >
const unsigned short & bdlat_CustomizedTypeFunctions_Imp::convertToBaseType |
( |
const TYPE & |
object, |
|
|
unsigned short * |
|
|
) |
| |
|
inlinestatic |