2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
16 #include "Eet_private.h"
19 eet_dictionary_add(void)
23 new = calloc(1, sizeof (Eet_Dictionary));
27 memset(new->hash, -1, sizeof (int) * 256);
33 eet_dictionary_free(Eet_Dictionary *ed)
39 for (i = 0; i < ed->count; ++i)
42 if (ed->all) free(ed->all);
48 _eet_dictionary_lookup(Eet_Dictionary *ed, const char *string, int hash)
53 current = ed->hash[hash];
57 if (ed->all[current].str)
59 if (strcmp(ed->all[current].str, string) >= 0)
62 if (ed->all[current].mmap)
64 if (strcmp(ed->all[current].mmap, string) >= 0)
69 current = ed->all[current].next;
79 eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
90 hash = _eet_hash_gen(string, 8);
92 idx = _eet_dictionary_lookup(ed, string, hash);
98 if (strcmp(ed->all[idx].str, string) == 0)
101 if (ed->all[idx].mmap)
103 if (strcmp(ed->all[idx].mmap, string) == 0)
108 if (ed->total == ed->count)
113 total = ed->total + 8;
115 new = realloc(ed->all, sizeof (Eet_String) * total);
123 len = strlen(string) + 1;
124 str = strdup(string);
128 current = ed->all + ed->count;
130 current->type = EET_D_NOT_CONVERTED;
132 current->hash = hash;
136 current->mmap = NULL;
140 current->next = ed->hash[hash];
142 ed->hash[hash] = ed->count;
147 current->prev = ed->all[idx].prev;
149 if (current->next != -1)
150 ed->all[current->next].prev = ed->count;
151 if (current->prev != -1)
152 ed->all[current->prev].next = ed->count;
154 ed->hash[hash] = ed->count;
161 eet_dictionary_string_get_size(const Eet_Dictionary *ed, int idx)
164 if (idx < 0) return 0;
166 return ed->all[idx].len;
171 eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx)
174 if (idx < 0) return -1;
176 return ed->all[idx].hash;
181 eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx)
183 if (!ed) return NULL;
184 if (idx < 0) return NULL;
188 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
189 if (ed->all[idx].str == NULL)
191 ed->all[idx].str = strdup(ed->all[idx].mmap);
192 ed->all[idx].mmap = NULL;
195 if (ed->all[idx].mmap)
196 return ed->all[idx].mmap;
198 return ed->all[idx].str;
203 static inline Eina_Bool
204 _eet_dictionary_string_get_me_cache(const char *s, int len, int *mantisse, int *exponent)
206 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
208 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
209 *exponent = (s[5] - '0');
216 static inline Eina_Bool
217 _eet_dictionary_string_get_float_cache(const char *s, int len, float *result)
222 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
224 if (s[4] == '+') *result = (float) (mantisse << exponent);
225 else *result = (float) mantisse / (float) (1 << exponent);
232 static inline Eina_Bool
233 _eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
238 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
240 if (s[4] == '+') *result = (double) (mantisse << exponent);
241 else *result = (double) mantisse / (float) (1 << exponent);
248 static inline Eina_Bool
249 _eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result)
251 if (!result) return EINA_FALSE;
252 if (!ed) return EINA_FALSE;
253 if (idx < 0) return EINA_FALSE;
254 if (!(idx < ed->count)) return EINA_FALSE;
259 eet_dictionary_string_get_float(const Eet_Dictionary *ed, int idx, float *result)
261 if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE;
263 if (!(ed->all[idx].type & EET_D_FLOAT))
267 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
269 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len, &ed->all[idx].f))
271 long long mantisse = 0;
274 if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE)
277 ed->all[idx].f = ldexpf((float) mantisse, exponent);
280 ed->all[idx].type |= EET_D_FLOAT;
283 *result = ed->all[idx].f;
288 eet_dictionary_string_get_double(const Eet_Dictionary *ed, int idx, double *result)
290 if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE;
292 if (!(ed->all[idx].type & EET_D_DOUBLE))
296 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
298 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len, &ed->all[idx].d))
300 long long mantisse = 0;
303 if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE)
306 ed->all[idx].d = ldexp((double) mantisse, exponent);
309 ed->all[idx].type |= EET_D_DOUBLE;
312 *result = ed->all[idx].d;
317 eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int idx, Eina_F32p32 *result)
319 if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE;
321 if (!(ed->all[idx].type & EET_D_FIXED_POINT))
326 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
328 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
331 ed->all[idx].fp = fp;
332 ed->all[idx].type |= EET_D_FIXED_POINT;
335 *result = ed->all[idx].fp;
340 eet_dictionary_string_check(Eet_Dictionary *ed, const char *string)
348 if (ed->start <= string
352 for (i = 0; i < ed->count; ++i)
353 if (ed->all[i].str == string)