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

#include <evo/type.h>

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

Detailed Description

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

Basic integer type.

A basic Evo container template for integer types.

Template Parameters
TInteger plain type (short, int, long, longl, ushort, uint, ulong, ulongl, etc)

Integer types:

Examples – using Int type (and int type) here, other supported integer types work the same:

Public Types

typedef void EvoNullableType
 Identify as nullable type. More...
 
typedef IntegerT< T > This
 This non-POD type More...
 
typedef T Type
 Wrapped POD type. More...
 

Public Member Functions

 IntegerT ()
 Constructor. More...
 
 IntegerT (const IntegerT< T > &val)
 Copy constructor. More...
 
 IntegerT (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...
 
IntegerT< T > & operator= (const IntegerT< T > &val)
 Assignment operator. More...
 
IntegerT< T > & operator= (T val)
 Assignment operator. More...
 
IntegerT< 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...
 
value (T defval) const
 Get underlying value or given default if null. More...
 

Static Public Member Functions

static int digits (T num, int base=10)
 Get number of digits for given number and base. More...
 
static int maxlen (int base=10)
 Get maximum formatted length for type at base. More...
 

Static Public Attributes

static const T ALLBITS = T(~ZERO)
 Mask with all bits set. More...
 
static const int BITS = sizeof(T) * 8
 Type size in bits. More...
 
static const int BITS_MINUS_1 = BITS - 1
 BITS minus 1, used by bit manipulation code. More...
 
static const int BYTES = sizeof(T)
 Type size in bytes. More...
 
static const T LBIT = RBIT << BITS_MINUS_1
 Mask with left-most (most significant) bit set. More...
 
static const T MAX = (SIGN ? ~LBIT : ALLBITS)
 Maximum interger value. More...
 
static const int MAXSTRLEN = impl::IntMaxLen<sizeof(T)>::value
 Max formatted length, including either sign or hex/octal prefix (0x/0), but not both. More...
 
static const T MIN = (SIGN ? LBIT : 0)
 Minimum integer value. More...
 
static const T RBIT = 0x01
 Mask with right-most (least significant) bit set. More...
 
static const bool SIGN = IsSigned<T>::value
 Whether type is signed. More...
 
static const T ZERO = 0
 Mask with all bits cleared (no bits set) More...
 

Member Typedef Documentation

◆ EvoNullableType

typedef void EvoNullableType
inherited

Identify as nullable type.

◆ This

typedef IntegerT<T> This

This non-POD type

◆ Type

typedef T Type

Wrapped POD type.

Constructor & Destructor Documentation

◆ IntegerT() [1/3]

IntegerT ( )
inline

Constructor.

◆ IntegerT() [2/3]

IntegerT ( const IntegerT< T > &  val)
inline

Copy constructor.

Parameters
valValue to copy

◆ IntegerT() [3/3]

IntegerT ( 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

◆ digits()

static int digits ( num,
int  base = 10 
)
inlinestatic

Get number of digits for given number and base.

Includes sign if negative.

Parameters
numNumber to use
baseNumber base to use
Returns
Number of digits for given number and base

◆ maxlen()

static int maxlen ( int  base = 10)
inlinestatic

Get maximum formatted length for type at base.

  • Includes either sign (if signed) or hex/octal prefix (if applicable), but not both
Parameters
baseNumber base to use
Returns
Max number length for given base

◆ 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]

IntegerT<T>& operator= ( const IntegerT< T > &  val)
inline

Assignment operator.

Parameters
valValue to copy
Returns
This

◆ operator=() [2/3]

IntegerT<T>& operator= ( val)
inline

Assignment operator.

Parameters
valValue to set
Returns
This

◆ operator=() [3/3]

IntegerT<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/3]

const T& value ( ) const
inlineinherited

Get underlying value (const).

Alternative to operator*().

Returns
Whether valid

◆ value() [2/3]

T& value ( )
inlineinherited

Get underlying value.

Alternative to operator*().

Returns
Whether valid

◆ value() [3/3]

T value ( defval) const
inline

Get underlying value or given default if null.

Parameters
defvalDefault value to use if null
Returns
Result value, or defval if null

Member Data Documentation

◆ ALLBITS

const T ALLBITS = T(~ZERO)
static

Mask with all bits set.

◆ BITS

const int BITS = sizeof(T) * 8
static

Type size in bits.

◆ BITS_MINUS_1

const int BITS_MINUS_1 = BITS - 1
static

BITS minus 1, used by bit manipulation code.

◆ BYTES

const int BYTES = sizeof(T)
static

Type size in bytes.

◆ LBIT

const T LBIT = RBIT << BITS_MINUS_1
static

Mask with left-most (most significant) bit set.

◆ MAX

const T MAX = (SIGN ? ~LBIT : ALLBITS)
static

Maximum interger value.

◆ MAXSTRLEN

const int MAXSTRLEN = impl::IntMaxLen<sizeof(T)>::value
static

Max formatted length, including either sign or hex/octal prefix (0x/0), but not both.

◆ MIN

const T MIN = (SIGN ? LBIT : 0)
static

Minimum integer value.

◆ RBIT

const T RBIT = 0x01
static

Mask with right-most (least significant) bit set.

◆ SIGN

const bool SIGN = IsSigned<T>::value
static

Whether type is signed.

◆ ZERO

const T ZERO = 0
static

Mask with all bits cleared (no bits set)


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