123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #ifndef obj_H_INCLUDED
- #define obj_H_INCLUDED
- #include "mem.h"
- struct ObjClass_;
- typedef struct ObjClass_ ObjClass;
- typedef ObjClass * (ObjMethod)(ObjClass * self, ...);
- #define IMPLEMENT_OBJCLASS \
- struct ObjClass_ * up; \
- ObjMethod * done; \
- ObjMethod * free;
- struct ObjClass_ {
- struct ObjClass_ * up;
- ObjMethod * done;
- ObjMethod * free;
- };
- #define OBJCLASS_GETFUNCTION_AT(KLASSPTR, FUNCTYPE, OFFSET) \
- ((FUNCTYPE)(((char *)(KLASSPTR))+(OFFSET)))
- #define OBJCLASS_GETFUNCTION(KLASSPTR, KLASSTYPE, FUNCTYPE, NAME) \
- OBJCLASS_GETFUNCTION_AT((KLASSPTR), (FUNCTYPE), \
- offsetof(KLASSTYPE, NAME))
- struct ObjPool_;
- typedef struct ObjPool_ ObjPool;
- struct ObjPoolNode_;
- typedef struct ObjPoolNode_ ObjPoolNode;
- struct ObjPool_ {
- ObjPoolNode * last;
-
- };
- #ifndef CFH_OBJ_PROTO
- #define CFH_OBJ_PROTO
- ObjPool * objpool_init (ObjPool * pool );
- void * objpool_register_data (ObjPool * pool , void * data );
- void * obj_alloc_in_pool (ObjPool * pool , size_t size , ObjClass * klass );
- void * obj_alloc (size_t size , ObjClass * klass );
- void * obj_ref (void * ptr );
- ObjClass * obj_class (void * ptr );
- ObjMethod * objclass_method_at (ObjClass * klass , size_t offset );
- ObjMethod * objclass_getfree (ObjClass * klass );
- void * obj_done (void * ptr );
- void * obj_free (void * ptr );
- void * obj_unref (void * ptr );
- ObjPool * objpool_unref (ObjPool * pool );
- #endif
- #endif
|