Changeset 71b00dcc in mainline for uspace/srv/net/structures/generic_char_map.h
- Timestamp:
- 2010-03-07T22:51:38Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 60ab6c3
- Parents:
- b5cbff4 (diff), 31c80a5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/structures/generic_char_map.h
rb5cbff4 r71b00dcc 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 )) 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 ); \ 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); \ 96 100 return ERROR_CODE; \ 97 101 } \ … … 99 103 } \ 100 104 \ 101 int name##_count( name##_ref map){ \102 return name##_is_valid( map ) ? name##_items_count( & map->values ) : -1;\105 int name##_count(name##_ref map){ \ 106 return name##_is_valid(map) ? name##_items_count(&map->values) : -1; \ 103 107 } \ 104 108 \ 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 );\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); \ 109 113 } \ 110 114 } \ 111 115 \ 112 void name##_exclude( name##_ref map, const char * name, const size_t length){ \113 if( name##_is_valid( map )){\114 int 116 void name##_exclude(name##_ref map, const char * name, const size_t length){ \ 117 if(name##_is_valid(map)){ \ 118 int index; \ 115 119 \ 116 index = char_map_exclude( & map->names, name, length); \117 if( index != CHAR_MAP_NULL ){\118 name##_items_exclude_index( & map->values, index); \120 index = char_map_exclude(&map->names, name, length); \ 121 if(index != CHAR_MAP_NULL){ \ 122 name##_items_exclude_index(&map->values, index); \ 119 123 } \ 120 124 } \ 121 125 } \ 122 126 \ 123 type * name##_find( name##_ref map, const char * name, const size_t length ){\124 if( name##_is_valid( map )){\125 int 127 type * name##_find(name##_ref map, const char * name, const size_t length){ \ 128 if(name##_is_valid(map)){ \ 129 int index; \ 126 130 \ 127 index = char_map_find( & map->names, name, length );\128 if( index != CHAR_MAP_NULL ){\129 return name##_items_get_index( & map->values, index );\131 index = char_map_find(&map->names, name, length); \ 132 if(index != CHAR_MAP_NULL){ \ 133 return name##_items_get_index(&map->values, index); \ 130 134 } \ 131 135 } \ … … 133 137 } \ 134 138 \ 135 int name##_initialize( name##_ref map ){\139 int name##_initialize(name##_ref map){ \ 136 140 ERROR_DECLARE; \ 137 141 \ 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 ); \ 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); \ 142 148 return ERROR_CODE; \ 143 149 } \ … … 146 152 } \ 147 153 \ 148 int name##_is_valid( name##_ref map){ \149 return map && ( map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE );\154 int name##_is_valid(name##_ref map){ \ 155 return map && (map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE); \ 150 156 } 151 157
Note:
See TracChangeset
for help on using the changeset viewer.