00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef COMPS_OBJECT_H
00021 #define COMPS_OBJECT_H
00022
00023 #include "comps_mm.h"
00024
00059 #define COMPS_OBJECT_CREATE(objtype, args)\
00060 (objtype*)comps_object_create(&objtype##_ObjInfo, args)
00061
00062
00063 #define COMPS_OBJECT_CMP(obj1,obj2)\
00064 comps_object_cmp((COMPS_Object*)obj1, (COMPS_Object*)obj2)
00065
00066 #define COMPS_OBJECT_DESTROY(obj1)\
00067 comps_object_destroy((COMPS_Object*)obj1)
00068
00069 #define COMPS_OBJECT_COPY(obj)\
00070 comps_object_copy(((COMPS_Object*)obj))
00071
00072 #define COMPS_OBJECT_INCREF(obj)\
00073 comps_object_incref(((COMPS_Object*)obj))
00074
00075 #define COMPS_OBJECT_REPLACE(oldobj, TYPE, new_obj)\
00076 COMPS_OBJECT_DESTROY(oldobj);\
00077 oldobj = (TYPE*)COMPS_OBJECT_INCREF(new_obj);
00078
00079
00080 #define COMPS_CAST_CONSTR void (*)(COMPS_Object*, COMPS_Object**)
00081 #define COMPS_CAST_DESTR void (*)(COMPS_Object*)
00082
00086 #define COMPS_Object_HEAD COMPS_RefC *refc;\
00087 COMPS_ObjectInfo *obj_info
00088
00089 #define COMPS_Object_TAIL(obj) extern COMPS_ObjectInfo obj##_ObjInfo
00090
00091 typedef struct COMPS_Object COMPS_Object;
00092 typedef struct COMPS_ObjectInfo COMPS_ObjectInfo;
00093 typedef struct COMPS_Packed COMPS_Packed;
00094 typedef struct COMPS_Num COMPS_Num;
00095 typedef struct COMPS_Str COMPS_Str;
00096
00097
00102 struct COMPS_ObjectInfo {
00103 size_t obj_size;
00104 void (*constructor)(COMPS_Object*, COMPS_Object **);
00106 void (*destructor)(COMPS_Object*);
00108 void (*copy)(COMPS_Object*, COMPS_Object*);
00110 COMPS_Object* (*deep_copy)(COMPS_Object*, COMPS_Object*);
00112 signed char (*obj_cmp)(COMPS_Object*, COMPS_Object*);
00114 char* (*to_str)(COMPS_Object*);
00116 };
00117
00124 struct COMPS_Object {
00125 COMPS_RefC *refc;
00126 COMPS_ObjectInfo *obj_info;
00127 };
00128
00133 struct COMPS_Num {
00134 COMPS_Object_HEAD;
00135 int val;
00136 };
00137 COMPS_Object_TAIL(COMPS_Num);
00138
00143 struct COMPS_Str {
00144 COMPS_Object_HEAD;
00145 char *val;
00146 };
00147 COMPS_Object_TAIL(COMPS_Str);
00148
00149
00158 COMPS_Object* comps_object_create(COMPS_ObjectInfo *obj_info, COMPS_Object **args);
00159
00163 void comps_object_destroy(COMPS_Object *comps_obj);
00164 void comps_object_destroy_v(void *comps_obj);
00174 COMPS_Object* comps_object_copy(COMPS_Object *comps_obj);
00175
00184 signed char comps_object_cmp(COMPS_Object *obj1, COMPS_Object *obj2);
00185 char comps_object_cmp_v(void *obj1, void *obj2);
00186
00195 char* comps_object_tostr(COMPS_Object *obj1);
00196
00199 COMPS_Object* comps_object_incref(COMPS_Object *obj);
00200
00204 COMPS_Num* comps_num(int n);
00205
00211 COMPS_Str* comps_str(const char *s);
00212
00220 COMPS_Str* comps_str_x(char *s);
00221
00227 void comps_str_set(COMPS_Str *str, char *s);
00228
00229
00230
00231
00237 signed char comps_str_fnmatch(COMPS_Str *str, char *pattern, int flags);
00238
00244 signed char comps_str_fnmatch_o(COMPS_Str *str, COMPS_Str *pattern, int flags);
00245
00246 #endif