00001 #ifndef NPS_OBJECT_H
00002 #define NPS_OBJECT_H
00003
00004 #include <stdarg.h>
00005 #include <stdlib.h>
00006 #include "../error/error.h"
00007
00008
00009
00010
00011
00012 struct Object {
00013 const struct Class *class;
00014 unsigned long count;
00015 };
00016
00017 struct Class {
00018 const struct Object descr;
00019 const struct Class *super;
00020 size_t size;
00021 char *name;
00022
00023 struct Object *(*ctor) (struct Object *, nps_error_t *, va_list *ap);
00024 int (*dtor) (struct Object *, nps_error_t *error);
00025 };
00026
00027
00028
00029
00030
00031
00032
00033 extern const struct Class Object[];
00034 extern const struct Class Class[];
00035
00036
00037
00038
00039
00040 extern void nps_initObject();
00041
00042
00043
00044 extern int nps_releaseClasses(nps_error_t *error);
00045
00046
00047
00048 extern struct Object *nps_cast(const struct Class *to, struct Object *val);
00049
00050 extern void nps_retain( struct Object *o);
00051
00052 extern int nps_release( struct Object *o, nps_error_t *err);
00053
00054
00055 extern struct Object *nps_new(const struct Class *class, nps_error_t *err,...);
00056
00057 #define CAST(cls,val) (struct cls *) nps_cast(cls,(struct Object *)val)
00058 #define NEW(cls,nps_err,...) \
00059 ((struct cls*) nps_new((struct Class *)cls, nps_err, __VA_ARGS__))
00060
00061 #define RELEASE(val,error) nps_release(CAST(Object,val),error)
00062 #define RETAIN(val) nps_retain(CAST(Object,val))
00063
00064 #endif