libcomps  ..
comps_obj.h
Go to the documentation of this file.
1 /* libcomps - C alternative to yum.comps library
2  * Copyright (C) 2013 Jindrich Luza
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17  * USA
18  */
19 
20 #ifndef COMPS_OBJECT_H
21 #define COMPS_OBJECT_H
22 
23 #include "comps_mm.h"
24 
59 #define COMPS_OBJECT_CREATE(objtype, args)\
60  (objtype*)comps_object_create(&objtype##_ObjInfo, args)
61 
62 
63 #define COMPS_OBJECT_CMP(obj1,obj2)\
64  comps_object_cmp((COMPS_Object*)obj1, (COMPS_Object*)obj2)
65 
66 #define COMPS_OBJECT_DESTROY(obj1)\
67  comps_object_destroy((COMPS_Object*)obj1)
68 
69 #define COMPS_OBJECT_COPY(obj)\
70  comps_object_copy(((COMPS_Object*)obj))
71 
72 #define COMPS_OBJECT_INCREF(obj)\
73  comps_object_incref(((COMPS_Object*)obj))
74 
75 #define COMPS_OBJECT_REPLACE(oldobj, TYPE, new_obj)\
76  COMPS_OBJECT_DESTROY(oldobj);\
77  oldobj = (TYPE*)COMPS_OBJECT_INCREF(new_obj);
78 
79 
80 #define COMPS_CAST_CONSTR void (*)(COMPS_Object*, COMPS_Object**)
81 #define COMPS_CAST_DESTR void (*)(COMPS_Object*)
82 
86 #define COMPS_Object_HEAD COMPS_RefC *refc;\
87  COMPS_ObjectInfo *obj_info
88 
89 #define COMPS_Object_TAIL(obj) extern COMPS_ObjectInfo obj##_ObjInfo
90 
91 typedef struct COMPS_Object COMPS_Object;
92 typedef struct COMPS_ObjectInfo COMPS_ObjectInfo;
93 typedef struct COMPS_Packed COMPS_Packed;
94 typedef struct COMPS_Num COMPS_Num;
95 typedef struct COMPS_Str COMPS_Str;
96 
97 
103  size_t obj_size;
110  COMPS_Object* (*deep_copy)(COMPS_Object*, COMPS_Object*);
112  signed char (*obj_cmp)(COMPS_Object*, COMPS_Object*);
114  char* (*to_str)(COMPS_Object*);
116 };
117 
124 struct COMPS_Object {
127 };
128 
133 struct COMPS_Num {
135  int val;
136 };
138 
143 struct COMPS_Str {
145  char *val;
146 };
148 
149 
159 
163 void comps_object_destroy(COMPS_Object *comps_obj);
164 void comps_object_destroy_v(void *comps_obj);
175 
184 signed char comps_object_cmp(COMPS_Object *obj1, COMPS_Object *obj2);
185 char comps_object_cmp_v(void *obj1, void *obj2);
186 
195 char* comps_object_tostr(COMPS_Object *obj1);
196 
200 
204 COMPS_Num* comps_num(int n);
205 
211 COMPS_Str* comps_str(const char *s);
212 
220 COMPS_Str* comps_str_x(char *s);
221 
227 void comps_str_set(COMPS_Str *str, char *s);
228 
229 //extern COMPS_ObjectInfo COMPS_Num_ObjInfo;
230 //extern COMPS_ObjectInfo COMPS_Str_ObjInfo;
231 
237 signed char comps_str_fnmatch(COMPS_Str *str, char *pattern, int flags);
238 
244 signed char comps_str_fnmatch_o(COMPS_Str *str, COMPS_Str *pattern, int flags);
245 
246 #endif
void comps_object_destroy(COMPS_Object *comps_obj)
void(* destructor)(COMPS_Object *)
Definition: comps_obj.h:106
#define COMPS_Object_HEAD
Definition: comps_obj.h:86
COMPS_ObjectInfo * obj_info
Definition: comps_obj.h:126
void(* constructor)(COMPS_Object *, COMPS_Object **)
Definition: comps_obj.h:104
char * val
Definition: comps_obj.h:145
Definition: comps_obj.h:124
void comps_str_set(COMPS_Str *str, char *s)
char * comps_object_tostr(COMPS_Object *obj1)
#define COMPS_Object_TAIL(obj)
insert "extern COMPS_ObjectInfo _ObjInfo" statement. Use this macro in combination with COMPS_OB...
Definition: comps_obj.h:89
COMPS_Object * comps_object_incref(COMPS_Object *obj)
size_t obj_size
Definition: comps_obj.h:103
signed char comps_str_fnmatch_o(COMPS_Str *str, COMPS_Str *pattern, int flags)
COMPS_Object * comps_object_create(COMPS_ObjectInfo *obj_info, COMPS_Object **args)
signed char(* obj_cmp)(COMPS_Object *, COMPS_Object *)
Definition: comps_obj.h:112
Definition: comps_obj.h:143
int val
Definition: comps_obj.h:135
COMPS_Str * comps_str(const char *s)
Definition: comps_obj.h:133
COMPS_RefC * refc
Definition: comps_obj.h:125
COMPS memory management(reference counter) file.
COMPS_Num * comps_num(int n)
void(* copy)(COMPS_Object *, COMPS_Object *)
Definition: comps_obj.h:108
Definition: comps_obj.h:102
signed char comps_str_fnmatch(COMPS_Str *str, char *pattern, int flags)
signed char comps_object_cmp(COMPS_Object *obj1, COMPS_Object *obj2)
COMPS_Str * comps_str_x(char *s)
COMPS_Object * comps_object_copy(COMPS_Object *comps_obj)
Definition: comps_mm.h:36