Go to the documentation of this file. 1#ifndef ERT_TYPE_MACROS_H
2#define ERT_TYPE_MACROS_H
47#define UTIL_IS_INSTANCE_FUNCTION(type , TYPE_ID) \
48bool type ## _is_instance( const void * __arg ) { \
52 const type ## _type * arg = (const type ## _type * ) __arg; \
53 if ( arg->__type_id == TYPE_ID) \
61#define UTIL_IS_INSTANCE_HEADER(type) bool type ## _is_instance( const void * __arg )
64#define UTIL_SAFE_CAST_FUNCTION(type , TYPE_ID) \
65type ## _type * type ## _safe_cast( void * __arg ) { \
66 if (__arg == NULL) { \
67 util_abort("%s: runtime cast failed - tried to dereference NULL\n",__func__); \
71 type ## _type * arg = (type ## _type *) __arg; \
72 if ( arg->__type_id == TYPE_ID) \
75 util_abort("%s: runtime cast failed: Got ID:%d Expected ID:%d \n", __func__ , arg->__type_id , TYPE_ID); \
80#define UTIL_SAFE_CAST_HEADER( type ) type ## _type * type ## _safe_cast( void * __arg )
83#define UTIL_SAFE_CAST_FUNCTION_CONST(type , TYPE_ID) \
84const type ## _type * type ## _safe_cast_const( const void * __arg ) { \
85 if (__arg == NULL) { \
86 util_abort("%s: runtime cast failed - tried to dereference NULL\n",__func__); \
90 const type ## _type * arg = (const type ## _type *) __arg; \
91 if ( arg->__type_id == TYPE_ID) \
94 util_abort("%s: runtime cast failed: Got ID:%d Expected ID:%d \n", __func__ , arg->__type_id , TYPE_ID); \
99#define UTIL_SAFE_CAST_HEADER_CONST( type ) const type ## _type * type ## _safe_cast_const( const void * __arg )
104#define UTIL_TRY_CAST_FUNCTION(type , TYPE_ID) \
105type ## _type * type ## _try_cast( void * __arg ) { \
109 type ## _type * arg = (type ## _type *) __arg; \
110 if ( arg->__type_id == TYPE_ID) \
116#define UTIL_TRY_CAST_HEADER( type ) type ## _type * type ## _try_cast( void * __arg )
119#define UTIL_TRY_CAST_FUNCTION_CONST(type , TYPE_ID) \
120const type ## _type * type ## _try_cast_const( const void * __arg ) { \
124 const type ## _type * arg = (type ## _type *) __arg; \
125 if ( arg->__type_id == TYPE_ID) \
131#define UTIL_TRY_CAST_HEADER_CONST( type ) const type ## _type * type ## _try_cast_const( const void * __arg )
136#define UTIL_TYPE_ID_DECLARATION int __type_id
137#define UTIL_TYPE_ID_INIT(var , TYPE_ID) var->__type_id = TYPE_ID;
|