inherit.h File Reference
`#include <gwenhywfar/misc.h>`
`#include <gwenhywfar/gwenhywfarapi.h>`

Go to the source code of this file.

## Macros

Macros To Be Used In Inherited Classes - Header Files
#define | GWEN_INHERIT_ELEMENT(t)
#define | GWEN_INHERIT_FUNCTION_DEFS(t)
#define | GWEN_INHERIT_FUNCTION_LIB_DEFS(t, decl)
Macros To Be Used In Inherited Classes - C Files
#define | GWEN_INHERIT_FINI(t, element)
#define | GWEN_INHERIT_FUNCTIONS(t)
#define | GWEN_INHERIT_INIT(t, element)
Macros To Be Used In Inheriting Classes
#define | GWEN_INHERIT(bt, t)
#define | GWEN_INHERIT_GETDATA(bt, t, element)
#define | GWEN_INHERIT_ISOFTYPE(bt, t, element)
#define | GWEN_INHERIT_REF(bt, t)
#define | GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
#define | GWEN_INHERIT_UNLINK(bt, t, element)

## Typedefs

typedef void GWENHYWFAR_CB(* | GWEN_INHERIT_FREEDATAFN) (void *baseData, void *data)
typedef struct GWEN_INHERITDATA | GWEN_INHERITDATA

## Functions

GWENHYWFAR_API void * | GWEN_Inherit_FindData (GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate)
GWENHYWFAR_API GWEN_INHERITDATA * | GWEN_Inherit_FindEntry (GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate)
GWENHYWFAR_API uint32_t | GWEN_Inherit_MakeId (const char *typeName)
GWENHYWFAR_API void | GWEN_InheritData_clear (GWEN_INHERITDATA *d)
GWENHYWFAR_API void | GWEN_InheritData_free (GWEN_INHERITDATA *d)
GWENHYWFAR_API void | GWEN_InheritData_freeAllData (GWEN_INHERITDATA *d)
GWENHYWFAR_API void | GWEN_InheritData_freeData (GWEN_INHERITDATA *d)
GWENHYWFAR_API void * | GWEN_InheritData_GetData (const GWEN_INHERITDATA *d)
GWENHYWFAR_API GWEN_INHERIT_FREEDATAFN | GWEN_InheritData_GetFreeDataFn (const GWEN_INHERITDATA *d)
GWENHYWFAR_API uint32_t | GWEN_InheritData_GetId (const GWEN_INHERITDATA *d)
GWENHYWFAR_API const char * | GWEN_InheritData_GetTypeName (const GWEN_INHERITDATA *d)
GWENHYWFAR_API GWEN_INHERITDATA * | GWEN_InheritData_new (const char *t, uint32_t id, void *data, void *baseData, GWEN_INHERIT_FREEDATAFN fn)

## Macro Definition Documentation

## GWEN_INHERIT

#define GWEN_INHERIT | ( |  | bt,
|  |  | t )

Value:
uint32_t t##__INHERIT_ID=0;

Use this in the C file of inheriting classes. It initializes a global variable with a hash of the inheriting type name. This is used to speed up inheritance functions. This variable will be filled with a value upon the first invocation of the macro GWEN_INHERIT_SETDATA.

Definition at line 264 of file inherit.h.

## GWEN_INHERIT_ELEMENT

#define GWEN_INHERIT_ELEMENT | ( |  | t | ) |

Value:
GWEN_INHERITDATA_LIST *INHERIT__list;
GWEN_INHERITDATA_LIST
Definition listdoc.h:4437

Use this macro inside the struct which you want to make inheritable. This macro defines some new elements for the struct for administration of inheritance.

Definition at line 112 of file inherit.h.

## GWEN_INHERIT_FINI

#define GWEN_INHERIT_FINI | ( |  | t,
|  |  | element )

Value:
{\
GWEN_INHERITDATA *inherit__data;\
\
assert(element);\
assert(element->INHERIT__list);\
\
while( (inherit__data=GWEN_InheritData_List_First(element->INHERIT__list)) ) {\
GWEN_InheritData_freeData(inherit__data); \
GWEN_InheritData_List_Del(inherit__data); \
GWEN_InheritData_free(inherit__data); \
} \
GWEN_InheritData_List_free(element->INHERIT__list);\
}
GWEN_INHERITDATA
struct GWEN_INHERITDATA GWEN_INHERITDATA
Definition inherit.h:34
GWEN_InheritData_List_First
GWEN_INHERITDATA * GWEN_InheritData_List_First(const GWEN_INHERITDATA_LIST *l)

Use this macro in your C file in destructor functions for the base class. This macro deinitializes the elements defined by the macro GWEN_INHERIT_ELEMENT. This should be the first instruction in that function, because it also gives inheriting classes the opportunity to free their own data associated with the given element. It causes the least problems if inheriting classes free their data before the base class does.

Definition at line 238 of file inherit.h.

## GWEN_INHERIT_FUNCTION_DEFS

#define GWEN_INHERIT_FUNCTION_DEFS | ( |  | t | ) |

Value:
GWEN_INHERIT_FUNCTION_LIB_DEFS(t, GWEN_DUMMY_EMPTY_ARG)
GWEN_DUMMY_EMPTY_ARG
#define GWEN_DUMMY_EMPTY_ARG
Definition idmap.h:60
GWEN_INHERIT_FUNCTION_LIB_DEFS
#define GWEN_INHERIT_FUNCTION_LIB_DEFS(t, decl)
Definition inherit.h:125

Use this macro in the header file of the base class. This defines the prototypes of some inheritance functions. This macro should be used in applications, not in libraries. In libraries please use the macro GWEN_INHERIT_FUNCTION_LIB_DEFS.

You should not care about these functions here, since you should not use them directly. Please use GWEN_INHERIT_GETDATA and GWEN_INHERIT_SETDATA instead.

Definition at line 147 of file inherit.h.

## GWEN_INHERIT_FUNCTION_LIB_DEFS

#define GWEN_INHERIT_FUNCTION_LIB_DEFS | ( |  | t,
|  |  | decl )

Value:
decl void t##__INHERIT_SETDATA(t *element, \
const char *typeName,\
uint32_t id,\
void *data,\
GWEN_INHERIT_FREEDATAFN f);\
decl int t##__INHERIT_ISOFTYPE(const t *element, uint32_t id);\
decl GWEN_INHERITDATA_LIST *t##__INHERIT_GETLIST(const t *element);\
decl void t##__INHERIT_UNLINK(t *element, \
const char *typeName,\
uint32_t id);
GWEN_INHERIT_FREEDATAFN
void GWENHYWFAR_CB(* GWEN_INHERIT_FREEDATAFN)(void *baseData, void *data)
Definition inherit.h:53

Use this macro in the header file of the base class. This defines the prototypes of some inheritance functions. This macro should be used in libraries with the __declspec(dllexport) as the `decl` argument.

You should not care about these functions here, since you should not use them directly. Please use GWEN_INHERIT_GETDATA and GWEN_INHERIT_SETDATA instead.

Definition at line 125 of file inherit.h.

## GWEN_INHERIT_FUNCTIONS

#define GWEN_INHERIT_FUNCTIONS | ( |  | t | ) |

Use this macro in the C file of the base class. It defines the implementations of the inheritance functions. This macro MUST be placed after the include statement which includes the classes header file.

Definition at line 163 of file inherit.h.

## GWEN_INHERIT_GETDATA

#define GWEN_INHERIT_GETDATA | ( |  | bt,
|  |  | t,
|  |  | element )

Value:
((t*)GWEN_Inherit_FindData(bt##__INHERIT_GETLIST(element),t##__INHERIT_ID,0))
GWEN_Inherit_FindData
GWENHYWFAR_API void * GWEN_Inherit_FindData(GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate)

This macros returns the private data of an inheriting class associated with an element of its base class.

Definition at line 279 of file inherit.h.

## GWEN_INHERIT_INIT

#define GWEN_INHERIT_INIT | ( |  | t,
|  |  | element )

Value:
{\
assert(element);\
element->INHERIT__list=GWEN_InheritData_List_new();\
}
GWEN_InheritData_List_new
GWEN_INHERITDATA_LIST * GWEN_InheritData_List_new()

Use this macro in your C file in constructor functions for the base class. This macro initializes the elements defined by the macro GWEN_INHERIT_ELEMENT.

Definition at line 223 of file inherit.h.

## GWEN_INHERIT_ISOFTYPE

#define GWEN_INHERIT_ISOFTYPE | ( |  | bt,
|  |  | t,
|  |  | element )

Value:
((bt##__INHERIT_ISOFTYPE(element,\
((t##__INHERIT_ID==0)?\
((t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t)))):\
t##__INHERIT_ID)))?1:0)
__STRING
#define __STRING(x)
Definition gwenhywfarapi.h:133
GWEN_Inherit_MakeId
GWENHYWFAR_API uint32_t GWEN_Inherit_MakeId(const char *typeName)

This macro checks whether the given element is of the given type.

Returns
  !=0 if the pointer is of the expected type, 0 otherwise

Parameters

  bt | base type
  t | derived type
  element | pointer which is to be checked

Definition at line 313 of file inherit.h.

## GWEN_INHERIT_REF

#define GWEN_INHERIT_REF | ( |  | bt,
|  |  | t )

Value:
extern uint32_t t##__INHERIT_ID;

This is an extern reference when you need to call GWEN_INHERIT_GETDATA from one source file while the GWEN_INHERIT stance is in another one.

Definition at line 271 of file inherit.h.

## GWEN_INHERIT_SETDATA

#define GWEN_INHERIT_SETDATA | ( |  | bt,
|  |  | t,
|  |  | element,
|  |  | data,
|  |  | fn )

Value:
{\
if (!t##__INHERIT_ID)\
t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\
bt##__INHERIT_SETDATA(element, __STRING(t), t##__INHERIT_ID, data, fn);\
}

This macro sets the private data of an inheriting class associated with an element of its base class. The last argument is a pointer to a function which frees the associated data. That function will be called when the element of the base class given is freed or new data is to be associated with the element. The prototype of that function is this:

typedef void (*function)(void *baseData, void *data);

Please note that the argument to that function is a pointer to the base type element. If you want to get the private data associated with the base type element (and you probably do) you must call GWEN_INHERIT_GETDATA. Every time the macro GWEN_INHERIT_SETDATA is used the previously associated data will be freed by calling the function whose prototype you've just learned.

Definition at line 300 of file inherit.h.

## GWEN_INHERIT_UNLINK

#define GWEN_INHERIT_UNLINK | ( |  | bt,
|  |  | t,
|  |  | element )

Value:
{\
if (!t##__INHERIT_ID)\
t##__INHERIT_ID=GWEN_Inherit_MakeId(__STRING(t));\
bt##__INHERIT_UNLINK(element, __STRING(t), t##__INHERIT_ID);\
}

This macro gives up the inheritance for the given type. After this macro has been executed there is no link left between the type and its base type.

Parameters

  bt | base type
  t | derived type

Definition at line 326 of file inherit.h.

## Typedef Documentation

## GWEN_INHERIT_FREEDATAFN

typedef void GWENHYWFAR_CB(* GWEN_INHERIT_FREEDATAFN) (void *baseData, void *data)

Definition at line 53 of file inherit.h.

## GWEN_INHERITDATA

typedef struct GWEN_INHERITDATA GWEN_INHERITDATA

Definition at line 34 of file inherit.h.

## Function Documentation

## GWEN_Inherit_FindData()

GWENHYWFAR_API void * GWEN_Inherit_FindData | ( | GWEN_INHERITDATA_LIST * | l,
|  | uint32_t | id,
|  | int | wantCreate )

References GWENHYWFAR_API.

## GWEN_Inherit_FindEntry()

GWENHYWFAR_API GWEN_INHERITDATA * GWEN_Inherit_FindEntry | ( | GWEN_INHERITDATA_LIST * | l,
|  | uint32_t | id,
|  | int | wantCreate )

## GWEN_Inherit_MakeId()

GWENHYWFAR_API uint32_t GWEN_Inherit_MakeId | ( | const char * | typeName | ) |

References GWENHYWFAR_API.

## GWEN_InheritData_clear()

GWENHYWFAR_API void GWEN_InheritData_clear | ( | GWEN_INHERITDATA * | d | ) |

References GWENHYWFAR_API.

## GWEN_InheritData_free()

GWENHYWFAR_API void GWEN_InheritData_free | ( | GWEN_INHERITDATA * | d | ) |

References GWENHYWFAR_API.

## GWEN_InheritData_freeAllData()

GWENHYWFAR_API void GWEN_InheritData_freeAllData | ( | GWEN_INHERITDATA * | d | ) |

References GWENHYWFAR_API.

## GWEN_InheritData_freeData()

GWENHYWFAR_API void GWEN_InheritData_freeData | ( | GWEN_INHERITDATA * | d | ) |

References GWENHYWFAR_API.

## GWEN_InheritData_GetData()

GWENHYWFAR_API void * GWEN_InheritData_GetData | ( | const GWEN_INHERITDATA * | d | ) |

References GWENHYWFAR_API.

## GWEN_InheritData_GetFreeDataFn()

GWENHYWFAR_API GWEN_INHERIT_FREEDATAFN GWEN_InheritData_GetFreeDataFn | ( | const GWEN_INHERITDATA * | d | ) |

References GWENHYWFAR_API.

## GWEN_InheritData_GetId()

GWENHYWFAR_API uint32_t GWEN_InheritData_GetId | ( | const GWEN_INHERITDATA * | d | ) |

References GWENHYWFAR_API.

## GWEN_InheritData_GetTypeName()

GWENHYWFAR_API const char * GWEN_InheritData_GetTypeName | ( | const GWEN_INHERITDATA * | d | ) |

References GWENHYWFAR_API.

## GWEN_InheritData_new()

GWENHYWFAR_API GWEN_INHERITDATA * GWEN_InheritData_new | ( | const char * | t,
|  | uint32_t | id,
|  | void * | data,
|  | void * | baseData,
|  | GWEN_INHERIT_FREEDATAFN | fn )

References GWENHYWFAR_API.