1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| /* Casting.h : Définitions d'opérateurs de cast pour C et C++
==========================================================
FROMVOID_CAST: Cast d'un pointeur void* en un autre pointeur
En C : Rien du tout, le cast est implicite
En C++ : static_cast
STATIC_CAST: Opérateur de cast standard du C++
En C : Cast de type C (parenthèses)
En C++ : static_cast
REINTERPRET_CAST: Opérateur de cast standard du C++
En C : Cast de type C (parenthèses)
En C++ : reinterpret_cast
CONST_CAST: Opérateur de cast standard du C++
En C : Cast de type C (parenthèses)
En C++ : const_cast
(rien pour reproduire le dynamic_cast, qui est spécifique au C++)
*/
#ifndef CASTING_H_INCLUDED
#define CASTING_H_INCLUDED
#ifdef __cplusplus
/* Version C++ */
#define FROMVOID_CAST(t, p) static_cast< t >(p)
#define STATIC_CAST(t, x) static_cast< t >(x)
#define REINTERPRET_CAST(t, x) reinterpret_cast< t >(x)
#define CONST_CAST(t, x) const_cast< t >(x)
#define CAST_POINTER(dest, t, p) do{ void* dest ## _tmp_ ## p = p; dest = static_cast< t >(dest ## _tmp_ ## p); }while(0)
#define CAST_POINTER_(dest, t, p) { void* dest ## _tmp_ ## p = p; dest = static_cast< t >(dest ## _tmp_ ## p); }
#define CAST_POINTERC(dest, t, p) do{ void const * dest ## _tmp_ ## p = p; dest = static_cast< t >(dest ## _tmp_ ## p); }while(0)
#define CAST_POINTERC_(dest, t, p) { void const * dest ## _tmp_ ## p = p; dest = static_cast< t >(dest ## _tmp_ ## p); }
#define ALLOC_ONE(t) (new t)
#define ALLOC_MANY(t,n) (new t[n])
#define FREE_ONE(p) delete (p)
#define FREE_MANY(p) delete[] (p)
/* Fin version C++ */
#else
/* Version C */
#define FROMVOID_CAST(t, p) (p)
#define STATIC_CAST(t, x) ((t)(x))
#define REINTERPRET_CAST(t, x) ((t)(x))
#define CONST_CAST(t, x) ((t)(x))
#define CAST_POINTER(dest, t, p) do{ void* dest ## _tmp_ ## p = p; dest = dest ## _tmp_ ## p; }while(0)
#define CAST_POINTER_(dest, t, p) { void* dest ## _tmp_ ## p = p; dest = dest ## _tmp_ ## p; }
#define CAST_POINTERC(dest, t, p) do{ void const * dest ## _tmp_ ## p = p; dest = dest ## _tmp_ ## p; }while(0)
#define CAST_POINTERC_(dest, t, p) { void const * dest ## _tmp_ ## p = p; dest = dest ## _tmp_ ## p; }
#define ALLOC_ONE(t) malloc(sizeof(t))
#define ALLOC_MANY(t,n) malloc(sizeof(t)*(n))
#define FREE_ONE(p) free(p)
#define FREE_MANY(p) free(p)
/*Fin opérateurs de cast*/
#endif
#endif/* ! CASTING_H_INCLUDED */ |
Partager