xb::type fixed for std::basic_strings
Status: Beta
Brought to you by:
tringi
I have added following two new specialization for xb::type template:
template <> struct xb::type <std::basic_string <char> >
template <> struct xb::type <std::basic_string <wchar_t> >
This enables better interaction with std::string and std::wstring classes. Without these fixes, it is often possible to initialize xb::value without correctly setting the xb::value::type to 'a' or 'w' (or 'W').
Updated xb_types.hpp and xb_types.cpp files
Logged In: YES
user_id=1590239
Originator: YES
Here is what the new codes are:
-- xb_types.hpp --
#ifndef XB_TYPES_HPP
#define XB_TYPES_HPP
#include "xb_size_type.hpp"
#include "xb_element.hpp"
#include <string>
namespace xb {
class element;
template <typename T>
struct type {
static const element info;
};
template <> struct type <bool>
{ static const element info; };
template <> struct type <char>
{ static const element info; };
template <> struct type <wchar_t>
{ static const element info; };
template <> struct type <signed char>
{ static const element info; };
template <> struct type <signed short>
{ static const element info; };
template <> struct type <signed int>
{ static const element info; };
template <> struct type <signed long>
{ static const element info; };
#ifdef XB_LONG_LONG_TYPE
template <> struct type <signed XB_LONG_LONG_TYPE>
{ static const element info; };
#endif
template <> struct type <unsigned char>
{ static const element info; };
template <> struct type <unsigned short>
{ static const element info; };
template <> struct type <unsigned int>
{ static const element info; };
template <> struct type <unsigned long>
{ static const element info; };
#ifdef XB_LONG_LONG_TYPE
template <> struct type <unsigned XB_LONG_LONG_TYPE>
{ static const element info; };
#endif
template <> struct type <float>
{ static const element info; };
template <> struct type <double>
{ static const element info; };
template <> struct type <long double>
{ static const element info; };
template <unsigned int N>
struct type <char [N]>
{ static const element & info; };
template <unsigned int N>
struct type <wchar_t [N]>
{ static const element & info; };
template <> struct type <std::basic_string <char> >
{ static const element info; };
template <> struct type <std::basic_string <wchar_t> >
{ static const element info; };
// namespace {
template <unsigned int N>
const element & type <char [N]> ::info = xb::type <char> ::info;
template <unsigned int N>
const element & type <wchar_t [N]> ::info = xb::type <wchar_t> ::info;
template <typename T>
const element type <T> ::info;
// };
};
#endif
-- end of xb_types.hpp --
-- xb_types.cpp --
#include "xb_types.hpp"
#include "xb_element.hpp"
const xb::element xb::type <bool> ::info ('b');
const xb::element xb::type <char> ::info ('a');
const xb::element xb::type <wchar_t> ::info ((sizeof (wchar_t) == 4) ? 'W' :
(sizeof (wchar_t) == 2) ? 'w' : '\0');
const xb::element xb::type <std::basic_string <char> > ::info ('a');
const xb::element xb::type <std::basic_string <wchar_t> >
::info ((sizeof (wchar_t) == 4) ? 'W' :
(sizeof (wchar_t) == 2) ? 'w' : '\0');
const xb::element xb::type <signed char> ::info ('i');
const xb::element xb::type <signed short> ::info ('i');
const xb::element xb::type <signed int> ::info ('i');
const xb::element xb::type <signed long> ::info ('i');
#ifdef XB_LONG_LONG_TYPE
const xb::element xb::type <signed XB_LONG_LONG_TYPE> ::info ('i');
#endif
const xb::element xb::type <unsigned char> ::info ('u');
const xb::element xb::type <unsigned short> ::info ('u');
const xb::element xb::type <unsigned int> ::info ('u');
const xb::element xb::type <unsigned long> ::info ('u');
#ifdef XB_LONG_LONG_TYPE
const xb::element xb::type <unsigned XB_LONG_LONG_TYPE> ::info ('u');
#endif
const xb::element xb::type <float> ::info ('f');
const xb::element xb::type <double> ::info ('f');
const xb::element xb::type <long double> ::info ('f');
-- end of xb_types.cpp --
Logged In: YES
user_id=1590239
Originator: YES
The new files are available to download, see below.
These will also be included in next release.