Overview
Comment: | cfw_new() takes parameters now. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
db15fc9166bbce80635eb0663ac7a6f2 |
User & Date: | js on 2012-04-08 17:32:57 |
Other Links: | manifest | tags |
Context
2012-04-08
| ||
17:50 | Add a buildsys. check-in: 839e11b5aa user: js tags: trunk | |
17:32 | cfw_new() takes parameters now. check-in: db15fc9166 user: js tags: trunk | |
17:24 | Initial import. check-in: 2605e9af3f user: js tags: trunk | |
Changes
Modified cfwarray.c from [1e8350aa19] to [8f48f16d9c].
︙ | ︙ | |||
31 32 33 34 35 36 37 | struct CFWArray { CFWObject obj; void **data; size_t size; }; | | | > > > > > > > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | struct CFWArray { CFWObject obj; void **data; size_t size; }; static bool ctor(void *ptr, va_list args) { CFWArray *array = ptr; void *obj; array->data = NULL; array->size = 0; while ((obj = va_arg(args, void*)) != NULL) if (!cfw_array_push(array, obj)) return false; return true; } static void dtor(void *ptr) { CFWArray *array = ptr; size_t i; |
︙ | ︙ |
Modified cfwclass.h from [42f745b6ab] to [c2d2546790].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 | */ #ifndef __CFWCLASS_H__ #define __CFWCLASS_H__ #include <stddef.h> #include <stdbool.h> typedef struct CFWClass { const char *name; size_t size; | > | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | */ #ifndef __CFWCLASS_H__ #define __CFWCLASS_H__ #include <stddef.h> #include <stdbool.h> #include <stdarg.h> typedef struct CFWClass { const char *name; size_t size; bool (*ctor)(void*, va_list args); void (*dtor)(void*); bool (*equal)(void*, void*); void* (*copy)(void*); } CFWClass; #endif |
Modified cfwobject.c from [ef5d30a523] to [36ac9401ba].
︙ | ︙ | |||
25 26 27 28 29 30 31 | */ #include <stdlib.h> #include "cfwobject.h" void* | | | > > > | > > > > > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | */ #include <stdlib.h> #include "cfwobject.h" void* cfw_new(CFWClass *class, ...) { CFWObject *obj; if ((obj = malloc(class->size)) == NULL) return NULL; obj->clsptr = class; obj->ref_cnt = 1; if (class->ctor != NULL) { va_list args; va_start(args, class); if (!class->ctor(obj, args)) { cfw_unref(obj); return NULL; } va_end(args); } return obj; } void* cfw_ref(void *ptr) { |
︙ | ︙ |
Modified cfwobject.h from [10cb4305fe] to [3af61b6ce2].
︙ | ︙ | |||
31 32 33 34 35 36 37 | typedef struct CFWObject { CFWClass *clsptr; int ref_cnt; } CFWObject; extern CFWClass *cfw_object; | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | typedef struct CFWObject { CFWClass *clsptr; int ref_cnt; } CFWObject; extern CFWClass *cfw_object; extern void* cfw_new(CFWClass*, ...); extern void* cfw_ref(void*); extern void cfw_unref(void*); extern void cfw_free(void*); extern bool cfw_equal(void*, void*); extern void* cfw_copy(void*); #endif |
Modified cfwstring.c from [0aece0c266] to [51f2e1e12f].
︙ | ︙ | |||
32 33 34 35 36 37 38 | struct CFWString { CFWObject obj; char *cstr; size_t len; }; | | | > > > > > > > | | > > > | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | struct CFWString { CFWObject obj; char *cstr; size_t len; }; static bool ctor(void *ptr, va_list args) { CFWString *str = ptr; const char *cstr = va_arg(args, const char*); if (cstr != NULL) { if ((str->cstr = strdup(cstr)) == NULL) return false; str->len = strlen(cstr); } else { str->cstr = NULL; str->len = 0; } return true; } static void dtor(void *ptr) { CFWString *str = ptr; |
︙ | ︙ |
Modified test.c from [2072f0950c] to [c532ff05d3].
︙ | ︙ | |||
29 30 31 32 33 34 35 36 | #include "cfwobject.h" #include "cfwstring.h" #include "cfwarray.h" int main() { CFWArray *a; | > < | < < | < < < < < < < < < | < | | < < < | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include "cfwobject.h" #include "cfwstring.h" #include "cfwarray.h" int main() { CFWString *s[3]; CFWArray *a; size_t i; s[0] = cfw_new(cfw_string, "Hallo"); s[1] = cfw_new(cfw_string, "Welt"); s[2] = cfw_new(cfw_string, "!"); a = cfw_new(cfw_array, s[0], s[1], s[2], NULL); for (i = 0; i < cfw_array_size(a); i++) puts(cfw_string_c(cfw_array_get(a, i))); return 0; } |