3 #endif /* ifdef HAVE_CONFIG_H */
12 #include "Eet_private.h"
15 eet_dictionary_add(void)
19 new = calloc(1, sizeof (Eet_Dictionary));
23 memset(new->hash, -1, sizeof (int) * 256);
26 } /* eet_dictionary_add */
29 eet_dictionary_free(Eet_Dictionary *ed)
35 for (i = 0; i < ed->count; ++i)
36 if (ed->all[i].allocated)
37 eina_stringshare_del(ed->all[i].str);
42 if (ed->converts) eina_hash_free(ed->converts);
46 } /* eet_dictionary_free */
49 _eet_dictionary_lookup(Eet_Dictionary *ed,
54 Eina_Bool found = EINA_FALSE;
58 current = ed->hash[hash];
62 if (ed->all[current].len == len)
64 if (ed->all[current].str &&
65 (ed->all[current].str == string || strcmp(ed->all[current].str, string) == 0))
73 current = ed->all[current].next;
76 if (current == -1 && found)
80 } /* _eet_dictionary_lookup */
83 eet_dictionary_string_add(Eet_Dictionary *ed,
95 hash = _eet_hash_gen(string, 8);
96 len = strlen(string) + 1;
98 idx = _eet_dictionary_lookup(ed, string, len, hash);
102 if (ed->all[idx].str && (ed->all[idx].str == string || strcmp(ed->all[idx].str, string) == 0))
106 if (ed->total == ed->count)
111 total = ed->total + 8;
113 new = realloc(ed->all, sizeof (Eet_String) * total);
121 str = eina_stringshare_add(string);
125 current = ed->all + ed->count;
127 current->allocated = EINA_TRUE;
129 current->hash = hash;
136 current->next = ed->hash[hash];
138 ed->hash[hash] = ed->count;
143 current->prev = ed->all[idx].prev;
145 if (current->next != -1)
146 ed->all[current->next].prev = ed->count;
148 if (current->prev != -1)
149 ed->all[current->prev].next = ed->count;
151 ed->hash[hash] = ed->count;
155 } /* eet_dictionary_string_add */
158 eet_dictionary_string_get_size(const Eet_Dictionary *ed,
168 return ed->all[idx].len;
171 } /* eet_dictionary_string_get_size */
174 eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
184 return ed->all[idx].hash;
187 } /* eet_dictionary_string_get_hash */
190 eet_dictionary_string_get_char(const Eet_Dictionary *ed,
202 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
203 if (!ed->all[idx].allocated)
205 ed->all[idx].str = strdup(ed->all[idx].str);
206 ed->all[idx].allocated = EINA_TRUE;
208 #endif /* ifdef _WIN32 */
209 return ed->all[idx].str;
213 } /* eet_dictionary_string_get_char */
215 static inline Eina_Bool
216 _eet_dictionary_string_get_me_cache(const char *s,
221 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
223 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
224 *exponent = (s[5] - '0');
230 } /* _eet_dictionary_string_get_me_cache */
232 static inline Eina_Bool
233 _eet_dictionary_string_get_float_cache(const char *s,
240 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
243 *result = (float)(mantisse << exponent);
245 *result = (float)mantisse / (float)(1 << exponent);
251 } /* _eet_dictionary_string_get_float_cache */
253 static inline Eina_Bool
254 _eet_dictionary_string_get_double_cache(const char *s,
261 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
264 *result = (double)(mantisse << exponent);
266 *result = (double)mantisse / (float)(1 << exponent);
272 } /* _eet_dictionary_string_get_double_cache */
274 static inline Eina_Bool
275 _eet_dictionary_test(const Eet_Dictionary *ed,
288 if (!(idx < ed->count))
292 } /* _eet_dictionary_test */
295 eet_dictionary_convert_get(const Eet_Dictionary *ed,
301 *str = ed->all[idx].str;
305 ((Eet_Dictionary*)ed)->converts = eina_hash_int32_new(free);
310 result = eina_hash_find(ed->converts, &idx);
311 if (result) return result;
314 result = calloc(1, sizeof (Eet_Convert));
316 eina_hash_add(ed->converts, &idx, result);
321 eet_dictionary_string_get_float(const Eet_Dictionary *ed,
325 Eet_Convert *convert;
328 if (!_eet_dictionary_test(ed, idx, result))
331 convert = eet_dictionary_convert_get(ed, idx, &str);
332 if (!convert) return EINA_FALSE;
334 if (!(convert->type & EET_D_FLOAT))
336 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
339 long long mantisse = 0;
342 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
343 &exponent) == EINA_FALSE)
346 convert->f = ldexpf((float)mantisse, exponent);
349 convert->type |= EET_D_FLOAT;
352 *result = convert->f;
354 } /* eet_dictionary_string_get_float */
357 eet_dictionary_string_get_double(const Eet_Dictionary *ed,
361 Eet_Convert *convert;
364 if (!_eet_dictionary_test(ed, idx, result))
367 convert = eet_dictionary_convert_get(ed, idx, &str);
368 if (!convert) return EINA_FALSE;
370 if (!(convert->type & EET_D_DOUBLE))
372 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
375 long long mantisse = 0;
378 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
379 &exponent) == EINA_FALSE)
382 convert->d = ldexp((double)mantisse, exponent);
385 convert->type |= EET_D_DOUBLE;
388 *result = convert->d;
390 } /* eet_dictionary_string_get_double */
393 eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
397 Eet_Convert *convert;
400 if (!_eet_dictionary_test(ed, idx, result))
403 convert = eet_dictionary_convert_get(ed, idx, &str);
404 if (!convert) return EINA_FALSE;
406 if (!(convert->type & EET_D_FIXED_POINT))
410 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
414 convert->type |= EET_D_FIXED_POINT;
417 *result = convert->fp;
419 } /* eet_dictionary_string_get_fp */
422 eet_dictionary_string_check(Eet_Dictionary *ed,
427 if ((!ed) || (!string))
430 if ((ed->start <= string) && (string < ed->end))
433 for (i = 0; i < ed->count; ++i)
434 if ((ed->all[i].allocated) && ed->all[i].str == string)
438 } /* eet_dictionary_string_check */