MeshLib
 
Loading...
Searching...
No Matches
TypeCast.h File Reference
#include "Concat.h"
#include <type_traits>
#include <utility>

Go to the source code of this file.

Classes

struct  auto_cast_trait< T >
 

Macros

#define ADD_AUTO_CAST(From, To)   template <> struct auto_cast_trait<From> { using target_type = To; }
 helper macro to associate source and target types for auto-casting
 
#define REGISTER_AUTO_CAST2(Type1, Type2)
 helper macro to associate two types mutually for auto-casting
 
#define REGISTER_AUTO_CAST(Type)   REGISTER_AUTO_CAST2( Type, MR_CONCAT( MR, Type ) )
 
#define ARG(X)   auto&& X = *auto_cast( MR_CONCAT( X, _ ) )
 
#define ARG_PTR(X)   auto&& X = auto_cast( MR_CONCAT( X, _ ) )
 helper macro to cast a function argument from C pointer to C++ pointer
 
#define ARG_VAL(X)   auto&& X = auto_cast( MR_CONCAT( X, _ ) )
 helper macro to cast a function argument from C pointer to C++ value
 
#define ARG_OF(Type, X)   auto&& X = *cast_to<Type>( MR_CONCAT( X, _ ) )
 helper macro to cast a function argument from C pointer to C++ reference of specified type
 
#define ARG_PTR_OF(Type, X)   auto&& X = cast_to<Type>( MR_CONCAT( X, _ ) )
 helper macro to cast a function argument from C pointer to C++ pointer of specified type
 
#define ARG_VAL_OF(Type, X)   auto&& X = cast_to<Type>( MR_CONCAT( X, _ ) )
 helper macro to cast a function argument from C pointer to C++ value of specified type
 
#define RETURN(...)   return auto_cast( __VA_ARGS__ )
 helper macro to auto-cast and return value
 
#define RETURN_NEW(...)   return auto_cast( new_from( __VA_ARGS__ ) )
 helper function to allocate a new object of auto-detected type, auto-cast and return it
 
#define RETURN_NEW_OF(Type, ...)   return auto_cast( new_from<Type>( __VA_ARGS__ ) )
 helper function to allocate a new object of specified type, auto-cast and return it
 

Functions

template<typename T , typename U >
auto cast_to (U *from)
 helper functions to cast types without explicit qualifiers
 
template<typename T , typename U >
auto cast_to (U &from)
 
template<typename T , typename U >
auto cast_to (U &&from)
 
template<typename U >
auto auto_cast (U &&from)
 helper function to cast to an associated type
 
template<typename T , typename U = std::remove_cvref_t<T>>
U * new_from (T &&a)
 helper function to allocate a new object of auto-detected type
 

Macro Definition Documentation

◆ ADD_AUTO_CAST

#define ADD_AUTO_CAST ( From,
To )   template <> struct auto_cast_trait<From> { using target_type = To; }

helper macro to associate source and target types for auto-casting

◆ ARG

#define ARG ( X)    auto&& X = *auto_cast( MR_CONCAT( X, _ ) )

helper macro to cast a function argument from C pointer to C++ reference

int mrClassGetValue( const MRClass* obj_ )
{
ARG( obj ); // declares `const Class& obj` variable and casts `obj_` to it
return obj.GetValue();
}
#define ARG(X)
Definition TypeCast.h:72

◆ ARG_OF

#define ARG_OF ( Type,
X )   auto&& X = *cast_to<Type>( MR_CONCAT( X, _ ) )

helper macro to cast a function argument from C pointer to C++ reference of specified type

◆ ARG_PTR

#define ARG_PTR ( X)    auto&& X = auto_cast( MR_CONCAT( X, _ ) )

helper macro to cast a function argument from C pointer to C++ pointer

◆ ARG_PTR_OF

#define ARG_PTR_OF ( Type,
X )   auto&& X = cast_to<Type>( MR_CONCAT( X, _ ) )

helper macro to cast a function argument from C pointer to C++ pointer of specified type

◆ ARG_VAL

#define ARG_VAL ( X)    auto&& X = auto_cast( MR_CONCAT( X, _ ) )

helper macro to cast a function argument from C pointer to C++ value

◆ ARG_VAL_OF

#define ARG_VAL_OF ( Type,
X )   auto&& X = cast_to<Type>( MR_CONCAT( X, _ ) )

helper macro to cast a function argument from C pointer to C++ value of specified type

◆ REGISTER_AUTO_CAST

#define REGISTER_AUTO_CAST ( Type)    REGISTER_AUTO_CAST2( Type, MR_CONCAT( MR, Type ) )

◆ REGISTER_AUTO_CAST2

#define REGISTER_AUTO_CAST2 ( Type1,
Type2 )
Value:
ADD_AUTO_CAST( Type1, Type2 ); \
ADD_AUTO_CAST( Type2, Type1 );
#define ADD_AUTO_CAST(From, To)
helper macro to associate source and target types for auto-casting
Definition TypeCast.h:53

helper macro to associate two types mutually for auto-casting

◆ RETURN

#define RETURN ( ...)    return auto_cast( __VA_ARGS__ )

helper macro to auto-cast and return value

◆ RETURN_NEW

#define RETURN_NEW ( ...)    return auto_cast( new_from( __VA_ARGS__ ) )

helper function to allocate a new object of auto-detected type, auto-cast and return it

◆ RETURN_NEW_OF

#define RETURN_NEW_OF ( Type,
... )   return auto_cast( new_from<Type>( __VA_ARGS__ ) )

helper function to allocate a new object of specified type, auto-cast and return it

Function Documentation

◆ auto_cast()

template<typename U >
auto auto_cast ( U && from)
inline

helper function to cast to an associated type

◆ cast_to() [1/3]

template<typename T , typename U >
auto cast_to ( U && from)
inline

◆ cast_to() [2/3]

template<typename T , typename U >
auto cast_to ( U & from)
inline

◆ cast_to() [3/3]

template<typename T , typename U >
auto cast_to ( U * from)
inline

helper functions to cast types without explicit qualifiers

◆ new_from()

template<typename T , typename U = std::remove_cvref_t<T>>
U * new_from ( T && a)
inline

helper function to allocate a new object of auto-detected type