Rev 4243 | Rev 4743 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4243 | Rev 4704 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | /** @addtogroup net |
29 | /** @addtogroup net |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
- | 34 | * Generic type field. |
|
34 | */ |
35 | */ |
35 | 36 | ||
36 | #ifndef __GENERIC_FIELD_H__ |
37 | #ifndef __GENERIC_FIELD_H__ |
37 | #define __GENERIC_FIELD_H__ |
38 | #define __GENERIC_FIELD_H__ |
38 | 39 | ||
39 | #include <errno.h> |
40 | #include <errno.h> |
40 | #include <malloc.h> |
41 | #include <malloc.h> |
41 | #include <mem.h> |
42 | #include <mem.h> |
42 | #include <unistd.h> |
43 | #include <unistd.h> |
43 | 44 | ||
- | 45 | /** Internal magic value for a field consistency check. |
|
- | 46 | */ |
|
44 | #define GENERIC_FIELD_MAGIC_VALUE 0x55667788 |
47 | #define GENERIC_FIELD_MAGIC_VALUE 0x55667788 |
45 | 48 | ||
- | 49 | /** Generic type field declaration. |
|
- | 50 | * @param name Name of the field. Input parameter. |
|
- | 51 | * @param type Inner object type. Input parameter |
|
- | 52 | */ |
|
46 | #define GENERIC_FIELD_DECLARE( name, type ) \ |
53 | #define GENERIC_FIELD_DECLARE( name, type ) \ |
47 | \ |
54 | \ |
48 | typedef struct name name##_t; \ |
55 | typedef struct name name##_t; \ |
49 | typedef name##_t * name##_ref; \ |
56 | typedef name##_t * name##_ref; \ |
50 | \ |
57 | \ |
Line 62... | Line 69... | ||
62 | type ** name##_get_field( name##_ref field ); \ |
69 | type ** name##_get_field( name##_ref field ); \ |
63 | type * name##_get_index( name##_ref field, int index ); \ |
70 | type * name##_get_index( name##_ref field, int index ); \ |
64 | int name##_initialize( name##_ref field ); \ |
71 | int name##_initialize( name##_ref field ); \ |
65 | int name##_is_valid( name##_ref field ); |
72 | int name##_is_valid( name##_ref field ); |
66 | 73 | ||
- | 74 | /** Generic type field implementation. |
|
- | 75 | * Should follow declaration with the same parameters. |
|
- | 76 | * @param name Name of the field. Input parameter. |
|
- | 77 | * @param type Inner object type. Input parameter |
|
- | 78 | */ |
|
67 | #define GENERIC_FIELD_IMPLEMENT( name, type ) \ |
79 | #define GENERIC_FIELD_IMPLEMENT( name, type ) \ |
68 | \ |
80 | \ |
69 | int name##_add( name##_ref field, type * value ){ \ |
81 | int name##_add( name##_ref field, type * value ){ \ |
70 | if( name##_is_valid( field )){ \ |
82 | if( name##_is_valid( field )){ \ |
71 | if( field->next == ( field->size - 1 )){ \ |
83 | if( field->next == ( field->size - 1 )){ \ |