Rev 4576 | Rev 4743 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4576 | Rev 4704 | ||
|---|---|---|---|
| Line 29... | Line 29... | ||
| 29 | /** @addtogroup net |
29 | /** @addtogroup net |
| 30 | * @{ |
30 | * @{ |
| 31 | */ |
31 | */ |
| 32 | 32 | ||
| 33 | /** @file |
33 | /** @file |
| - | 34 | * Integer to generic type map. |
|
| 34 | */ |
35 | */ |
| 35 | 36 | ||
| 36 | #ifndef __NET_INT_MAP_H__ |
37 | #ifndef __NET_INT_MAP_H__ |
| 37 | #define __NET_INT_MAP_H__ |
38 | #define __NET_INT_MAP_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 map consistency check. |
|
| - | 46 | */ |
|
| 44 | #define INT_MAP_MAGIC_VALUE 0x11223344 |
47 | #define INT_MAP_MAGIC_VALUE 0x11223344 |
| - | 48 | ||
| - | 49 | /** Internal magic value for an item consistency check. |
|
| - | 50 | */ |
|
| 45 | #define INT_MAP_ITEM_MAGIC_VALUE 0x55667788 |
51 | #define INT_MAP_ITEM_MAGIC_VALUE 0x55667788 |
| 46 | 52 | ||
| - | 53 | /** Integer to generic type map declaration. |
|
| - | 54 | * @param name Name of the map. Input parameter. |
|
| - | 55 | * @param type Inner object type. Input parameter |
|
| - | 56 | */ |
|
| 47 | #define INT_MAP_DECLARE( name, type ) \ |
57 | #define INT_MAP_DECLARE( name, type ) \ |
| 48 | \ |
58 | \ |
| 49 | typedef struct name name##_t; \ |
59 | typedef struct name name##_t; \ |
| 50 | typedef name##_t * name##_ref; \ |
60 | typedef name##_t * name##_ref; \ |
| 51 | typedef struct name##_item name##_item_t; \ |
61 | typedef struct name##_item name##_item_t; \ |
| Line 75... | Line 85... | ||
| 75 | int name##_initialize( name##_ref map ); \ |
85 | int name##_initialize( name##_ref map ); \ |
| 76 | int name##_is_valid( name##_ref map ); \ |
86 | int name##_is_valid( name##_ref map ); \ |
| 77 | void name##_item_destroy( name##_item_ref item ); \ |
87 | void name##_item_destroy( name##_item_ref item ); \ |
| 78 | int name##_item_is_valid( name##_item_ref item ); |
88 | int name##_item_is_valid( name##_item_ref item ); |
| 79 | 89 | ||
| - | 90 | /** Integer to generic type map implementation. |
|
| - | 91 | * Should follow declaration with the same parameters. |
|
| - | 92 | * @param name Name of the map. Input parameter. |
|
| - | 93 | * @param type Inner object type. Input parameter |
|
| - | 94 | */ |
|
| 80 | #define INT_MAP_IMPLEMENT( name, type ) \ |
95 | #define INT_MAP_IMPLEMENT( name, type ) \ |
| 81 | \ |
96 | \ |
| 82 | int name##_add( name##_ref map, int key, type * value ){ \ |
97 | int name##_add( name##_ref map, int key, type * value ){ \ |
| 83 | if( name##_is_valid( map )){ \ |
98 | if( name##_is_valid( map )){ \ |
| 84 | if( map->next == ( map->size - 1 )){ \ |
99 | if( map->next == ( map->size - 1 )){ \ |