00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CU_INHERIT_H
00019 #define CU_INHERIT_H
00020
00021 #include <stddef.h>
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef CU_MARG
00030 # ifndef CU_NDEBUG
00031 # define CU_MARG(ptr_t, ptr) ((ptr_t)(1? (ptr_t)(ptr) : (ptr)))
00032 # else
00033 # define CU_MARG(ptr_t, ptr) ((ptr_t)(ptr))
00034 # endif
00035 #endif
00036
00037 #define CU_BASE_FIELD(base_s) _base_##base_s
00038 #define cu_inherit(base_s) struct base_s CU_BASE_FIELD(base_s)
00039 #define cu_inherit_virtual(base_s) struct base_s *_vbase_##base_s
00040 #define cu_set_virtual(base_s, ptr, vbase) \
00041 ((void)((ptr)->_vbase_##base_s = vbase))
00042
00043 #define cu_base_offset(sup, base) \
00044 offsetof(struct sup, _base_##base)
00045
00046 #define cu_to(b1, o) (&(o)->CU_BASE_FIELD(b1))
00047 #define cu_to2(b2, b1, o) cu_to(b2, cu_to(b1, o))
00048 #define cu_to3(b3, b2, b1, o) cu_to(b3, cu_to2(b2, b1, o))
00049 #define cu_to4(b4, b3, b2, b1, o) cu_to(b4, cu_to3(b3, b2, b1, o))
00050 #define cu_to5(b5, b4, b3, b2, b1, o) cu_to(b5, cu_to4(b4, b3, b2, b1, o))
00051 #define cu_to_virtual(base_s, o) ((o)->_vbase_##base_s)
00052
00053 #define cu_from(s1, s0, o) \
00054 ((struct s1 *)((char *)CU_MARG(struct s0 *, o) \
00055 - offsetof(struct s1, _base_##s0)))
00056 #define cu_from2(s2, s1, s0, o) \
00057 cu_from(s2, s1, cu_from(s1, s0, o))
00058 #define cu_from3(s3, s2, s1, s0, o) \
00059 cu_from(s3, s2, cu_from2(s2, s1, s0, o))
00060 #define cu_from4(s4, s3, s2, s1, s0, o) \
00061 cu_from(s4, s3, cu_from3(s3, s2, s1, s0, o))
00062 #define cu_from5(s0, s1, s2, s3, s4, s5, o) \
00063 cu_sub(s0, s1, cu_sub4(s1, s2, s3, s4, s5, (o)))
00064
00065
00066 #endif