libcomps ..

Loading...
Searching...
No Matches
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
102 struct COMPS_ObjectInfo {
103 size_t obj_size;
104 void (*constructor)(COMPS_Object*, COMPS_Object **);
106 void (*destructor)(COMPS_Object*);
108 void (*copy)(COMPS_Object*, COMPS_Object*);
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 {
125 COMPS_RefC *refc;
126 COMPS_ObjectInfo *obj_info;
127};
128
133 struct COMPS_Num {
134 COMPS_Object_HEAD;
135 int val;
136};
137 COMPS_Object_TAIL(COMPS_Num);
138
143 struct COMPS_Str {
144 COMPS_Object_HEAD;
145 char *val;
146};
147 COMPS_Object_TAIL(COMPS_Str);
148
149
158 COMPS_Object* comps_object_create(COMPS_ObjectInfo *obj_info, COMPS_Object **args);
159
163 void comps_object_destroy(COMPS_Object *comps_obj);
164 void comps_object_destroy_v(void *comps_obj);
174 COMPS_Object* comps_object_copy(COMPS_Object *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
199 COMPS_Object* comps_object_incref(COMPS_Object *obj);
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
comps_mm.h
COMPS memory management(reference counter) file.
COMPS_Object_HEAD
#define COMPS_Object_HEAD
Definition comps_obj.h:86
comps_num
COMPS_Num * comps_num(int n)
comps_object_cmp
signed char comps_object_cmp(COMPS_Object *obj1, COMPS_Object *obj2)
comps_object_destroy
void comps_object_destroy(COMPS_Object *comps_obj)
comps_str_fnmatch_o
signed char comps_str_fnmatch_o(COMPS_Str *str, COMPS_Str *pattern, int flags)
comps_object_create
COMPS_Object * comps_object_create(COMPS_ObjectInfo *obj_info, COMPS_Object **args)
comps_str_fnmatch
signed char comps_str_fnmatch(COMPS_Str *str, char *pattern, int flags)
comps_str_x
COMPS_Str * comps_str_x(char *s)
COMPS_Object_TAIL
#define COMPS_Object_TAIL(obj)
insert "extern COMPS_ObjectInfo <obj>_ObjInfo" statement. Use this macro in combination with COMPS_OB...
Definition comps_obj.h:89
comps_object_tostr
char * comps_object_tostr(COMPS_Object *obj1)
comps_object_copy
COMPS_Object * comps_object_copy(COMPS_Object *comps_obj)
comps_str_set
void comps_str_set(COMPS_Str *str, char *s)
comps_object_incref
COMPS_Object * comps_object_incref(COMPS_Object *obj)
comps_str
COMPS_Str * comps_str(const char *s)
COMPS_Num
Definition comps_obj.h:133
COMPS_Num::val
int val
Definition comps_obj.h:135
COMPS_ObjectInfo
Definition comps_obj.h:102
COMPS_ObjectInfo::obj_cmp
signed char(* obj_cmp)(COMPS_Object *, COMPS_Object *)
Definition comps_obj.h:112
COMPS_ObjectInfo::copy
void(* copy)(COMPS_Object *, COMPS_Object *)
Definition comps_obj.h:108
COMPS_ObjectInfo::constructor
void(* constructor)(COMPS_Object *, COMPS_Object **)
Definition comps_obj.h:104
COMPS_ObjectInfo::obj_size
size_t obj_size
Definition comps_obj.h:103
COMPS_ObjectInfo::destructor
void(* destructor)(COMPS_Object *)
Definition comps_obj.h:106
COMPS_Object
Definition comps_obj.h:124
COMPS_Object::refc
COMPS_RefC * refc
Definition comps_obj.h:125
COMPS_Object::obj_info
COMPS_ObjectInfo * obj_info
Definition comps_obj.h:126
COMPS_RefC
Definition comps_mm.h:36
COMPS_Str
Definition comps_obj.h:143
COMPS_Str::val
char * val
Definition comps_obj.h:145