Base Framework
Classes | Static Public Member Functions | List of all members
Cast Class Reference

Type casting support. More...

#include <base/Cast.h>

Classes

class  Container
 
class  Extract
 
class  Impersonate
 

Static Public Member Functions

template<class RESULT >
static RESULT implicit (RESULT argument) noexcept
 
template<class TYPE >
static uint8 * getAddress (TYPE &value) noexcept
 
template<class TYPE >
static const uint8 * getAddress (const TYPE &value) noexcept
 
template<class TYPE >
static volatile uint8 * getAddress (volatile TYPE &value) noexcept
 
template<class TYPE >
static const volatile uint8 * getAddress (volatile const TYPE &value) noexcept
 
template<class TYPE >
static uint8 * getAddress (TYPE value[]) noexcept
 
template<class TYPE >
static const uint8 * getAddress (const TYPE value[]) noexcept
 
template<class TYPE >
static volatile uint8 * getAddress (volatile TYPE value[]) noexcept
 
template<class TYPE >
static const volatile uint8 * getAddress (volatile const TYPE value[]) noexcept
 
template<class TYPE >
static char * getCharAddress (TYPE &value) noexcept
 
template<class TYPE >
static const char * getCharAddress (const TYPE &value) noexcept
 
template<class TYPE >
static volatile char * getCharAddress (volatile TYPE &value) noexcept
 
template<class TYPE >
static const volatile char * getCharAddress (volatile const TYPE &value) noexcept
 
template<class TYPE >
static char * getCharAddress (TYPE value[]) noexcept
 
template<class TYPE >
static const char * getCharAddress (const TYPE value[]) noexcept
 
template<class TYPE >
static volatile char * getCharAddress (volatile TYPE value[]) noexcept
 
template<class TYPE >
static const volatile char * getCharAddress (volatile const TYPE value[]) noexcept
 
static MemorySize getOffset (const volatile void *value) noexcept
 
template<class TYPE >
static TYPE getPointer (MemorySize value) noexcept
 
template<class RESULT >
static RESULT up (RESULT value) noexcept
 
template<class RESULT , class ORIGINAL >
static RESULT explicitly (ORIGINAL value) noexcept
 
template<class RESULT , class ORIGINAL >
static RESULT pointer (ORIGINAL value) noexcept
 
template<class RESULT , class ORIGINAL >
static RESULT anypointer (ORIGINAL value) noexcept
 
template<class RESULT , class ORIGINAL >
static RESULT reinterpret (ORIGINAL value) noexcept
 
template<class RESULT , class ARGUMENT >
static RESULT impersonate (ARGUMENT value) noexcept
 
template<class RESULT , class ARGUMENT >
static RESULT container (ARGUMENT value) noexcept
 
template<class RESULT , class ARGUMENT >
static RESULT extract (ARGUMENT value) noexcept
 

Detailed Description

Type casting support.

This class provides common casting methods.

Version
1.0

Member Function Documentation

◆ container()

template<class RESULT , class ARGUMENT >
static RESULT Cast::container ( ARGUMENT  value)
inlinestaticnoexcept

Casts the argument to the specified type. The result type must not occupy less memory than the argument type.

See also
impersonate

◆ extract()

template<class RESULT , class ARGUMENT >
static RESULT Cast::extract ( ARGUMENT  value)
inlinestaticnoexcept

Casts the argument to the specified type. The result type must not occupy more memory than the argument type.

See also
container

◆ getAddress() [1/8]

template<class TYPE >
static const uint8* Cast::getAddress ( const TYPE &  value)
inlinestaticnoexcept

Returns the address of the specified object as a byte pointer (i.e. uint8*).

◆ getAddress() [2/8]

template<class TYPE >
static const uint8* Cast::getAddress ( const TYPE  value[])
inlinestaticnoexcept

Returns the address of the specified object as a byte pointer (i.e. uint8*).

◆ getAddress() [3/8]

template<class TYPE >
static uint8* Cast::getAddress ( TYPE &  value)
inlinestaticnoexcept

Returns the address of the specified object as a byte pointer (i.e. uint8*).

◆ getAddress() [4/8]

template<class TYPE >
static uint8* Cast::getAddress ( TYPE  value[])
inlinestaticnoexcept

Returns the address of the specified array as a byte pointer (i.e. uint8*).

◆ getAddress() [5/8]

template<class TYPE >
static const volatile uint8* Cast::getAddress ( volatile const TYPE &  value)
inlinestaticnoexcept

Returns the address of the specified object as a byte pointer (i.e. uint8*).

◆ getAddress() [6/8]

template<class TYPE >
static const volatile uint8* Cast::getAddress ( volatile const TYPE  value[])
inlinestaticnoexcept

Returns the address of the specified object as a byte pointer (i.e. uint8*).

◆ getAddress() [7/8]

template<class TYPE >
static volatile uint8* Cast::getAddress ( volatile TYPE &  value)
inlinestaticnoexcept

Returns the address of the specified object as a byte pointer (i.e. uint8*).

◆ getAddress() [8/8]

template<class TYPE >
static volatile uint8* Cast::getAddress ( volatile TYPE  value[])
inlinestaticnoexcept

Returns the address of the specified object as a byte pointer (i.e. uint8*).

◆ getCharAddress() [1/8]

template<class TYPE >
static const char* Cast::getCharAddress ( const TYPE &  value)
inlinestaticnoexcept

Returns the address of the specified object as a char pointer.

◆ getCharAddress() [2/8]

template<class TYPE >
static const char* Cast::getCharAddress ( const TYPE  value[])
inlinestaticnoexcept

Returns the address of the specified object as a char pointer.

◆ getCharAddress() [3/8]

template<class TYPE >
static char* Cast::getCharAddress ( TYPE &  value)
inlinestaticnoexcept

Returns the address of the specified object as a char pointer.

◆ getCharAddress() [4/8]

template<class TYPE >
static char* Cast::getCharAddress ( TYPE  value[])
inlinestaticnoexcept

Returns the address of the specified object as a char pointer.

◆ getCharAddress() [5/8]

template<class TYPE >
static const volatile char* Cast::getCharAddress ( volatile const TYPE &  value)
inlinestaticnoexcept

Returns the address of the specified object as a char pointer.

◆ getCharAddress() [6/8]

template<class TYPE >
static const volatile char* Cast::getCharAddress ( volatile const TYPE  value[])
inlinestaticnoexcept

Returns the address of the specified object as a char pointer.

◆ getCharAddress() [7/8]

template<class TYPE >
static volatile char* Cast::getCharAddress ( volatile TYPE &  value)
inlinestaticnoexcept

Returns the address of the specified object as a char pointer.

◆ getCharAddress() [8/8]

template<class TYPE >
static volatile char* Cast::getCharAddress ( volatile TYPE  value[])
inlinestaticnoexcept

Returns the address of the specified object as a char pointer.

◆ getOffset()

static MemorySize Cast::getOffset ( const volatile void *  value)
inlinestaticnoexcept

Returns the memory offset of the specified pointer. Any qualifiers are lost in the process!

◆ getPointer()

template<class TYPE >
static TYPE Cast::getPointer ( MemorySize  value)
inlinestaticnoexcept

Returns the pointer value corresponding to the specified memory offset.

◆ impersonate()

template<class RESULT , class ARGUMENT >
static RESULT Cast::impersonate ( ARGUMENT  value)
inlinestaticnoexcept

Casts the argument to the specified type. The argument and result types must have the exact same memory size.

See also
container

◆ implicit()

template<class RESULT >
static RESULT Cast::implicit ( RESULT  argument)
inlinestaticnoexcept

Implicit cast to the specified type.

◆ pointer()

template<class RESULT , class ORIGINAL >
static RESULT Cast::pointer ( ORIGINAL  value)
inlinestaticnoexcept

This method casts any pointer type to any other pointer type (at compile time). You should definitely avoid this function when possible. However, it is not as dangerous as using reinterpret_cast directly. This function does not cast away the qualifiers (e.g. const).

◆ up()

template<class RESULT >
static RESULT Cast::up ( RESULT  value)
inlinestaticnoexcept

This cast function is used to up cast pointers (i.e. you can explicitly specify the desired pointer type). This function only works if there exists implicit rules which convert the input type to the desired type.