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)
116 if (ed->total == ed->count)
121 total = ed->total + 8;
123 new = realloc(ed->all, sizeof (Eet_String) * total);
131 str = strdup(string);
135 current = ed->all + ed->count;
137 current->type = EET_D_NOT_CONVERTED;
139 current->hash = hash;
143 current->mmap = NULL;
147 current->next = ed->hash[hash];
149 ed->hash[hash] = ed->count;
154 current->prev = ed->all[idx].prev;
156 if (current->next != -1)
157 ed->all[current->next].prev = ed->count;
159 if (current->prev != -1)
160 ed->all[current->prev].next = ed->count;
162 ed->hash[hash] = ed->count;
166 } /* eet_dictionary_string_add */
169 eet_dictionary_string_get_size(const Eet_Dictionary *ed,
179 return ed->all[idx].len;
182 } /* eet_dictionary_string_get_size */
185 eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
195 return ed->all[idx].hash;
198 } /* eet_dictionary_string_get_hash */
201 eet_dictionary_string_get_char(const Eet_Dictionary *ed,
213 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
214 if (!ed->all[idx].str)
216 ed->all[idx].str = strdup(ed->all[idx].mmap);
217 ed->all[idx].mmap = NULL;
220 #else /* ifdef _WIN32 */
221 if (ed->all[idx].mmap)
222 return ed->all[idx].mmap;
224 #endif /* ifdef _WIN32 */
225 return ed->all[idx].str;
229 } /* eet_dictionary_string_get_char */
231 static inline Eina_Bool
232 _eet_dictionary_string_get_me_cache(const char *s,
237 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
239 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
240 *exponent = (s[5] - '0');
246 } /* _eet_dictionary_string_get_me_cache */
248 static inline Eina_Bool
249 _eet_dictionary_string_get_float_cache(const char *s,
256 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
259 *result = (float)(mantisse << exponent);
261 *result = (float)mantisse / (float)(1 << exponent);
267 } /* _eet_dictionary_string_get_float_cache */
269 static inline Eina_Bool
270 _eet_dictionary_string_get_double_cache(const char *s,
277 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
280 *result = (double)(mantisse << exponent);
282 *result = (double)mantisse / (float)(1 << exponent);
288 } /* _eet_dictionary_string_get_double_cache */
290 static inline Eina_Bool
291 _eet_dictionary_test(const Eet_Dictionary *ed,
304 if (!(idx < ed->count))
308 } /* _eet_dictionary_test */
311 eet_dictionary_string_get_float(const Eet_Dictionary *ed,
315 if (!_eet_dictionary_test(ed, idx, result))
318 if (!(ed->all[idx].type & EET_D_FLOAT))
322 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
324 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
327 long long mantisse = 0;
330 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
331 &exponent) == EINA_FALSE)
334 ed->all[idx].f = ldexpf((float)mantisse, exponent);
337 ed->all[idx].type |= EET_D_FLOAT;
340 *result = ed->all[idx].f;
342 } /* eet_dictionary_string_get_float */
345 eet_dictionary_string_get_double(const Eet_Dictionary *ed,
349 if (!_eet_dictionary_test(ed, idx, result))
352 if (!(ed->all[idx].type & EET_D_DOUBLE))
356 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
358 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
361 long long mantisse = 0;
364 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
365 &exponent) == EINA_FALSE)
368 ed->all[idx].d = ldexp((double)mantisse, exponent);
371 ed->all[idx].type |= EET_D_DOUBLE;
374 *result = ed->all[idx].d;
376 } /* eet_dictionary_string_get_double */
379 eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
383 if (!_eet_dictionary_test(ed, idx, result))
386 if (!(ed->all[idx].type & EET_D_FIXED_POINT))
391 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
393 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
396 ed->all[idx].fp = fp;
397 ed->all[idx].type |= EET_D_FIXED_POINT;
400 *result = ed->all[idx].fp;
402 } /* eet_dictionary_string_get_fp */
405 eet_dictionary_string_check(Eet_Dictionary *ed,
410 if ((!ed) || (!string))
413 if ((ed->start <= string) && (string < ed->end))
416 for (i = 0; i < ed->count; ++i)
417 if (ed->all[i].str == string)
421 } /* eet_dictionary_string_check */