Changes in uspace/srv/net/structures/generic_char_map.h [aadf01e:21580dd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/structures/generic_char_map.h
raadf01e r21580dd 54 54 * @param[in] type Inner object type. 55 55 */ 56 #define GENERIC_CHAR_MAP_DECLARE( name, type) \56 #define GENERIC_CHAR_MAP_DECLARE( name, type ) \ 57 57 \ 58 GENERIC_FIELD_DECLARE( name##_items, type) \58 GENERIC_FIELD_DECLARE( name##_items, type ) \ 59 59 \ 60 60 typedef struct name name##_t; \ … … 62 62 \ 63 63 struct name{ \ 64 char_map_t 65 name##_items_t 66 int 64 char_map_t names; \ 65 name##_items_t values; \ 66 int magic; \ 67 67 }; \ 68 68 \ 69 int name##_add(name##_ref map, const char * name, const size_t length, type * value); \70 int name##_count(name##_ref map); \71 void name##_destroy(name##_ref map);\72 void name##_exclude(name##_ref map, const char * name, const size_t length); \73 type * name##_find(name##_ref map, const char * name, const size_t length);\74 int name##_initialize(name##_ref map);\75 int name##_is_valid(name##_ref map);69 int name##_add( name##_ref map, const char * name, const size_t length, type * value ); \ 70 int name##_count( name##_ref map ); \ 71 void name##_destroy( name##_ref map ); \ 72 void name##_exclude( name##_ref map, const char * name, const size_t length ); \ 73 type * name##_find( name##_ref map, const char * name, const size_t length ); \ 74 int name##_initialize( name##_ref map ); \ 75 int name##_is_valid( name##_ref map ); 76 76 77 77 /** Character string to generic type map implementation. … … 80 80 * @param[in] type Inner object type. 81 81 */ 82 #define GENERIC_CHAR_MAP_IMPLEMENT( name, type)\82 #define GENERIC_CHAR_MAP_IMPLEMENT( name, type ) \ 83 83 \ 84 GENERIC_FIELD_IMPLEMENT( name##_items, type)\84 GENERIC_FIELD_IMPLEMENT( name##_items, type ) \ 85 85 \ 86 int name##_add( name##_ref map, const char * name, const size_t length, type * value){ \86 int name##_add( name##_ref map, const char * name, const size_t length, type * value ){ \ 87 87 ERROR_DECLARE; \ 88 88 \ 89 int 89 int index; \ 90 90 \ 91 if(! name##_is_valid(map)){ \ 92 return EINVAL; \ 93 } \ 94 index = name##_items_add(&map->values, value); \ 95 if(index < 0){ \ 96 return index; \ 97 } \ 98 if(ERROR_OCCURRED(char_map_add(&map->names, name, length, index))){ \ 99 name##_items_exclude_index(&map->values, index); \ 91 if( ! name##_is_valid( map )) return EINVAL; \ 92 index = name##_items_add( & map->values, value ); \ 93 if( index < 0 ) return index; \ 94 if( ERROR_OCCURRED( char_map_add( & map->names, name, length, index ))){ \ 95 name##_items_exclude_index( & map->values, index ); \ 100 96 return ERROR_CODE; \ 101 97 } \ … … 103 99 } \ 104 100 \ 105 int name##_count( name##_ref map){ \106 return name##_is_valid( map) ? name##_items_count(&map->values) : -1;\101 int name##_count( name##_ref map ){ \ 102 return name##_is_valid( map ) ? name##_items_count( & map->values ) : -1; \ 107 103 } \ 108 104 \ 109 void name##_destroy( name##_ref map){ \110 if( name##_is_valid(map)){\111 char_map_destroy( &map->names);\112 name##_items_destroy( &map->values);\105 void name##_destroy( name##_ref map ){ \ 106 if( name##_is_valid( map )){ \ 107 char_map_destroy( & map->names ); \ 108 name##_items_destroy( & map->values ); \ 113 109 } \ 114 110 } \ 115 111 \ 116 void name##_exclude( name##_ref map, const char * name, const size_t length){ \117 if( name##_is_valid(map)){\118 int 112 void name##_exclude( name##_ref map, const char * name, const size_t length ){ \ 113 if( name##_is_valid( map )){ \ 114 int index; \ 119 115 \ 120 index = char_map_exclude( &map->names, name, length); \121 if( index != CHAR_MAP_NULL){\122 name##_items_exclude_index( &map->values, index); \116 index = char_map_exclude( & map->names, name, length ); \ 117 if( index != CHAR_MAP_NULL ){ \ 118 name##_items_exclude_index( & map->values, index ); \ 123 119 } \ 124 120 } \ 125 121 } \ 126 122 \ 127 type * name##_find( name##_ref map, const char * name, const size_t length){\128 if( name##_is_valid(map)){\129 int 123 type * name##_find( name##_ref map, const char * name, const size_t length ){ \ 124 if( name##_is_valid( map )){ \ 125 int index; \ 130 126 \ 131 index = char_map_find( &map->names, name, length);\132 if( index != CHAR_MAP_NULL){\133 return name##_items_get_index( &map->values, index);\127 index = char_map_find( & map->names, name, length ); \ 128 if( index != CHAR_MAP_NULL ){ \ 129 return name##_items_get_index( & map->values, index ); \ 134 130 } \ 135 131 } \ … … 137 133 } \ 138 134 \ 139 int name##_initialize( name##_ref map){\135 int name##_initialize( name##_ref map ){ \ 140 136 ERROR_DECLARE; \ 141 137 \ 142 if(! map){ \ 143 return EINVAL; \ 144 } \ 145 ERROR_PROPAGATE(char_map_initialize(&map->names)); \ 146 if(ERROR_OCCURRED(name##_items_initialize(&map->values))){ \ 147 char_map_destroy(&map->names); \ 138 if( ! map ) return EINVAL; \ 139 ERROR_PROPAGATE( char_map_initialize( & map->names )); \ 140 if( ERROR_OCCURRED( name##_items_initialize( & map->values ))){ \ 141 char_map_destroy( & map->names ); \ 148 142 return ERROR_CODE; \ 149 143 } \ … … 152 146 } \ 153 147 \ 154 int name##_is_valid( name##_ref map){ \155 return map && ( map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE);\148 int name##_is_valid( name##_ref map ){ \ 149 return map && ( map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE ); \ 156 150 } 157 151
Note:
See TracChangeset
for help on using the changeset viewer.