Evo C++ Library v0.5.1
Public Types | Public Member Functions | Static Public Attributes | List of all members
CharT< T > Struct Template Reference

#include <evo/type.h>

Inheritance diagram for CharT< T >:
Inheritance graph
[legend]

Detailed Description

template<class T>
struct evo::CharT< T >

Nullable primitive character base type.

Template Parameters
TCharacter type (char)

Character types:

Examples:

Public Types

enum  Category {
  cNONE =0, cSPACE, cSYMBOL, cALPHANUM,
  cDIGIT, cALPHA, cALPHA_U, cALPHA_L
}
 Character category. More...
 
enum  Digit {
  dNONE =0, dBASE36, dHEX, dDECIMAL,
  dOCTAL
}
 Character digit type. More...
 
typedef void EvoNullableType
 Identify as nullable type. More...
 
typedef CharT< T > This
 This non-POD type More...
 
typedef T Type
 Wrapped POD type. More...
 

Public Member Functions

 CharT ()
 Constructor. More...
 
 CharT (const CharT< T > &val)
 Copy constructor. More...
 
 CharT (T val)
 Constructor. More...
 
int compare (const Nullable< T > &val) const
 Comparison. More...
 
int compare (T val) const
 Comparison. More...
 
T & denull ()
 Clears null flag and returns value reference. More...
 
bool null () const
 Get whether null. More...
 
 operator SafeBoolType () const
 Safe (explicit) evaluation as bool type. More...
 
bool operator! () const
 Negation operator returns whether null or 0. More...
 
bool operator!= (const Nullable< T > &val) const
 Inequality operator. More...
 
bool operator!= (T val) const
 Inequality operator. More...
 
const T & operator* () const
 Dereference for explicit conversion to underlying type (const). More...
 
T & operator* ()
 Dereference for explicit conversion to underlying type. More...
 
bool operator< (const Nullable< T > &val) const
 Less than operator. More...
 
bool operator< (T val) const
 Less than operator. More...
 
bool operator<= (const Nullable< T > &val) const
 Less than or equal operator. More...
 
bool operator<= (T val) const
 Less than or equal operator. More...
 
CharT< T > & operator= (const CharT< char > &val)
 Assignment operator. More...
 
CharT< T > & operator= (char val)
 Assignment operator. More...
 
CharT< T > & operator= (ValNull)
 Assignment operator to set as null by passing vNULL. More...
 
bool operator== (const Nullable< T > &val) const
 Equality operator. More...
 
bool operator== (T val) const
 Equality operator. More...
 
bool operator> (const Nullable< T > &val) const
 Greater than operator. More...
 
bool operator> (T val) const
 Greater than operator. More...
 
bool operator>= (const Nullable< T > &val) const
 Greater than or equal operator. More...
 
bool operator>= (T val) const
 Greater than or equal operator. More...
 
Nullable< T > & set ()
 Set as null. More...
 
Nullable< T > & set (const Nullable< T > &src)
 Set as copy of given value. More...
 
Nullable< T > & set (T src)
 Set as given value. More...
 
bool valid () const
 Get whether valid (not null). More...
 
const T & value () const
 Get underlying value (const). More...
 
T & value ()
 Get underlying value. More...
 

Static Public Attributes

static const int BITS = BYTES * CHAR_BIT
 Type size in bits (8) More...
 
static const int BYTES = sizeof(T)
 Type size in bytes, usually 1. More...
 

Member Typedef Documentation

◆ EvoNullableType

typedef void EvoNullableType
inherited

Identify as nullable type.

◆ This

typedef CharT<T> This

This non-POD type

◆ Type

typedef T Type

Wrapped POD type.

Member Enumeration Documentation

◆ Category

enum Category

Character category.

  • Overlapping categories (ex: alphanumeric) can be checked with greater-than (>) comparison:
    bool space = (cat == Char::cSPACE); // Whitespace (space, tab)
    bool symbol = (cat == Char::cSYMBOL); // Symbols (comma, precent, dollar, etc)
    bool digit = (cat == Char::cDIGIT); // Decimal digit (0-9)
    bool uppercase = (cat == Char::cALPHA_U); // Alphabet uppercase (A-Z)
    bool lowercase = (cat == Char::cALPHA_L); // Alphabet lowercase (a-z)
    bool alphanum = (cat > Char::cALPHANUM); // Alphanumeric (0-9, A-Z, a-z)
    bool alpha = (cat > Char::cALPHA); // Alphabet (A-Z, a-z)
    bool printable = (cat > Char::cNONE); // Any printable character
    bool visible = (cat > Char::cSPACE); // Any visible character (printable and not whitespace)
Enumerator
cNONE 

Non printable char.

cSPACE 

Whitespace (space, tab)

cSYMBOL 

Symbol character (printable but not alphanumeric)

cALPHANUM 

Alpha-numeric – categories greater than this are alphanumeric.

cDIGIT 

Decimal digit (0-9)

cALPHA 

Alphabet – categories greater than this are alphabetic.

cALPHA_U 

Alphabet uppercase (A-Z)

cALPHA_L 

Alphabet lowercase (a-z)

◆ Digit

enum Digit

Character digit type.

  • Digit types overlap so check with greater-than-or-equal (>=) comparison:
    bool b36 = (dig >= Char::dBASE36); // base 36 digit (0-9, A-Z)
    bool hex = (dig >= Char::dHEX); // hex digit (0-9, A-F)
    bool dec = (dig >= Char::dDECIMAL); // decimal digit (0-9)
    bool oct = (dig >= Char::dOCTAL); // octal digit (0-7)
    bool err = (dig == Char::dHEX); // error: must use operator >= here
Enumerator
dNONE 

Not a digit.

dBASE36 

Base 36 character.

dHEX 

Hexadecimal character.

dDECIMAL 

Decimal character.

dOCTAL 

Octal character.

Constructor & Destructor Documentation

◆ CharT() [1/3]

CharT ( )
inline

Constructor.

◆ CharT() [2/3]

CharT ( const CharT< T > &  val)
inline

Copy constructor.

Parameters
valValue to copy

◆ CharT() [3/3]

CharT ( val)
inline

Constructor.

Parameters
valValue to set

Member Function Documentation

◆ compare() [1/2]

int compare ( const Nullable< T > &  val) const
inlineinherited

Comparison.

Parameters
valValue to compare to
Returns
Result (<0 if this is less, 0 if equal, >0 if this is greater)

◆ compare() [2/2]

int compare ( val) const
inlineinherited

Comparison.

  • If null, the result is always -1 as null compares as less than any non-null value
Parameters
valValue to compare to
Returns
Result (<0 if this is less, 0 if equal, >0 if this is greater)

◆ denull()

T& denull ( )
inlineinherited

Clears null flag and returns value reference.

  • Value is unchanged, POD types default to 0 when null
  • Useful for updating the underlying value by reference
  • Note: Nullable<bool> template specialization returns by value instead of reference
Returns
Whether valid

◆ null()

bool null ( ) const
inlineinherited

Get whether null.

Returns
Whether null

◆ operator SafeBoolType()

operator SafeBoolType ( ) const
inlineinherited

Safe (explicit) evaluation as bool type.

  • This is called when object is directly evaluated as a bool, and is equivalent to: !operator!()
  • See SafeBool

◆ operator!()

bool operator! ( ) const
inlineinherited

Negation operator returns whether null or 0.

Returns
Whether null or 0

◆ operator!=() [1/2]

bool operator!= ( const Nullable< T > &  val) const
inlineinherited

Inequality operator.

Parameters
valValue to compare to
Returns
Whether inequal

◆ operator!=() [2/2]

bool operator!= ( val) const
inlineinherited

Inequality operator.

  • If null, the result is always true as null is not equal to any non-null value
Parameters
valValue to compare to
Returns
Whether inequal, true if null

◆ operator*() [1/2]

const T& operator* ( ) const
inlineinherited

Dereference for explicit conversion to underlying type (const).

Alternative to value().

Returns
Underlying type value

◆ operator*() [2/2]

T& operator* ( )
inlineinherited

Dereference for explicit conversion to underlying type.

Alternative to value().

Returns
Underlying type value

◆ operator<() [1/2]

bool operator< ( const Nullable< T > &  val) const
inlineinherited

Less than operator.

  • If null, null is less than any non-null value
Parameters
valValue to compare to
Returns
Whether less than val

◆ operator<() [2/2]

bool operator< ( val) const
inlineinherited

Less than operator.

  • If null, null is less than any non-null value
Parameters
valValue to compare to
Returns
Whether less than val

◆ operator<=() [1/2]

bool operator<= ( const Nullable< T > &  val) const
inlineinherited

Less than or equal operator.

  • If null, null is less than or equal to any value
Parameters
valValue to compare to
Returns
Whether less than or equal to val, true if null

◆ operator<=() [2/2]

bool operator<= ( val) const
inlineinherited

Less than or equal operator.

  • If null, null is less than or equal to any value
Parameters
valValue to compare to
Returns
Whether less than or equal to val, true if null

◆ operator=() [1/3]

CharT<T>& operator= ( const CharT< char > &  val)
inline

Assignment operator.

Parameters
valValue to copy
Returns
This

◆ operator=() [2/3]

CharT<T>& operator= ( char  val)
inline

Assignment operator.

Parameters
valValue to set
Returns
This

◆ operator=() [3/3]

CharT<T>& operator= ( ValNull  )
inline

Assignment operator to set as null by passing vNULL.

Returns
This

◆ operator==() [1/2]

bool operator== ( const Nullable< T > &  val) const
inlineinherited

Equality operator.

Parameters
valValue to compare to
Returns
Whether equal

◆ operator==() [2/2]

bool operator== ( val) const
inlineinherited

Equality operator.

  • If null, the result is always false as null is not equal to any non-null value
Parameters
valValue to compare to
Returns
Whether equal, false if null

◆ operator>() [1/2]

bool operator> ( const Nullable< T > &  val) const
inlineinherited

Greater than operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than val, false if null

◆ operator>() [2/2]

bool operator> ( val) const
inlineinherited

Greater than operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than val, false if null

◆ operator>=() [1/2]

bool operator>= ( const Nullable< T > &  val) const
inlineinherited

Greater than or equal operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than or equal to val

◆ operator>=() [2/2]

bool operator>= ( val) const
inlineinherited

Greater than or equal operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than or equal to val

◆ set() [1/3]

Nullable<T>& set ( )
inlineinherited

Set as null.

Returns
This

◆ set() [2/3]

Nullable<T>& set ( const Nullable< T > &  src)
inlineinherited

Set as copy of given value.

Parameters
srcSource to copy
Returns
This

◆ set() [3/3]

Nullable<T>& set ( src)
inlineinherited

Set as given value.

Parameters
srcSource to set
Returns
This

◆ valid()

bool valid ( ) const
inlineinherited

Get whether valid (not null).

Returns
Whether valid

◆ value() [1/2]

const T& value ( ) const
inlineinherited

Get underlying value (const).

Alternative to operator*().

Returns
Whether valid

◆ value() [2/2]

T& value ( )
inlineinherited

Get underlying value.

Alternative to operator*().

Returns
Whether valid

Member Data Documentation

◆ BITS

const int BITS = BYTES * CHAR_BIT
static

Type size in bits (8)

◆ BYTES

const int BYTES = sizeof(T)
static

Type size in bytes, usually 1.


The documentation for this struct was generated from the following file: