Commit ae5751fe25355bc1ddbc1604bb1d60e6465f1110

Authored by Georg Hopp
1 parent 35d70dd7

<<improve>> class definition

  1 +2011-11-18 00:01:31 +0100 Georg Hopp
  2 +
  3 + * <<improve>> class definition (HEAD, master)
  4 +
  5 +2011-11-17 14:33:33 +0100 Georg Hopp
  6 +
  7 + * Merge branch 'master' of 192.168.10.10:/var/lib/git/token (origin/master, origin/HEAD)
  8 +
  9 +2011-11-17 14:32:08 +0100 Georg Hopp
  10 +
  11 + * add extra dist files to Makefile.am
  12 +
1 13 2011-11-17 14:32:08 +0100 Georg Hopp
2 14
3   - * add extra dist files to Makefile.am (HEAD, origin/master, origin/HEAD, master)
  15 + * add extra dist files to Makefile.am
4 16
5 17 2011-11-17 13:32:46 +0100 Georg Hopp
6 18
... ...
... ... @@ -10,27 +10,27 @@
10 10
11 11
12 12 void
13   -setHashString(struct DYNTYPE_HASH * hash, const char * const key, const char * value)
  13 +setHashString(DYNTYPE_HASH hash, const char * const key, const char * value)
14 14 {
15   - struct DYNTYPE * dyn;
  15 + DYNTYPE dyn;
16 16
17 17 dyn = new(DYNTYPE, DYNTYPE_TYPE_STRING, strlen(value), value);
18 18 dyntype_hash_set(hash, key, dyn);
19 19 }
20 20
21 21 void
22   -setHashInt(struct DYNTYPE_HASH * hash, const char * const key, const int value)
  22 +setHashInt(DYNTYPE_HASH hash, const char * const key, const int value)
23 23 {
24   - struct DYNTYPE * dyn;
  24 + DYNTYPE dyn;
25 25
26 26 dyn = new(DYNTYPE, DYNTYPE_TYPE_INT, sizeof(int), value);
27 27 dyntype_hash_set(hash, key, dyn);
28 28 }
29 29
30 30 void
31   -deleteHashValue(struct DYNTYPE_HASH * hash, const char * const key)
  31 +deleteHashValue(DYNTYPE_HASH hash, const char * const key)
32 32 {
33   - struct DYNTYPE * dyn = dyntype_hash_get(hash, key);
  33 + DYNTYPE dyn = dyntype_hash_get(hash, key);
34 34
35 35 delete(&dyn);
36 36 }
... ... @@ -38,10 +38,11 @@ deleteHashValue(struct DYNTYPE_HASH * hash, const char * const key)
38 38 int
39 39 main(int argc, char * argv[])
40 40 {
41   - struct CRYPT * crypt;
42   - struct PACKET * packet;
43   - struct DYNTYPE_HASH * data;
44   - struct DYNTYPE * _clear;
  41 + CRYPT crypt;
  42 + PACKET packet;
  43 + DYNTYPE_HASH data;
  44 + DYNTYPE _clear;
  45 +
45 46 struct json_object * json;
46 47 const char * json_str;
47 48 char * encrypted;
... ... @@ -49,13 +50,13 @@ main(int argc, char * argv[])
49 50 char pass[] = "1234";
50 51 size_t length;
51 52
52   - packet = new(PACKET);
  53 + packet = new(PACKET, NULL);
53 54
54 55 packet_setHeader(
55 56 packet,
56 57 new(DYNTYPE, DYNTYPE_TYPE_INT, sizeof(int), time(NULL)));
57 58
58   - data = new(DYNTYPE_HASH);
  59 + data = new(DYNTYPE_HASH, NULL);
59 60
60 61 setHashString(data, "#C#", "this comes from C");
61 62 setHashString(data, "usr", "ppohg");
... ... @@ -66,7 +67,7 @@ main(int argc, char * argv[])
66 67 packet,
67 68 new(DYNTYPE,
68 69 DYNTYPE_TYPE_HASH,
69   - sizeof(struct DYNTYPE_HASH *),
  70 + sizeof(DYNTYPE_HASH),
70 71 data));
71 72
72 73 json = toJson(packet);
... ...
... ... @@ -22,17 +22,26 @@
22 22 #include <sys/types.h>
23 23 #include <json/json.h>
24 24
  25 +#define SWAP(a, b) a ^= b; b ^= a; a ^= b;
  26 +
25 27 #define CCLASS_MAGIC 0xFEFE
26 28
27   -#define INIT_CCLASS(name, jsonConst, toJson) \
28   - static const struct CCLASS _##name = { \
  29 +#define CLASS(_class) \
  30 + typedef struct _##_class { \
  31 + const _CCLASS const class;
  32 +
  33 +#define ENDC(_class) } * _class; \
  34 + extern const _CCLASS const __##_class;
  35 +
  36 +#define INIT_CCLASS(class, jsonConst, toJson) \
  37 + static const struct CCLASS _class = { \
29 38 CCLASS_MAGIC, \
30   - sizeof(struct name), \
  39 + sizeof(struct _##class), \
31 40 (ctor)__construct, \
32 41 (jCtor)jsonConst, \
33 42 (dtor)__destruct, \
34 43 (jTo)toJson \
35   - }; const struct CCLASS * const name = &_##name
  44 + }; const _CCLASS const __##class = &_class
36 45
37 46
38 47
... ... @@ -42,23 +51,27 @@ typedef void (* jCtor)(void *, struct json_object *);
42 51 typedef struct json_object * (* jTo)(void *);
43 52
44 53
45   -struct CCLASS {
  54 +typedef struct CCLASS {
46 55 const int magic;
47 56 size_t size;
48 57 void (* __construct)(void * _this, va_list * params);
49 58 void (* __jsonConst)(void * _this, struct json_object * json);
50 59 void (* __destruct)(void * _this);
51 60 struct json_object * (* __toJson)(void * _this);
52   -};
  61 +} * _CCLASS;
53 62 #define CCLASS_PTR_SIZE sizeof(struct CCLASS *)
54 63 #define CCLASS_SIZE sizeof(struct CCLASS)
55 64
56   -void * new(const void * _class, ...);
57   -void * newFromJson(const void * _class, struct json_object * json);
  65 +void * _new(const void * _class, ...);
  66 +void * _newFromJson(const void * _class, struct json_object * json);
58 67 void delete(void * _object);
59 68 struct json_object * toJson(void * _object);
60 69 int isObject(void * _object);
61   -int instanceOf(const void * _class, void * _object);
  70 +int _instanceOf(const void * _class, void * _object);
  71 +
  72 +#define new(class, ...) _new((__##class), __VA_ARGS__)
  73 +#define newFromJson(class, json) _newFromJson((__##class), (json))
  74 +#define instanceOf(class, object) _instanceOf((__##class), (object))
62 75
63 76 #endif//__CCLASS_H__
64 77
... ...
... ... @@ -23,44 +23,32 @@
23 23 #include "token/cclass.h"
24 24
25 25
26   -struct CRYPT {
27   - const struct CCLASS * const class;
  26 +CLASS(CRYPT)
28 27 const char * algorithm;
29 28 const char * mode;
30 29 MCRYPT mcrypt;
31 30 size_t ivsize;
32 31 size_t keysize;
33 32 void * iv;
34   -};
  33 +ENDC(CRYPT)
35 34
36   -extern const struct CCLASS * const CRYPT;
37 35
38 36 void * crypt_encrypt(
39   - struct CRYPT * _this,
  37 + CRYPT _this,
40 38 const void * const data,
41 39 const char * const password,
42 40 size_t * length);
43 41
44 42 void * crypt_decrypt(
45   - struct CRYPT * _this,
  43 + CRYPT _this,
46 44 const void * const data,
47 45 const char * const password,
48 46 size_t * length);
49 47
50   -void * crypt_createIv(
51   - struct CRYPT * _this);
52   -
53   -void crypt_setIv(
54   - struct CRYPT * _this,
55   - const void * const iv);
56   -
57   -void crypt_setIvsize(
58   - struct CRYPT * _this,
59   - const size_t size);
60   -
61   -void crypt_setKeysize(
62   - struct CRYPT * _this,
63   - const size_t size);
  48 +void * crypt_createIv(CRYPT _this);
  49 +void crypt_setIv(CRYPT _this, const void * const iv);
  50 +void crypt_setIvsize(CRYPT _this, const size_t size);
  51 +void crypt_setKeysize(CRYPT _this, const size_t size);
64 52
65 53 #endif//__CRYPT_H__
66 54 // vim: set et ts=4 sw=4:
... ...
... ... @@ -22,7 +22,7 @@
22 22
23 23 #include "token/cclass.h"
24 24
25   -struct DYNTYPE;
  25 +struct _DYNTYPE;
26 26
27 27 #include "token/dyntype/hash.h"
28 28
... ... @@ -38,8 +38,7 @@ enum DYNTYPE_TYPES {
38 38 };
39 39
40 40
41   -struct DYNTYPE {
42   - const struct CCLASS * const class;
  41 +CLASS(DYNTYPE)
43 42 enum DYNTYPE_TYPES type;
44 43 size_t size;
45 44 union _data {
... ... @@ -47,12 +46,10 @@ struct DYNTYPE {
47 46 int _int;
48 47 double _float;
49 48 char * _string;
50   - struct DYNTYPE ** _array;
51   - struct DYNTYPE_HASH * _hash;
  49 + struct _DYNTYPE ** _array;
  50 + DYNTYPE_HASH _hash;
52 51 } data;
53   -};
54   -
55   -extern const struct CCLASS * const DYNTYPE;
  52 +ENDC(DYNTYPE)
56 53
57 54 #endif//__DYNTYPE_H__
58 55
... ...
... ... @@ -24,25 +24,17 @@
24 24 #include "token/dyntype.h"
25 25
26 26
27   -struct DYNTYPE_HASH {
28   - const struct CCLASS * const class;
  27 +CLASS(DYNTYPE_HASH)
29 28 char ** keys;
30   - struct DYNTYPE ** values;
  29 + struct _DYNTYPE ** values;
31 30 size_t size;
32 31 size_t used;
33   -};
  32 +ENDC(DYNTYPE_HASH)
34 33
35   -extern const struct CCLASS * const DYNTYPE_HASH;
36 34
37   -void dyntype_hash_set(struct DYNTYPE_HASH * _this,
38   - const char * key,
39   - struct DYNTYPE * value);
40   -
41   -struct DYNTYPE *
42   -dyntype_hash_get(struct DYNTYPE_HASH * _this, const char * key);
43   -
44   -struct DYNTYPE *
45   -dyntype_hash_del(struct DYNTYPE_HASH * _this, const char * key);
  35 +void dyntype_hash_set(DYNTYPE_HASH _this, const char * key, struct _DYNTYPE * value);
  36 +struct _DYNTYPE * dyntype_hash_get(DYNTYPE_HASH _this, const char * key);
  37 +struct _DYNTYPE * dyntype_hash_del(DYNTYPE_HASH _this, const char * key);
46 38
47 39 #endif//__DYNTYPE_HASH_H__
48 40
... ...
... ... @@ -27,29 +27,17 @@ enum PACKET_CONTENT_KEYS {
27 27 PACKET_DATA
28 28 };
29 29
30   -struct PACKET {
31   - const struct CCLASS * const class;
32   - struct DYNTYPE * content[2];
33   -};
34   -
35   -extern const struct CCLASS * const PACKET;
36   -
37   -struct DYNTYPE * packet_getHeader(
38   - struct PACKET * _this);
39   -
40   -struct DYNTYPE * packet_getData(
41   - struct PACKET * _this);
42 30
43   -void packet_setHeader(
44   - struct PACKET * _this,
45   - struct DYNTYPE * header);
  31 +CLASS(PACKET)
  32 + DYNTYPE content[2];
  33 +ENDC(PACKET)
46 34
47   -void packet_setData(
48   - struct PACKET * _this,
49   - struct DYNTYPE * data);
50 35
51   -void packet_set_default_content(
52   - struct PACKET * _this);
  36 +DYNTYPE packet_getHeader(PACKET _this);
  37 +DYNTYPE packet_getData(PACKET _this);
  38 +void packet_setHeader(PACKET _this, DYNTYPE header);
  39 +void packet_setData(PACKET _this, DYNTYPE data);
  40 +void packet_set_default_content(PACKET _this);
53 41
54 42 #endif//__PACKET_H__
55 43
... ...
... ... @@ -24,10 +24,10 @@
24 24
25 25
26 26 void *
27   -new(const void * _class, ...)
  27 +_new(const void * _class, ...)
28 28 {
29   - const struct CCLASS * class = _class;
30   - void * object = calloc(1, class->size);
  29 + const _CCLASS class = _class;
  30 + void * object = calloc(1, class->size);
31 31
32 32 * (const struct CCLASS **) object = class;
33 33
... ... @@ -43,7 +43,7 @@ new(const void * _class, ...)
43 43 }
44 44
45 45 void *
46   -newFromJson(const void * _class, struct json_object * json)
  46 +_newFromJson(const void * _class, struct json_object * json)
47 47 {
48 48 const struct CCLASS * class = _class;
49 49 void * object = calloc(1, class->size);
... ... @@ -91,7 +91,7 @@ isObject(void * _object)
91 91 }
92 92
93 93 int
94   -instanceOf(const void * _class, void * _object)
  94 +_instanceOf(const void * _class, void * _object)
95 95 {
96 96 const struct CCLASS ** class = _object;
97 97
... ...
... ... @@ -30,7 +30,7 @@
30 30
31 31 static
32 32 void
33   -__construct(struct CRYPT * _this, va_list * params)
  33 +__construct(CRYPT _this, va_list * params)
34 34 {
35 35 _this->algorithm = va_arg(* params, const char * const);
36 36 _this->mode = va_arg(* params, const char * const);
... ... @@ -47,7 +47,7 @@ __construct(struct CRYPT * _this, va_list * params)
47 47
48 48 static
49 49 void
50   -__destruct(struct CRYPT * _this)
  50 +__destruct(CRYPT _this)
51 51 {
52 52 if (_this->iv) {
53 53 free(_this->iv);
... ... @@ -59,7 +59,7 @@ __destruct(struct CRYPT * _this)
59 59 INIT_CCLASS(CRYPT, NULL, NULL);
60 60
61 61 void *
62   -crypt_createIv(struct CRYPT * _this)
  62 +crypt_createIv(CRYPT _this)
63 63 {
64 64 int urandom;
65 65 size_t rsize = 0;
... ... @@ -80,7 +80,7 @@ crypt_createIv(struct CRYPT * _this)
80 80
81 81 static
82 82 void *
83   -createKey(struct CRYPT * _this, const char * const password)
  83 +createKey(CRYPT _this, const char * const password)
84 84 {
85 85 void * key = NULL;
86 86
... ... @@ -102,7 +102,7 @@ createKey(struct CRYPT * _this, const char * const password)
102 102
103 103 void *
104 104 crypt_encrypt(
105   - struct CRYPT * _this,
  105 + CRYPT _this,
106 106 const void * const data,
107 107 const char * const password,
108 108 size_t * length)
... ... @@ -138,7 +138,7 @@ crypt_encrypt(
138 138
139 139 void *
140 140 crypt_decrypt(
141   - struct CRYPT * _this,
  141 + CRYPT _this,
142 142 const void * const data,
143 143 const char * const password,
144 144 size_t * length)
... ...
... ... @@ -26,7 +26,7 @@
26 26
27 27 static
28 28 void
29   -__construct(struct DYNTYPE * _this, va_list * params)
  29 +__construct(DYNTYPE _this, va_list * params)
30 30 {
31 31 _this->type = va_arg(* params, enum DYNTYPE_TYPES);
32 32 _this->size = va_arg(* params, size_t);
... ... @@ -42,7 +42,7 @@ __construct(struct DYNTYPE * _this, va_list * params)
42 42 break;
43 43
44 44 case DYNTYPE_TYPE_HASH:
45   - (_this->data)._hash = va_arg(* params, struct DYNTYPE_HASH *);
  45 + (_this->data)._hash = va_arg(* params, DYNTYPE_HASH);
46 46 break;
47 47
48 48 default:
... ... @@ -52,7 +52,7 @@ __construct(struct DYNTYPE * _this, va_list * params)
52 52
53 53 static
54 54 void
55   -__jsonConst(struct DYNTYPE * _this, struct json_object * json)
  55 +__jsonConst(DYNTYPE _this, struct json_object * json)
56 56 {
57 57 switch (json_object_get_type(json)) {
58 58 case json_type_int:
... ... @@ -75,7 +75,7 @@ __jsonConst(struct DYNTYPE * _this, struct json_object * json)
75 75
76 76 case json_type_object:
77 77 _this->type = DYNTYPE_TYPE_HASH;
78   - _this->size = sizeof(struct DYNTYPE_HASH *);
  78 + _this->size = sizeof(DYNTYPE_HASH);
79 79 (_this->data)._hash = newFromJson(DYNTYPE_HASH, json);
80 80 break;
81 81
... ... @@ -88,7 +88,7 @@ __jsonConst(struct DYNTYPE * _this, struct json_object * json)
88 88
89 89 static
90 90 void
91   -__destruct(struct DYNTYPE * _this)
  91 +__destruct(DYNTYPE _this)
92 92 {
93 93 if (_this) {
94 94 switch(_this->type) {
... ... @@ -108,7 +108,7 @@ __destruct(struct DYNTYPE * _this)
108 108
109 109 static
110 110 struct json_object *
111   -__toJson(struct DYNTYPE * _this)
  111 +__toJson(DYNTYPE _this)
112 112 {
113 113 struct json_object * json = NULL;
114 114
... ...
... ... @@ -27,11 +27,11 @@
27 27 #define HASH_ENTRY_CHUNK_SIZE 128
28 28
29 29
30   -static void _updateHashSize(struct DYNTYPE_HASH * _this);
  30 +static void _updateHashSize(DYNTYPE_HASH _this);
31 31
32 32 static
33 33 void
34   -__construct(struct DYNTYPE_HASH * _this, va_list * params)
  34 +__construct(DYNTYPE_HASH _this, va_list * params)
35 35 {
36 36 _this->size = 0;
37 37 _this->used = 0;
... ... @@ -40,7 +40,7 @@ __construct(struct DYNTYPE_HASH * _this, va_list * params)
40 40
41 41 static
42 42 void
43   -__jsonConst(struct DYNTYPE_HASH * _this, struct json_object * json)
  43 +__jsonConst(DYNTYPE_HASH _this, struct json_object * json)
44 44 {
45 45 __construct(_this, NULL);
46 46
... ... @@ -55,7 +55,7 @@ __jsonConst(struct DYNTYPE_HASH * _this, struct json_object * json)
55 55
56 56 static
57 57 void
58   -__destruct(struct DYNTYPE_HASH * _this)
  58 +__destruct(DYNTYPE_HASH _this)
59 59 {
60 60 size_t index;
61 61
... ... @@ -69,7 +69,7 @@ __destruct(struct DYNTYPE_HASH * _this)
69 69
70 70 static
71 71 struct json_object *
72   -__toJson(struct DYNTYPE_HASH * _this)
  72 +__toJson(DYNTYPE_HASH _this)
73 73 {
74 74 size_t index;
75 75 struct json_object * json = json_object_new_object();
... ... @@ -88,7 +88,7 @@ INIT_CCLASS(DYNTYPE_HASH, __jsonConst, __toJson);
88 88
89 89 static
90 90 void
91   -_updateHashSize(struct DYNTYPE_HASH * _this)
  91 +_updateHashSize(DYNTYPE_HASH _this)
92 92 {
93 93 if (_this->used == _this->size) {
94 94 _this->size += HASH_ENTRY_CHUNK_SIZE;
... ... @@ -100,16 +100,16 @@ _updateHashSize(struct DYNTYPE_HASH * _this)
100 100
101 101 _this->values = realloc(
102 102 _this->values,
103   - sizeof(struct DYNTYPE *) * _this->size);
104   - memset(_this->values + (_this->used * sizeof(struct DYNTYPE *)),
  103 + sizeof(DYNTYPE) * _this->size);
  104 + memset(_this->values + (_this->used * sizeof(DYNTYPE)),
105 105 0,
106   - HASH_ENTRY_CHUNK_SIZE * sizeof(struct DYNTYPE *));
  106 + HASH_ENTRY_CHUNK_SIZE * sizeof(DYNTYPE));
107 107 }
108 108 }
109 109
110 110 static
111 111 size_t
112   -_getHashIdx(struct DYNTYPE_HASH * _this, const char * key)
  112 +_getHashIdx(DYNTYPE_HASH _this, const char * key)
113 113 {
114 114 size_t index;
115 115
... ... @@ -121,9 +121,7 @@ _getHashIdx(struct DYNTYPE_HASH * _this, const char * key)
121 121 }
122 122
123 123 void
124   -dyntype_hash_set(struct DYNTYPE_HASH * _this,
125   - const char * key,
126   - struct DYNTYPE * value)
  124 +dyntype_hash_set(DYNTYPE_HASH _this, const char * key, DYNTYPE value)
127 125 {
128 126 size_t index = _getHashIdx(_this, key);
129 127
... ... @@ -139,8 +137,7 @@ dyntype_hash_set(struct DYNTYPE_HASH * _this,
139 137 _updateHashSize(_this);
140 138 }
141 139
142   -struct DYNTYPE *
143   -dyntype_hash_get(struct DYNTYPE_HASH * _this, const char * key)
  140 +DYNTYPE dyntype_hash_get(DYNTYPE_HASH _this, const char * key)
144 141 {
145 142 size_t index = _getHashIdx(_this, key);
146 143
... ... @@ -151,10 +148,9 @@ dyntype_hash_get(struct DYNTYPE_HASH * _this, const char * key)
151 148 return _this->values[index];
152 149 }
153 150
154   -struct DYNTYPE *
155   -dyntype_hash_del(struct DYNTYPE_HASH * _this, const char * key)
  151 +DYNTYPE dyntype_hash_del(DYNTYPE_HASH _this, const char * key)
156 152 {
157   - struct DYNTYPE * found = NULL;
  153 + DYNTYPE found = NULL;
158 154 size_t index = _getHashIdx(_this, key);
159 155
160 156 if (index == _this->used) {
... ... @@ -169,7 +165,7 @@ dyntype_hash_del(struct DYNTYPE_HASH * _this, const char * key)
169 165
170 166 memmove(_this->values + index + 1,
171 167 _this->values + index,
172   - (_this->size - index) * sizeof(struct DYNTYPE *));
  168 + (_this->size - index) * sizeof(DYNTYPE));
173 169
174 170 _this->used -= 1;
175 171 }
... ...
... ... @@ -22,14 +22,14 @@
22 22
23 23 static
24 24 void
25   -__construct(struct PACKET * _this, va_list * params)
  25 +__construct(PACKET _this, va_list * params)
26 26 {
27 27 packet_set_default_content(_this);
28 28 }
29 29
30 30 static
31 31 void
32   -__jsonConst(struct PACKET * _this, struct json_object * json)
  32 +__jsonConst(PACKET _this, struct json_object * json)
33 33 {
34 34 struct json_object * header = NULL;
35 35 struct json_object * data = NULL;
... ... @@ -53,13 +53,13 @@ __jsonConst(struct PACKET * _this, struct json_object * json)
53 53
54 54 static
55 55 void
56   -__destruct(struct PACKET * _this)
  56 +__destruct(PACKET _this)
57 57 {
58 58 }
59 59
60 60 static
61 61 struct json_object *
62   -__toJson(struct PACKET * _this)
  62 +__toJson(PACKET _this)
63 63 {
64 64 struct json_object * json = json_object_new_array();
65 65
... ... @@ -71,36 +71,30 @@ __toJson(struct PACKET * _this)
71 71
72 72 INIT_CCLASS(PACKET, __jsonConst, __toJson);
73 73
74   -struct DYNTYPE *
75   -packet_getHeader(struct PACKET * _this)
  74 +DYNTYPE packet_getHeader(PACKET _this)
76 75 {
77 76 return _this->content[PACKET_HEADER];
78 77 }
79 78
80   -struct DYNTYPE *
81   -packet_getData(struct PACKET * _this)
  79 +DYNTYPE packet_getData(PACKET _this)
82 80 {
83 81 return _this->content[PACKET_DATA];
84 82 }
85 83
86 84 void
87   -packet_setHeader(
88   - struct PACKET * _this,
89   - struct DYNTYPE * header)
  85 +packet_setHeader(PACKET _this, DYNTYPE header)
90 86 {
91 87 _this->content[PACKET_HEADER] = header;
92 88 }
93 89
94 90 void
95   -packet_setData(
96   - struct PACKET * _this,
97   - struct DYNTYPE * data)
  91 +packet_setData(PACKET _this, DYNTYPE data)
98 92 {
99 93 _this->content[PACKET_DATA] = data;
100 94 }
101 95
102 96 void
103   -packet_set_default_content(struct PACKET * _this)
  97 +packet_set_default_content(PACKET _this)
104 98 {
105 99 _this->content[PACKET_HEADER] = NULL;
106 100 _this->content[PACKET_DATA] = NULL;
... ...
... ... @@ -7,7 +7,7 @@
7 7
8 8 const char testname[] = "cclassTest";
9 9
10   -struct MOCK_CLASS * mock = NULL;
  10 +MOCK_CLASS mock = NULL;
11 11
12 12 static
13 13 int
... ...
... ... @@ -12,7 +12,7 @@
12 12
13 13
14 14 const char testname[] = "cryptTest";
15   -struct CRYPT * crypt = NULL;
  15 +CRYPT crypt = NULL;
16 16
17 17
18 18 static
... ...
... ... @@ -15,7 +15,7 @@ _reset()
15 15
16 16 static
17 17 void
18   -__construct(struct MOCK_CLASS * _this, va_list * params)
  18 +__construct(MOCK_CLASS _this, va_list * params)
19 19 {
20 20 _called = 1;
21 21 _this->value = va_arg(* params, int);
... ... @@ -23,7 +23,7 @@ __construct(struct MOCK_CLASS * _this, va_list * params)
23 23
24 24 static
25 25 void
26   -__jsonConst(struct MOCK_CLASS * _this, json_object * json)
  26 +__jsonConst(MOCK_CLASS _this, json_object * json)
27 27 {
28 28 _called = 1;
29 29 assert(json_type_int == json_object_get_type(json));
... ... @@ -33,14 +33,14 @@ __jsonConst(struct MOCK_CLASS * _this, json_object * json)
33 33
34 34 static
35 35 void
36   -__destruct(struct MOCK_CLASS * _this)
  36 +__destruct(MOCK_CLASS _this)
37 37 {
38 38 _called = 1;
39 39 }
40 40
41 41 static
42 42 struct json_object *
43   -__toJson(struct MOCK_CLASS * _this)
  43 +__toJson(MOCK_CLASS _this)
44 44 {
45 45 struct json_object * json = json_object_new_int(_this->value);
46 46
... ... @@ -55,13 +55,13 @@ INIT_CCLASS(MOCK_CLASS, __jsonConst, __toJson);
55 55 */
56 56
57 57 int
58   -mock_class_getValue(struct MOCK_CLASS * _this)
  58 +mock_class_getValue(MOCK_CLASS _this)
59 59 {
60 60 return _this->value;
61 61 }
62 62
63 63 void
64   -mock_class_setValue(struct MOCK_CLASS * _this, int value)
  64 +mock_class_setValue(MOCK_CLASS _this, int value)
65 65 {
66 66 _this->value = value;
67 67 }
... ...
... ... @@ -8,19 +8,18 @@ extern char _called;
8 8
9 9 extern void inline _reset();
10 10
11   -struct MOCK_CLASS {
12   - const struct CCLASS * const class;
  11 +CLASS(MOCK_CLASS)
13 12 int value;
14   -};
  13 +ENDC(MOCK_CLASS)
15 14
16   -extern const struct CCLASS * const MOCK_CLASS;
  15 +extern const _CCLASS const __MOCK_CLASS;
17 16
18 17 /**
19 18 * ~~~ method declarations ~~~~~~~~
20 19 */
21 20
22   -int mock_class_getValue(struct MOCK_CLASS * _this);
23   -void mock_class_setValue(struct MOCK_CLASS * _this, int value);
  21 +int mock_class_getValue(MOCK_CLASS _this);
  22 +void mock_class_setValue(MOCK_CLASS _this, int value);
24 23
25 24 #endif//__MOCK_CLASS_H__
26 25 // vim: set et ts=4 sw=4:
... ...
... ... @@ -11,27 +11,27 @@
11 11
12 12
13 13 void
14   -setHashString(struct DYNTYPE_HASH * hash, const char * const key, const char * value)
  14 +setHashString(DYNTYPE_HASH hash, const char * const key, const char * value)
15 15 {
16   - struct DYNTYPE * dyn;
  16 + DYNTYPE dyn;
17 17
18 18 dyn = new(DYNTYPE, DYNTYPE_TYPE_STRING, strlen(value), value);
19 19 dyntype_hash_set(hash, key, dyn);
20 20 }
21 21
22 22 void
23   -setHashInt(struct DYNTYPE_HASH * hash, const char * const key, const int value)
  23 +setHashInt(DYNTYPE_HASH hash, const char * const key, const int value)
24 24 {
25   - struct DYNTYPE * dyn;
  25 + DYNTYPE dyn;
26 26
27 27 dyn = new(DYNTYPE, DYNTYPE_TYPE_INT, sizeof(int), value);
28 28 dyntype_hash_set(hash, key, dyn);
29 29 }
30 30
31 31 void
32   -deleteHashValue(struct DYNTYPE_HASH * hash, const char * const key)
  32 +deleteHashValue(DYNTYPE_HASH hash, const char * const key)
33 33 {
34   - struct DYNTYPE * dyn = dyntype_hash_get(hash, key);
  34 + DYNTYPE dyn = dyntype_hash_get(hash, key);
35 35
36 36 delete(&dyn);
37 37 }
... ... @@ -39,19 +39,20 @@ deleteHashValue(struct DYNTYPE_HASH * hash, const char * const key)
39 39 int
40 40 main(int argc, char * argv[])
41 41 {
42   - struct PACKET * packet;
43   - struct DYNTYPE_HASH * data;
44   - struct DYNTYPE * _clear;
  42 + PACKET packet;
  43 + DYNTYPE_HASH data;
  44 + DYNTYPE _clear;
  45 +
45 46 struct json_object * json;
46 47 char * json_str;
47 48
48   - packet = new(PACKET);
  49 + packet = new(PACKET, NULL);
49 50
50 51 packet_setHeader(
51 52 packet,
52 53 new(DYNTYPE, DYNTYPE_TYPE_INT, sizeof(int), time(NULL)));
53 54
54   - data = new(DYNTYPE_HASH);
  55 + data = new(DYNTYPE_HASH, NULL);
55 56
56 57 setHashString(data, "#C#", "this comes from C");
57 58 setHashString(data, "usr", "ppohg");
... ...
... ... @@ -12,7 +12,7 @@ static
12 12 int
13 13 __setUp()
14 14 {
15   - packet = new(PACKET);
  15 + packet = new(PACKET, NULL);
16 16
17 17 ASSERT_INSTANCE_OF(PACKET, packet);
18 18 return TEST_OK;
... ...
... ... @@ -30,7 +30,7 @@ enum RESULT_TYPES {
30 30 #define ASSERT_OBJECT_NULL(val) if (! isObjectNull((val))) return TEST_FAILED
31 31 #define ASSERT_OBJECT_NOT_NULL(val) if (isObjectNull((val))) return TEST_FAILED
32 32 #define ASSERT_INSTANCE_OF(class, val) \
33   - if (! instanceOf((class), (val))) return TEST_FAILED
  33 + if (! instanceOf(class, val)) return TEST_FAILED
34 34
35 35
36 36 typedef int (* const testfunc)(void);
... ...
Please register or login to post a comment