8#ifndef HPP_ALIB_CHARACTERS_TRAITS 
    9#define HPP_ALIB_CHARACTERS_TRAITS 1 
   17#include "alib/lang/integers.hpp" 
   20namespace alib {  
namespace characters {
 
   37#if defined(ALIB_CHARACTERS_NATIVE_WCHAR) 
   38#   error "Preprocessor symbol ALIB_CHARACTERS_NATIVE_WCHAR must not be passed to the compiler. It is deduced in ALib headers." 
   71    #define A_NCHAR(STR)  STR 
   74    #if ALIB_CHARACTERS_SIZEOF_WCHAR == ALIB_SIZEOF_WCHAR_T 
   76    #   define ALIB_CHARACTERS_NATIVE_WCHAR 1 
   78    #   if ALIB_CHARACTERS_SIZEOF_WCHAR == 2 
   79            using wchar     =  wchar_t;
 
   80            using xchar     =  char32_t;
 
   81            #define A_WCHAR(STR)  L ## STR 
   82            #define A_XCHAR(STR)  U ## STR 
   83            #define A_SCHAR(STR)  U ## STR 
   85            using wchar     =  wchar_t;
 
   86            using xchar     =  char16_t;
 
   87            #define A_WCHAR(STR)  L ## STR 
   88            #define A_XCHAR(STR)  u ## STR 
   89            #define A_SCHAR(STR)  u ## STR 
   94    #   define ALIB_CHARACTERS_NATIVE_WCHAR 0 
   96    #   if ALIB_CHARACTERS_SIZEOF_WCHAR == 2 
   97            using wchar     =  char16_t;
 
   98            using xchar     =  wchar_t;
 
   99            #define A_WCHAR(STR)  u ## STR 
  100            #define A_XCHAR(STR)  L ## STR 
  101            #define A_SCHAR(STR)  L ## STR 
  103            using wchar     =  char32_t;
 
  104            using xchar     =  wchar_t;
 
  105            #define A_WCHAR(STR)  U ## STR 
  106            #define A_XCHAR(STR)  L ## STR 
  107            #define A_SCHAR(STR)  L ## STR 
  156#define ALIB_CHAR_TYPE_ID_CHARACTER 
  157#define ALIB_CHAR_TYPE_ID_COMPLEMENT 
  158#define ALIB_CHAR_TYPE_ID_STRANGE 
  161#elif !ALIB_CHARACTERS_WIDE 
  166    #define A_CHAR(STR)     STR 
  167    #define A_CCHAR(STR)    A_WCHAR(STR) 
  168    #define ALIB_CHAR_TYPE_ID_CHARACTER   1 
  169    #define ALIB_CHAR_TYPE_ID_COMPLEMENT  2 
  170    #define ALIB_CHAR_TYPE_ID_STRANGE     3 
  176    #define A_CHAR(STR)     A_WCHAR(STR) 
  177    #define A_CCHAR(STR)    STR 
  179    #define ALIB_CHAR_TYPE_ID_CHARACTER   2 
  180    #define ALIB_CHAR_TYPE_ID_COMPLEMENT  1 
  181    #define ALIB_CHAR_TYPE_ID_STRANGE     3 
  184#define ALIB_CHAR_TYPE_ID_N   1 
  185#define ALIB_CHAR_TYPE_ID_W   2 
  186#define ALIB_CHAR_TYPE_ID_X   3 
  252template<
typename TString, 
typename TChar, 
typename TEnableIf= 
void>
 
  281    const TChar* 
Buffer( 
const TString& src );
 
 
  334template<
typename TString, 
typename TChar, 
typename TEnableIf= 
void>
 
  350    const TChar* 
Buffer( 
const TString& src );
 
 
  393template<
typename TString, 
typename TEnableIf= 
void>
 
  415template<
typename TString, 
typename EnableIf= 
void>
 
  424template<
typename T> 
struct TT_CharArrayType  <T, typename std::enable_if<characters::T_CharArray  <T,nchar>::Access != AccessType::NONE>::type>: std::true_type { 
using TChar= 
nchar; };
 
  425template<
typename T> 
struct TT_CharArrayType  <T, typename std::enable_if<characters::T_CharArray  <T,wchar>::Access != AccessType::NONE>::type>: std::true_type { 
using TChar= 
wchar; };
 
  426template<
typename T> 
struct TT_CharArrayType  <T, typename std::enable_if<characters::T_CharArray  <T,xchar>::Access != AccessType::NONE>::type>: std::true_type { 
using TChar= 
xchar; };
 
  427template<
typename T> 
struct TT_ZTCharArrayType<T, typename std::enable_if<characters::T_ZTCharArray<T,nchar>::Access != AccessType::NONE>::type>: std::true_type { 
using TChar= 
nchar; };
 
  428template<
typename T> 
struct TT_ZTCharArrayType<T, typename std::enable_if<characters::T_ZTCharArray<T,wchar>::Access != AccessType::NONE>::type>: std::true_type { 
using TChar= 
wchar; };
 
  429template<
typename T> 
struct TT_ZTCharArrayType<T, typename std::enable_if<characters::T_ZTCharArray<T,xchar>::Access != AccessType::NONE>::type>: std::true_type { 
using TChar= 
xchar; };
 
  439#define ALIB_CHARACTER_ARRAY_internal( C_ZTC, TString, TChar, Const, pAccess, pConstruction)       \ 
  440template<>  struct     T_ ## C_ZTC ## harArray<TString, TChar>                                     \ 
  442    static constexpr    AccessType               Access=    AccessType::       pAccess;            \ 
  443    static constexpr    ConstructionType   Construction=    ConstructionType:: pConstruction;      \ 
  445    static inline       const TChar*          Buffer(  TString Const &  src );                     \ 
  446    static inline       integer               Length(  TString Const &  src );                     \ 
  448    static inline       TString               Construct(  const TChar* array, integer length );    \ 
  454#define ALIB_CHARACTER_ARRAY(            TString, TChar,        Access     , Construction )        \ 
  455ALIB_CHARACTER_ARRAY_internal(     C ,   TString, TChar, const, Access     , Construction ) 
 
  457#define ALIB_CHARACTER_ARRAY_MUTABLE(    TString, TChar,                     Construction )        \ 
  458ALIB_CHARACTER_ARRAY_internal(     C ,   TString, TChar,      , MutableOnly, Construction ) 
 
  460#define ALIB_CHARACTER_ZT_ARRAY(         TString, TChar,        Access     , Construction )        \ 
  461ALIB_CHARACTER_ARRAY_internal(    ZTC,   TString, TChar, const, Access     , Construction ) 
 
  463#define ALIB_CHARACTER_ZT_ARRAY_MUTABLE( TString, TChar,                     Construction )        \ 
  464ALIB_CHARACTER_ARRAY_internal(    ZTC,   TString, TChar,      , MutableOnly, Construction ) 
 
  468#define ALIB_CHARACTER_ARRAY_IMPL_BUFFER(           TString, TChar, ... )                         \ 
  469const TChar*  T_CharArray<TString,TChar>::Buffer(TString const&  src ) { __VA_ARGS__ } 
 
  471#define ALIB_CHARACTER_ARRAY_IMPL_LENGTH(           TString, TChar, ... )                         \ 
  472integer       T_CharArray<TString,TChar>::Length(TString const&  src ) { __VA_ARGS__ } 
 
  474#define ALIB_CHARACTER_ARRAY_IMPL_BUFFER_MUTABLE(   TString, TChar, ... )                          \ 
  475const TChar*  T_CharArray<TString,TChar>::Buffer(TString      &  src ) { __VA_ARGS__ } 
 
  477#define ALIB_CHARACTER_ARRAY_IMPL_LENGTH_MUTABLE(   TString, TChar, ... )                          \ 
  478integer       T_CharArray<TString,TChar>::Length(TString      &  src ) { __VA_ARGS__ } 
 
  480#define ALIB_CHARACTER_ARRAY_IMPL_CONSTRUCT(        TString, TChar, ... )                          \ 
  481    TString  T_CharArray  <TString,TChar>::Construct( const TChar* array, integer length ) { __VA_ARGS__ } 
 
  483#define ALIB_CHARACTER_ZT_ARRAY_IMPL_BUFFER(        TString, TChar, ... )                          \ 
  484const TChar* T_ZTCharArray<TString,TChar>::Buffer( TString const&  src ) { __VA_ARGS__ } 
 
  486#define ALIB_CHARACTER_ZT_ARRAY_IMPL_LENGTH(        TString, TChar, ... )                          \ 
  487integer      T_ZTCharArray<TString,TChar>::Length( TString const&  src ) { __VA_ARGS__ } 
 
  489#define ALIB_CHARACTER_ZT_ARRAY_IMPL_BUFFER_MUTABLE(TString, TChar, ... )                          \ 
  490const TChar* T_ZTCharArray<TString,TChar>::Buffer( TString      &  src ) { __VA_ARGS__ } 
 
  492#define ALIB_CHARACTER_ZT_ARRAY_IMPL_LENGTH_MUTABLE(TString, TChar, ... )                          \ 
  493integer      T_ZTCharArray<TString,TChar>::Length( TString      &  src ) { __VA_ARGS__ } 
 
  495#define ALIB_CHARACTER_ZT_ARRAY_IMPL_CONSTRUCT(     TString, TChar, ... )                          \ 
  496    TString  T_ZTCharArray<TString,TChar>::Construct( const TChar* array, integer length ) { __VA_ARGS__ } 
 
  505template<
size_t TCapacity, 
typename TChar>
 
  506struct T_CharArray<TChar[TCapacity], TChar>
 
  509    static constexpr const TChar*   
Buffer( TChar 
const (&src) [TCapacity] ) { 
return src; }
 
  510    static constexpr integer        Length( TChar 
const (&   ) [TCapacity] ) { 
return TCapacity -1; }
 
  514template<
size_t TCapacity, 
typename TChar>
 
  515struct T_ZTCharArray<TChar[TCapacity], TChar>
 
  518    static constexpr const TChar*   
Buffer( TChar 
const (&src) [TCapacity] ) { 
return src; }
 
  519    static constexpr integer        Length( TChar 
const (&   ) [TCapacity] ) { 
return TCapacity -1; }
 
  523template<
typename TChar> 
struct T_CharArray<TChar const*, TChar>
 
  527    static constexpr const TChar*      Buffer(
const TChar* 
const & src       ) { 
return src; }
 
  528    static constexpr integer           Length(
const TChar* 
const & src       ) { 
return src ? 
static_cast<integer>( std::char_traits<TChar>::length(src) ) : 0; }
 
  529    static constexpr const TChar*      Construct(
const TChar* array, 
integer ) { 
return array; }
 
  532template<
typename TChar> 
struct T_ZTCharArray<TChar const*, TChar>
 
  536    static constexpr const TChar*      Buffer(
const TChar* 
const & src       ) { 
return src; }
 
  537    static constexpr integer           Length(
const TChar* 
const & src       ) { 
return src ? 
static_cast<integer>( std::char_traits<TChar>::length(src) ) : 0; }
 
  538    static constexpr const TChar*      Construct(
const TChar* array, 
integer ) { 
return array; }
 
  542template<
typename TChar> 
struct T_CharArray<TChar*, TChar>
 
  546    static constexpr const TChar*      Buffer(      TChar* 
const & src       ) { 
return src;  }
 
  547    static constexpr integer           Length(      TChar* 
const & src       ) { 
return src ? 
static_cast<integer>( std::char_traits<TChar>::length(src) ) : 0; }
 
  548    static constexpr       TChar*      Construct(
const TChar* array, 
integer ) { 
return const_cast<TChar*
>( array ); }
 
  552template<
typename TChar> 
struct T_ZTCharArray<TChar*, TChar>
 
  556    static constexpr const TChar*      Buffer(     TChar* 
const & src        ) { 
return src;  }
 
  557    static constexpr integer           Length(     TChar* 
const & src        ) { 
return src ? 
static_cast<integer>( std::char_traits<TChar>::length(src) ) : 0; }
 
  558    static constexpr       TChar*      Construct(
const TChar* array, 
integer ) { 
return const_cast<TChar*
>( array ); }
 
  586#define ATMP_CHAR_COMPLEMENT( TChar )    typename TT_ComplementChar<TChar>::type 
  614template<>   
struct TT_CharOfSize<sizeof(
wchar)> : 
public std::true_type     { 
using type= 
wchar; };
 
  615template<>   
struct TT_CharOfSize<sizeof(
xchar)> : 
public std::true_type     { 
using type= 
xchar; };
 
  627template<
typename TChar> 
struct TT_IsChar : 
public std::false_type {};
 
  631template<>   
struct TT_IsChar<
wchar> : 
public std::true_type {};
 
  632template<>   
struct TT_IsChar<
xchar> : 
public std::true_type {};
 
#define ALIB_ASSERT_MODULE(modulename)
integer Length(const TChar *cstring)
@ ExplicitOnly
Allows explicit construction of objects from character array data.
@ Implicit
Allows implicit (and explicit) construction of objects from character array data.
PLATFORM_SPECIFIC strangeChar
PLATFORM_SPECIFIC complementChar
PLATFORM_SPECIFIC character
@ ExplicitOnly
Allows explicit access of the character array data from mutable or constant objects.
@ MutableOnly
Allows explicit access of the character array data from mutable objects.
characters::complementChar complementChar
Type alias in namespace alib.
characters::wchar wchar
Type alias in namespace alib.
characters::xchar xchar
Type alias in namespace alib.
characters::strangeChar strangeChar
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
void TChar
The character type of the character array that is implemented with type TString.
void type
Default is void.
static const TChar * Buffer(const TString &src)
static constexpr ConstructionType Construction
static TString Construct(const TChar *array, integer length)
static constexpr AccessType Access
static integer Length(const TString &src)
static const TChar * Buffer(const TString &src)
static TString Construct(const TChar *array, integer length)
static integer Length(const TString &src)