libcomps  ..
 All Data Structures Files Functions Variables Enumerations Macros Modules Pages
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 
47 #define COMPS_OBJECT_CMP(obj1,obj2)\
48  comps_object_cmp((COMPS_Object*)obj1, (COMPS_Object*)obj2)
49 
50 #define COMPS_OBJECT_DESTROY(obj1)\
51  comps_object_destroy((COMPS_Object*)obj1)
52 
53 #define COMPS_OBJECT_COPY(obj)\
54  comps_object_copy(((COMPS_Object*)obj))
55 
56 #define COMPS_OBJECT_INCREF(obj)\
57  comps_object_incref(((COMPS_Object*)obj))
58 
59 #define COMPS_CAST_CONSTR void (*)(COMPS_Object*, COMPS_Object**)
60 #define COMPS_CAST_DESTR void (*)(COMPS_Object*)
61 
65 #define COMPS_Object_HEAD COMPS_RefC *refc;\
66  COMPS_ObjectInfo *obj_info
67 
68 typedef struct COMPS_Object COMPS_Object;
69 typedef struct COMPS_ObjectInfo COMPS_ObjectInfo;
70 typedef struct COMPS_Packed COMPS_Packed;
71 typedef struct COMPS_Num COMPS_Num;
72 typedef struct COMPS_Str COMPS_Str;
73 
74 
80  size_t obj_size;
87  COMPS_Object* (*deep_copy)(COMPS_Object*, COMPS_Object*);
89  signed char (*obj_cmp)(COMPS_Object*, COMPS_Object*);
91  char* (*to_str)(COMPS_Object*);
93 };
94 
101 struct COMPS_Object {
104 };
105 
110 struct COMPS_Num {
112  int val;
113 };
114 
119 struct COMPS_Str {
121  char *val;
122 };
123 
124 
134 
138 void comps_object_destroy(COMPS_Object *comps_obj);
139 void comps_object_destroy_v(void *comps_obj);
150 
159 signed char comps_object_cmp(COMPS_Object *obj1, COMPS_Object *obj2);
160 char comps_object_cmp_v(void *obj1, void *obj2);
161 
170 char* comps_object_tostr(COMPS_Object *obj1);
171 
175 
179 COMPS_Num* comps_num(int n);
180 
186 COMPS_Str* comps_str(const char *s);
187 
195 COMPS_Str* comps_str_x(char *s);
196 
202 void comps_str_set(COMPS_Str *str, char *s);
203 
204 extern COMPS_ObjectInfo COMPS_Num_ObjInfo;
205 extern COMPS_ObjectInfo COMPS_Str_ObjInfo;
206 
207 #endif
void comps_object_destroy(COMPS_Object *comps_obj)
void(* copy)(COMPS_Object *, COMPS_Object *)
Definition: comps_obj.h:85
#define COMPS_Object_HEAD
Definition: comps_obj.h:65
COMPS_ObjectInfo * obj_info
Definition: comps_obj.h:103
char * val
Definition: comps_obj.h:121
Definition: comps_obj.h:101
void comps_str_set(COMPS_Str *str, char *s)
char * comps_object_tostr(COMPS_Object *obj1)
COMPS_Object * comps_object_incref(COMPS_Object *obj)
size_t obj_size
Definition: comps_obj.h:80
COMPS_Object * comps_object_create(COMPS_ObjectInfo *obj_info, COMPS_Object **args)
Definition: comps_obj.h:119
int val
Definition: comps_obj.h:112
COMPS_Str * comps_str(const char *s)
Definition: comps_obj.h:110
COMPS_RefC * refc
Definition: comps_obj.h:102
COMPS memory management(reference counter) file.
COMPS_Num * comps_num(int n)
Definition: comps_obj.h:79
void(* destructor)(COMPS_Object *)
Definition: comps_obj.h:83
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)
void(* constructor)(COMPS_Object *, COMPS_Object **)
Definition: comps_obj.h:81
Definition: comps_mm.h:36
signed char(* obj_cmp)(COMPS_Object *, COMPS_Object *)
Definition: comps_obj.h:89