2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
7 #endif /* ifdef HAVE_CONFIG_H */
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);
30 } /* eet_dictionary_add */
33 eet_dictionary_free(Eet_Dictionary *ed)
39 for (i = 0; i < ed->count; ++i)
48 } /* eet_dictionary_free */
51 _eet_dictionary_lookup(Eet_Dictionary *ed,
58 current = ed->hash[hash];
62 if (ed->all[current].str)
63 if (strcmp(ed->all[current].str, string) >= 0)
66 if (ed->all[current].mmap)
67 if (strcmp(ed->all[current].mmap, string) >= 0)
71 current = ed->all[current].next;
78 } /* _eet_dictionary_lookup */
81 eet_dictionary_string_add(Eet_Dictionary *ed,
93 hash = _eet_hash_gen(string, 8);
95 idx = _eet_dictionary_lookup(ed, string, hash);
100 if (strcmp(ed->all[idx].str, string) == 0)
103 if (ed->all[idx].mmap)
104 if (strcmp(ed->all[idx].mmap, string) == 0)
109 if (ed->total == ed->count)
114 total = ed->total + 8;
116 new = realloc(ed->all, sizeof (Eet_String) * total);
124 len = strlen(string) + 1;
125 str = strdup(string);
129 current = ed->all + ed->count;
131 current->type = EET_D_NOT_CONVERTED;
133 current->hash = hash;
137 current->mmap = NULL;
141 current->next = ed->hash[hash];
143 ed->hash[hash] = ed->count;
148 current->prev = ed->all[idx].prev;
150 if (current->next != -1)
151 ed->all[current->next].prev = ed->count;
153 if (current->prev != -1)
154 ed->all[current->prev].next = ed->count;
156 ed->hash[hash] = ed->count;
160 } /* eet_dictionary_string_add */
163 eet_dictionary_string_get_size(const Eet_Dictionary *ed,
173 return ed->all[idx].len;
176 } /* eet_dictionary_string_get_size */
179 eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
189 return ed->all[idx].hash;
192 } /* eet_dictionary_string_get_hash */
195 eet_dictionary_string_get_char(const Eet_Dictionary *ed,
207 /* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
208 if (ed->all[idx].str == NULL)
210 ed->all[idx].str = strdup(ed->all[idx].mmap);
211 ed->all[idx].mmap = NULL;
214 #else /* ifdef _WIN32 */
215 if (ed->all[idx].mmap)
216 return ed->all[idx].mmap;
218 #endif /* ifdef _WIN32 */
219 return ed->all[idx].str;
223 } /* eet_dictionary_string_get_char */
225 static inline Eina_Bool
226 _eet_dictionary_string_get_me_cache(const char *s,
231 if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
233 *mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
234 *exponent = (s[5] - '0');
240 } /* _eet_dictionary_string_get_me_cache */
242 static inline Eina_Bool
243 _eet_dictionary_string_get_float_cache(const char *s,
250 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
253 *result = (float)(mantisse << exponent);
255 *result = (float)mantisse / (float)(1 << exponent);
261 } /* _eet_dictionary_string_get_float_cache */
263 static inline Eina_Bool
264 _eet_dictionary_string_get_double_cache(const char *s,
271 if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
274 *result = (double)(mantisse << exponent);
276 *result = (double)mantisse / (float)(1 << exponent);
282 } /* _eet_dictionary_string_get_double_cache */
284 static inline Eina_Bool
285 _eet_dictionary_test(const Eet_Dictionary *ed,
298 if (!(idx < ed->count))
302 } /* _eet_dictionary_test */
305 eet_dictionary_string_get_float(const Eet_Dictionary *ed,
309 if (!_eet_dictionary_test(ed, idx, result))
312 if (!(ed->all[idx].type & EET_D_FLOAT))
316 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
318 if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
321 long long mantisse = 0;
324 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
325 &exponent) == EINA_FALSE)
328 ed->all[idx].f = ldexpf((float)mantisse, exponent);
331 ed->all[idx].type |= EET_D_FLOAT;
334 *result = ed->all[idx].f;
336 } /* eet_dictionary_string_get_float */
339 eet_dictionary_string_get_double(const Eet_Dictionary *ed,
343 if (!_eet_dictionary_test(ed, idx, result))
346 if (!(ed->all[idx].type & EET_D_DOUBLE))
350 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
352 if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
355 long long mantisse = 0;
358 if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
359 &exponent) == EINA_FALSE)
362 ed->all[idx].d = ldexp((double)mantisse, exponent);
365 ed->all[idx].type |= EET_D_DOUBLE;
368 *result = ed->all[idx].d;
370 } /* eet_dictionary_string_get_double */
373 eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
375 Eina_F32p32 * result)
377 if (!_eet_dictionary_test(ed, idx, result))
380 if (!(ed->all[idx].type & EET_D_FIXED_POINT))
385 str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
387 if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
390 ed->all[idx].fp = fp;
391 ed->all[idx].type |= EET_D_FIXED_POINT;
394 *result = ed->all[idx].fp;
396 } /* eet_dictionary_string_get_fp */
399 eet_dictionary_string_check(Eet_Dictionary *ed,
404 if ((ed == NULL) || (string == NULL))
407 if ((ed->start <= string) && (string < ed->end))
410 for (i = 0; i < ed->count; ++i)
411 if (ed->all[i].str == string)
415 } /* eet_dictionary_string_check */