Loading...
Searching...
No Matches
comps_obj.h
Go to the documentation of this file.
/* libcomps - C alternative to yum.comps library
* Copyright (C) 2013 Jindrich Luza
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA
*/
#ifndef COMPS_OBJECT_H
#define COMPS_OBJECT_H
#include "comps_mm.h"
#define COMPS_OBJECT_CREATE(objtype, args)\
(objtype*)comps_object_create(&objtype##_ObjInfo, args)
#define COMPS_OBJECT_CMP(obj1,obj2)\
comps_object_cmp((COMPS_Object*)obj1, (COMPS_Object*)obj2)
#define COMPS_OBJECT_DESTROY(obj1)\
comps_object_destroy((COMPS_Object*)obj1)
#define COMPS_OBJECT_COPY(obj)\
comps_object_copy(((COMPS_Object*)obj))
#define COMPS_OBJECT_INCREF(obj)\
comps_object_incref(((COMPS_Object*)obj))
#define COMPS_OBJECT_REPLACE(oldobj, TYPE, new_obj)\
COMPS_OBJECT_DESTROY(oldobj);\
oldobj = (TYPE*)COMPS_OBJECT_INCREF(new_obj);
#define COMPS_CAST_CONSTR void (*)(COMPS_Object*, COMPS_Object**)
#define COMPS_CAST_DESTR void (*)(COMPS_Object*)
#define COMPS_Object_HEAD COMPS_RefC *refc;\
COMPS_ObjectInfo *obj_info
#define COMPS_Object_TAIL(obj) extern COMPS_ObjectInfo obj##_ObjInfo
typedef struct COMPS_Object COMPS_Object;
typedef struct COMPS_ObjectInfo COMPS_ObjectInfo;
typedef struct COMPS_Packed COMPS_Packed;
typedef struct COMPS_Num COMPS_Num;
typedef struct COMPS_Str COMPS_Str;
struct COMPS_ObjectInfo {
size_t obj_size;
void (*constructor)(COMPS_Object*, COMPS_Object **);
void (*destructor)(COMPS_Object*);
void (*copy)(COMPS_Object*, COMPS_Object*);
COMPS_Object* (*deep_copy)(COMPS_Object*, COMPS_Object*);
signed char (*obj_cmp)(COMPS_Object*, COMPS_Object*);
char* (*to_str)(COMPS_Object*);
};
struct COMPS_Object {
COMPS_RefC *refc;
COMPS_ObjectInfo *obj_info;
};
struct COMPS_Num {
COMPS_Object_HEAD;
int val;
};
COMPS_Object_TAIL(COMPS_Num);
struct COMPS_Str {
COMPS_Object_HEAD;
char *val;
};
COMPS_Object_TAIL(COMPS_Str);
COMPS_Object* comps_object_create(COMPS_ObjectInfo *obj_info, COMPS_Object **args);
void comps_object_destroy(COMPS_Object *comps_obj);
void comps_object_destroy_v(void *comps_obj);
COMPS_Object* comps_object_copy(COMPS_Object *comps_obj);
signed char comps_object_cmp(COMPS_Object *obj1, COMPS_Object *obj2);
char comps_object_cmp_v(void *obj1, void *obj2);
char* comps_object_tostr(COMPS_Object *obj1);
COMPS_Object* comps_object_incref(COMPS_Object *obj);
COMPS_Num* comps_num(int n);
COMPS_Str* comps_str(const char *s);
COMPS_Str* comps_str_x(char *s);
void comps_str_set(COMPS_Str *str, char *s);
//extern COMPS_ObjectInfo COMPS_Num_ObjInfo;
//extern COMPS_ObjectInfo COMPS_Str_ObjInfo;
signed char comps_str_fnmatch(COMPS_Str *str, char *pattern, int flags);
signed char comps_str_fnmatch_o(COMPS_Str *str, COMPS_Str *pattern, int flags);
#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