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,
54 current = ed->hash[hash];
58 if (ed->all[current].str)
59 if (strcmp(ed->all[current].str, string) >= 0)
62 if (ed->all[current].mmap)
63 if (strcmp(ed->all[current].mmap, string) >= 0)
67 current = ed->all[current].next;
74 } /* _eet_dictionary_lookup */
77 eet_dictionary_string_add(Eet_Dictionary *ed,
89 hash = _eet_hash_gen(string, 8);
91 idx = _eet_dictionary_lookup(ed, string, hash);
96 if (strcmp(ed->all[idx].str, string) == 0)
99 if (ed->all[idx].mmap)
100 if (strcmp(ed->all[idx].mmap, string) == 0)
105 if (ed->total == ed->count)
110 total = ed->total + 8;
112 new = realloc(ed->all, sizeof (Eet_String) * total);
120 len = strlen(string) + 1;
121 str = strdup(string);
125 current = ed->all + ed->count;
127 current->type = EET_D_NOT_CONVERTED;
129 current->hash = hash;
133 current->mmap = NULL;
137 current->next = ed->hash[hash];
139 ed->hash[hash] = ed->count;
144 current->prev = ed->all[idx].prev;
146 if (current->next != -1)
147 ed->all[current->next].prev = ed->count;
149 if (current->prev != -1)
150 ed->all[current->prev].next = ed->count;
152 ed->hash[hash] = ed->count;
156 } /* eet_dictionary_string_add */
159 eet_dictionary_string_get_size(const Eet_Dictionary *ed,
169 return ed->all[idx].len;
172 } /* eet_dictionary_string_get_size */
175 eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
185 return ed->all[idx].hash;
188 } /* eet_dictionary_string_get_hash */
191 eet_dictionary_string_get_char(const Eet_Dictionary *ed,
203 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
204 if (!ed->all[idx].str)
206 ed->all[idx].str = strdup(ed->all[idx].mmap);
207 ed->all[idx].mmap = NULL;
210 #else /* ifdef _WIN32 */
211 if (ed->all[idx].mmap)
212 return ed->all[idx].mmap;
214 #endif /* ifdef _WIN32 */
215 return ed->all[idx].str;
219 } /* eet_dictionary_string_get_char */
221 static inline Eina_Bool
222 _eet_dictionary_string_get_me_cache(const char *s,
227 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
229 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
230 *exponent = (s[5] - '0');
236 } /* _eet_dictionary_string_get_me_cache */
238 static inline Eina_Bool
239 _eet_dictionary_string_get_float_cache(const char *s,
246 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
249 *result = (float)(mantisse << exponent);
251 *result = (float)mantisse / (float)(1 << exponent);
257 } /* _eet_dictionary_string_get_float_cache */
259 static inline Eina_Bool
260 _eet_dictionary_string_get_double_cache(const char *s,
267 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
270 *result = (double)(mantisse << exponent);
272 *result = (double)mantisse / (float)(1 << exponent);
278 } /* _eet_dictionary_string_get_double_cache */
280 static inline Eina_Bool
281 _eet_dictionary_test(const Eet_Dictionary *ed,
294 if (!(idx < ed->count))
298 } /* _eet_dictionary_test */
301 eet_dictionary_string_get_float(const Eet_Dictionary *ed,
305 if (!_eet_dictionary_test(ed, idx, result))
308 if (!(ed->all[idx].type & EET_D_FLOAT))
312 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
314 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
317 long long mantisse = 0;
320 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
321 &exponent) == EINA_FALSE)
324 ed->all[idx].f = ldexpf((float)mantisse, exponent);
327 ed->all[idx].type |= EET_D_FLOAT;
330 *result = ed->all[idx].f;
332 } /* eet_dictionary_string_get_float */
335 eet_dictionary_string_get_double(const Eet_Dictionary *ed,
339 if (!_eet_dictionary_test(ed, idx, result))
342 if (!(ed->all[idx].type & EET_D_DOUBLE))
346 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
348 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
351 long long mantisse = 0;
354 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
355 &exponent) == EINA_FALSE)
358 ed->all[idx].d = ldexp((double)mantisse, exponent);
361 ed->all[idx].type |= EET_D_DOUBLE;
364 *result = ed->all[idx].d;
366 } /* eet_dictionary_string_get_double */
369 eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
373 if (!_eet_dictionary_test(ed, idx, result))
376 if (!(ed->all[idx].type & EET_D_FIXED_POINT))
381 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
383 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
386 ed->all[idx].fp = fp;
387 ed->all[idx].type |= EET_D_FIXED_POINT;
390 *result = ed->all[idx].fp;
392 } /* eet_dictionary_string_get_fp */
395 eet_dictionary_string_check(Eet_Dictionary *ed,
400 if ((!ed) || (!string))
403 if ((ed->start <= string) && (string < ed->end))
406 for (i = 0; i < ed->count; ++i)
407 if (ed->all[i].str == string)
411 } /* eet_dictionary_string_check */