00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __SIMPLE_MAP_H__
00026 #define __SIMPLE_MAP_H__
00027
00028 #if defined(_WIN32) || defined(__declspec)
00029
00030 #ifdef COMPILE_DLL
00031 #define STORAGE_TYPE __declspec(dllexport)
00032 #else // COMPILE_DLL
00033 #define STORAGE_TYPE __declspec(dllimport)
00034 #endif // COMPILE_DLL
00035
00036 #else
00037 #define STORAGE_TYPE extern
00038 #endif // _WIN32 || __declspec
00039
00040
00041
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045
00052 typedef struct _simple_map_el {
00053 void *value;
00054 char *key;
00055 struct _simple_map_el *next;
00056
00057 } SimpleMapEl;
00058
00060 typedef void (*MapDestructor) (void*);
00061 typedef unsigned int (*MapHashFunc) (char *);
00062 typedef int (*MapCompareFunc) (char *, char *);
00063 typedef char *(*MapCopyFunc) (char *);
00064 typedef void (*MapFreeFunc)(char *);
00065
00066
00067 typedef struct {
00068 MapHashFunc hash_element;
00069 MapCompareFunc compare_elements;
00070 MapCopyFunc copy_element;
00071 MapFreeFunc free_element;
00072
00073 } MapTypeInfo;
00074
00075
00076
00079 typedef struct {
00080
00081 int size;
00082 struct _simple_map_el **table;
00083 MapDestructor free_element;
00084 MapTypeInfo type;
00085
00086 } SimpleMap;
00087
00089 typedef int (*MapIterator) (SimpleMap *map, char *key, void *value, void *data);
00090
00091
00094 STORAGE_TYPE SimpleMap* map_new();
00095
00096
00099 STORAGE_TYPE SimpleMap* map_new_with_destructor(MapDestructor destructor);
00100
00103 STORAGE_TYPE SimpleMap* map_new_configured(int size, MapDestructor destructor);
00104
00107 STORAGE_TYPE SimpleMap* map_new_configured_full(int size, MapDestructor destructor,
00108 MapTypeInfo *pInfo);
00109
00110
00113 STORAGE_TYPE void map_set(SimpleMap *map, char *key, void *value );
00114
00117 STORAGE_TYPE void map_remove(SimpleMap *map, char *key);
00118
00119
00124 STORAGE_TYPE int map_foreach(SimpleMap *map, MapIterator iterator, void *data);
00125
00128 STORAGE_TYPE void *map_get(SimpleMap *map, char *key);
00129
00131 STORAGE_TYPE int map_has_key(SimpleMap *map, char *key);
00132
00133
00136 STORAGE_TYPE void* map_get_element( SimpleMap*, char* key );
00137
00140 STORAGE_TYPE void map_free(SimpleMap *map);
00141
00142
00145 STORAGE_TYPE SimpleMap *map_copy(SimpleMap *map);
00146
00147
00148 #ifdef __cplusplus
00149 }
00150 #endif
00151
00152 #endif