📄 ooc99.h
字号:
#define private(decl) _concat_(decl, \ _concat_(__ooc_private_, \ _concat_(__LINE__,__STDC_VERSION__)))#endif/* ----------------------------------------------- macros for object identification, cast & delete -----------------------------------------------*/#define super(obj, super) \ (&((obj)->m.super))#define className(obj) \ (typeid(obj)->name)#define isA(obj, class) \ ((obj)->__vptr == (void*)(class).__vptr)#define offsetOf(obj) \ ((obj)->__iptr->offset)#define methodAddr(obj, msg) \ ((obj)->__vptr->msg)#define typeid(obj) \ (((t_object*)base_cast(obj))->__iptr->info)#define base_cast(obj) \ ((void*const)((char*)(obj) - offsetOf(obj)))#define super_cast(obj, super) \ super(obj, super)#define static_cast(obj, objclass, subclass) \ ((_concat_(t_,subclass)*const)((char*)(obj) - \ offsetof(_concat_(t_,subclass),m.objclass)))#define dynamic_cast(obj, class) \ ((_concat_(t_,class)*)_ooc_castDynamic_((void*)(obj), (void*)&(class)))#define delete(obj) \ ((obj) ? \ (typeid(obj)->class->_object(base_cast(obj)), \ free(base_cast(obj))): \ (void)0)/* ----------------------------- macros for method declaration -----------------------------*/#ifdef IMPLEMENTATION# undef classMethod# undef classMethod_# undef method# undef method_# undef constMethod# undef constMethod_# define classMethod(fct) \ (*fct)(void)# define classMethod_(fct, args) \ (*fct)(_getprm_ args)# define method(fct) \ (*fct) (t_OBJECT *const)# define method_(fct, args) \ (*fct) (t_OBJECT *const, _getprm_ args)# define constMethod(fct) \ (*fct) (t_OBJECT const*const)# define constMethod_(fct, args) \ (*fct) (t_OBJECT const*const, _getprm_ args)# define initClassDecl() \ void classMethodDecl(initClass)# define dtorDecl() \ void methodDecl(_concat_(_,OBJECT))# define classMethodDecl(fct) \ static methodName(fct)(void)# define classMethodDecl_(fct, args) \ static methodName(fct)(_getprm_ args)# define methodDecl(fct) \ static methodName(fct)(t_OBJECT *const this)# define methodDecl_(fct, args) \ static methodName(fct)(t_OBJECT *const this, _getprm_ args)# define constMethodDecl(fct) \ static methodName(fct)(t_OBJECT const*const this)# define constMethodDecl_(fct, args) \ static methodName(fct)(t_OBJECT const*const this, _getprm_ args)# define methodOvldDecl(fct, obj) \ static methodOvldName(fct,obj)(_concat_(t_,obj) *const this)# define methodOvldDecl_(fct, obj, args) \ static methodOvldName(fct,obj)(_concat_(t_,obj) *const this, _getprm_ args)# define constMethodOvldDecl(fct, obj) \ static methodOvldName(fct,obj)(_concat_(t_,obj) const*const this)# define constMethodOvldDecl_(fct, obj, args) \ static methodOvldName(fct,obj)(_concat_(t_,obj) const*const this, _getprm_ args)# define methodName(fct) \ _concat_(_concat_(fct,_m_),OBJECT)# define methodOvldName(fct, obj) \ _concat_(_concat_(fct,_m_),_concat_(_concat_(obj,_),OBJECT))#else# define classMethod(fct) \ (*const fct)(void)# define classMethod_(fct, args) \ (*const fct)(_getprm_ args)# define method(fct) \ (*const fct) (t_OBJECT *const)# define method_(fct, args) \ (*const fct) (t_OBJECT *const, _getprm_ args)# define constMethod(fct) \ (*const fct) (t_OBJECT const*const)# define constMethod_(fct, args) \ (*const fct) (t_OBJECT const*const, _getprm_ args)#endif/* -------------------------- macros for message passing --------------------------*//* object messages */#define sendMsg(obj, msg) \ ((obj)->__vptr->msg)(obj)#define sendMsg_(obj, msg, args) \ ((obj)->__vptr->msg)(obj, _getprm_ args)/* class messages */#define sendCMsg(obj, class, msg) \ ((class).__vptr->msg)(obj)#define sendCMsg_(obj, class, msg, args) \ ((class).__vptr->msg)(obj, _getprm_ args)/* -------------------------- macros for generic objects --------------------------*/#define GENERIC(obj) _concat_(gTypePrefix, obj)#define GENERIC_DTOR(obj) _concat_(_,GENERIC(obj))/* ----------- base object -----------*//* maximum number of super classes */#define _OBJECT_MAXEXTRASUPER_ 4/* disable _CONST__ if requested by user */#ifdef ALLOW_OBJCOPY# define _CONST__# define objCopy(a,b) ((a) = (b))#else# define _CONST__ const# define objCopy(a,b) memcpy(&(a), &(b), sizeof(a))#endif/* disable _CONST_ in implementation */#ifdef IMPLEMENTATION# undef _CONST_# define _CONST_#else# undef _CONST_# define _CONST_ _CONST__#endif#ifndef _OOC_INCLUDE_ONCE_#define _OOC_INCLUDE_ONCE_/* object type (public) */typedef union { struct _ooc_vtbl_object const *_CONST__ __vptr; struct _ooc_vtbl_object _CONST_*_CONST_ __iptr;} t_object;/* object virtual table type (private) */struct _ooc_vtbl_object { struct _ooc_type_info const*_CONST_ info; size_t offset;};/* object class type (private) */struct _ooc_class_object { struct _ooc_vtbl_object const*const __vptr; t_object (*const object) (void); void (*const _object) (t_object *const);};/* object RTTI (private) */struct _ooc_type_info { char const*const name; struct _ooc_class_object const*_CONST_ class; t_object const*_CONST_ obj; struct _ooc_type_info const*_CONST_ super; size_t _CONST_ extraSuper; size_t _CONST_ extraOffset[_OBJECT_MAXEXTRASUPER_];};#endif/* ------------ debug info ------------*/#if defined(DEBUG_CALL) || defined(DEBUG_MEM) || defined(DEBUG_OBJ)# include <oodebug.h>#endif#ifndef DEBUG_MEM/* for compatibility with oodebug.h */extern char *strdup(const char*); /* not ISO C, but in libc or ooc.c */#endif/* ------------ declarations ------------*//* Extern declarations*/extern void _ooc_updateRef_ (t_object *const, struct _ooc_type_info const*const);extern void*const _ooc_castDynamic_ (t_object const*const, struct _ooc_class_object const*const);extern void ooc_delete (void *const);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -