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)
44 } /* eet_dictionary_free */
47 _eet_dictionary_lookup(Eet_Dictionary *ed,
52 Eina_Bool found = EINA_FALSE;
56 current = ed->hash[hash];
60 if (ed->all[current].len == len)
62 if (ed->all[current].str)
63 if (strcmp(ed->all[current].str, string) == 0)
69 if (ed->all[current].mmap)
70 if (strcmp(ed->all[current].mmap, string) == 0)
78 current = ed->all[current].next;
81 if (current == -1 && found)
85 } /* _eet_dictionary_lookup */
88 eet_dictionary_string_add(Eet_Dictionary *ed,
100 hash = _eet_hash_gen(string, 8);
101 len = strlen(string) + 1;
103 idx = _eet_dictionary_lookup(ed, string, len, hash);
107 if (ed->all[idx].str)
108 if (strcmp(ed->all[idx].str, string) == 0)
111 if (ed->all[idx].mmap)
112 if (strcmp(ed->all[idx].mmap, string) == 0)
117 if (ed->total == ed->count)
122 total = ed->total + 8;
124 new = realloc(ed->all, sizeof (Eet_String) * total);
132 str = strdup(string);
136 current = ed->all + ed->count;
138 current->type = EET_D_NOT_CONVERTED;
140 current->hash = hash;
144 current->mmap = NULL;
148 current->next = ed->hash[hash];
150 ed->hash[hash] = ed->count;
155 current->prev = ed->all[idx].prev;
157 if (current->next != -1)
158 ed->all[current->next].prev = ed->count;
160 if (current->prev != -1)
161 ed->all[current->prev].next = ed->count;
163 ed->hash[hash] = ed->count;
167 } /* eet_dictionary_string_add */
170 eet_dictionary_string_get_size(const Eet_Dictionary *ed,
180 return ed->all[idx].len;
183 } /* eet_dictionary_string_get_size */
186 eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
196 return ed->all[idx].hash;
199 } /* eet_dictionary_string_get_hash */
202 eet_dictionary_string_get_char(const Eet_Dictionary *ed,
214 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
215 if (!ed->all[idx].str)
217 ed->all[idx].str = strdup(ed->all[idx].mmap);
218 ed->all[idx].mmap = NULL;
221 #else /* ifdef _WIN32 */
222 if (ed->all[idx].mmap)
223 return ed->all[idx].mmap;
225 #endif /* ifdef _WIN32 */
226 return ed->all[idx].str;
230 } /* eet_dictionary_string_get_char */
232 static inline Eina_Bool
233 _eet_dictionary_string_get_me_cache(const char *s,
238 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
240 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
241 *exponent = (s[5] - '0');
247 } /* _eet_dictionary_string_get_me_cache */
249 static inline Eina_Bool
250 _eet_dictionary_string_get_float_cache(const char *s,
257 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
260 *result = (float)(mantisse << exponent);
262 *result = (float)mantisse / (float)(1 << exponent);
268 } /* _eet_dictionary_string_get_float_cache */
270 static inline Eina_Bool
271 _eet_dictionary_string_get_double_cache(const char *s,
278 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
281 *result = (double)(mantisse << exponent);
283 *result = (double)mantisse / (float)(1 << exponent);
289 } /* _eet_dictionary_string_get_double_cache */
291 static inline Eina_Bool
292 _eet_dictionary_test(const Eet_Dictionary *ed,
305 if (!(idx < ed->count))
309 } /* _eet_dictionary_test */
312 eet_dictionary_string_get_float(const Eet_Dictionary *ed,
316 if (!_eet_dictionary_test(ed, idx, result))
319 if (!(ed->all[idx].type & EET_D_FLOAT))
323 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
325 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
328 long long mantisse = 0;
331 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
332 &exponent) == EINA_FALSE)
335 ed->all[idx].f = ldexpf((float)mantisse, exponent);
338 ed->all[idx].type |= EET_D_FLOAT;
341 *result = ed->all[idx].f;
343 } /* eet_dictionary_string_get_float */
346 eet_dictionary_string_get_double(const Eet_Dictionary *ed,
350 if (!_eet_dictionary_test(ed, idx, result))
353 if (!(ed->all[idx].type & EET_D_DOUBLE))
357 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
359 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
362 long long mantisse = 0;
365 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
366 &exponent) == EINA_FALSE)
369 ed->all[idx].d = ldexp((double)mantisse, exponent);
372 ed->all[idx].type |= EET_D_DOUBLE;
375 *result = ed->all[idx].d;
377 } /* eet_dictionary_string_get_double */
380 eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
384 if (!_eet_dictionary_test(ed, idx, result))
387 if (!(ed->all[idx].type & EET_D_FIXED_POINT))
392 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
394 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
397 ed->all[idx].fp = fp;
398 ed->all[idx].type |= EET_D_FIXED_POINT;
401 *result = ed->all[idx].fp;
403 } /* eet_dictionary_string_get_fp */
406 eet_dictionary_string_check(Eet_Dictionary *ed,
411 if ((!ed) || (!string))
414 if ((ed->start <= string) && (string < ed->end))
417 for (i = 0; i < ed->count; ++i)
418 if (ed->all[i].str == string)
422 } /* eet_dictionary_string_check */