2008-03-07 23:28:12 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2008-03-28 10:17:43 -07:00
|
|
|
# include <config.h>
|
2010-07-30 18:54:48 -07:00
|
|
|
#endif /* ifdef HAVE_CONFIG_H */
|
2008-03-07 23:28:12 -08:00
|
|
|
|
2008-03-28 10:17:43 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2008-10-20 02:44:34 -07:00
|
|
|
#include <Eina.h>
|
|
|
|
|
2008-03-01 09:37:39 -08:00
|
|
|
#include "Eet.h"
|
|
|
|
#include "Eet_private.h"
|
|
|
|
|
|
|
|
Eet_Dictionary *
|
|
|
|
eet_dictionary_add(void)
|
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
Eet_Dictionary *ed;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
ed = eet_dictionary_calloc(1);
|
|
|
|
if (!ed) return NULL;
|
|
|
|
memset(ed->hash, -1, sizeof(int) * 256);
|
|
|
|
eina_rwlock_new(&ed->rwlock);
|
|
|
|
return ed;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
|
|
|
void
|
2010-07-31 11:54:54 -07:00
|
|
|
eet_dictionary_free(Eet_Dictionary *ed)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2011-12-02 14:50:00 -08:00
|
|
|
int i;
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2011-12-02 14:50:00 -08:00
|
|
|
if (!ed) return;
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_free(&ed->rwlock);
|
2012-05-14 23:43:07 -07:00
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
for (i = 0; i < ed->count; i++)
|
|
|
|
{
|
|
|
|
if (ed->all_allocated[i >> 3] & (1 << (i & 0x7)))
|
|
|
|
{
|
|
|
|
eina_stringshare_del(ed->all[i].str);
|
|
|
|
}
|
|
|
|
}
|
2013-04-03 20:01:07 -07:00
|
|
|
free(ed->all);
|
|
|
|
free(ed->all_hash);
|
|
|
|
free(ed->all_allocated);
|
2011-12-02 08:10:41 -08:00
|
|
|
|
2011-12-02 14:50:00 -08:00
|
|
|
if (ed->converts) eina_hash_free(ed->converts);
|
|
|
|
eet_dictionary_mp_free(ed);
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
|
|
|
static int
|
2010-07-31 11:54:54 -07:00
|
|
|
_eet_dictionary_lookup(Eet_Dictionary *ed,
|
2010-07-31 11:57:35 -07:00
|
|
|
const char *string,
|
2011-10-20 22:40:01 -07:00
|
|
|
int len,
|
2013-04-04 20:14:50 -07:00
|
|
|
int hash,
|
|
|
|
int *previous)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
int prev = -1, current;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
|
|
|
current = ed->hash[hash];
|
|
|
|
while (current != -1)
|
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
if ((ed->all[current].str) &&
|
|
|
|
((ed->all[current].str == string) ||
|
|
|
|
((ed->all[current].len == len) &&
|
|
|
|
(!strcmp(ed->all[current].str, string)))))
|
2011-10-20 22:40:01 -07:00
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
break;
|
2011-10-20 22:40:01 -07:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
prev = current;
|
|
|
|
current = ed->all[current].next;
|
|
|
|
}
|
2013-04-04 20:14:50 -07:00
|
|
|
if (previous) *previous = prev;
|
2008-03-01 09:37:39 -08:00
|
|
|
return current;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
|
|
|
int
|
2010-07-31 11:54:54 -07:00
|
|
|
eet_dictionary_string_add(Eet_Dictionary *ed,
|
2010-07-31 11:57:35 -07:00
|
|
|
const char *string)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2010-07-31 11:54:54 -07:00
|
|
|
Eet_String *current;
|
2010-11-29 06:04:16 -08:00
|
|
|
const char *str;
|
2018-11-20 09:15:57 -08:00
|
|
|
int hash, idx, pidx, len, cnt;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
if (!ed) return -1;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
|
|
|
hash = _eet_hash_gen(string, 8);
|
2010-09-03 06:25:22 -07:00
|
|
|
len = strlen(string) + 1;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read(&ed->rwlock);
|
2012-05-14 23:43:07 -07:00
|
|
|
|
2013-04-04 20:14:50 -07:00
|
|
|
idx = _eet_dictionary_lookup(ed, string, len, hash, &pidx);
|
2010-03-01 03:03:35 -08:00
|
|
|
if (idx != -1)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2018-11-20 08:57:24 -08:00
|
|
|
eina_rwlock_release(&ed->rwlock);
|
|
|
|
return idx;
|
2008-03-01 09:37:39 -08:00
|
|
|
}
|
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
str = eina_stringshare_add(string);
|
|
|
|
if (!str) goto on_error;
|
|
|
|
|
|
|
|
eina_rwlock_release(&ed->rwlock);
|
|
|
|
eina_rwlock_take_write(&ed->rwlock);
|
2008-03-01 09:37:39 -08:00
|
|
|
if (ed->total == ed->count)
|
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
Eet_String *s;
|
|
|
|
unsigned char *new_hash, *new_allocated;
|
2010-07-27 18:45:57 -07:00
|
|
|
int total;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
total = ed->total + 64;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
s = realloc(ed->all, total * sizeof(Eet_String));
|
|
|
|
if (!s) goto on_error;
|
|
|
|
ed->all = s;
|
2013-04-03 20:01:07 -07:00
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
new_hash = realloc(ed->all_hash, total);
|
|
|
|
if (!new_hash) goto on_error;
|
|
|
|
ed->all_hash = new_hash;
|
|
|
|
|
|
|
|
new_allocated = realloc(ed->all_allocated, ((total >> 3) + 1));
|
|
|
|
if (!new_allocated) goto on_error;
|
|
|
|
ed->all_allocated = new_allocated;
|
2013-04-03 20:01:07 -07:00
|
|
|
|
2008-03-01 09:37:39 -08:00
|
|
|
ed->total = total;
|
|
|
|
}
|
|
|
|
|
|
|
|
current = ed->all + ed->count;
|
|
|
|
|
2013-11-07 00:58:42 -08:00
|
|
|
ed->all_allocated[ed->count >> 3] |= (1 << (ed->count & 0x7));
|
2013-04-03 20:01:07 -07:00
|
|
|
ed->all_hash[ed->count] = hash;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2010-11-29 06:04:16 -08:00
|
|
|
current->str = str;
|
2008-03-01 09:37:39 -08:00
|
|
|
current->len = len;
|
|
|
|
|
2019-02-12 23:59:46 -08:00
|
|
|
current->next = ed->hash[hash];
|
|
|
|
ed->hash[hash] = ed->count;
|
|
|
|
|
2012-05-15 00:51:00 -07:00
|
|
|
cnt = ed->count++;
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release(&ed->rwlock);
|
2012-05-15 00:06:12 -07:00
|
|
|
return cnt;
|
2012-05-14 23:43:07 -07:00
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
on_error:
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release(&ed->rwlock);
|
2012-05-14 23:43:07 -07:00
|
|
|
return -1;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
|
|
|
int
|
2010-07-31 11:54:54 -07:00
|
|
|
eet_dictionary_string_get_size(const Eet_Dictionary *ed,
|
|
|
|
int idx)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2012-05-14 23:43:07 -07:00
|
|
|
int length = 0;
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2012-05-14 23:43:07 -07:00
|
|
|
if (!ed) goto done;
|
|
|
|
if (idx < 0) goto done;
|
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
2018-11-20 09:15:57 -08:00
|
|
|
if (idx < ed->count) length = ed->all[idx].len;
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2018-11-20 09:15:57 -08:00
|
|
|
done:
|
2012-05-14 23:43:07 -07:00
|
|
|
return length;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2012-02-10 07:30:33 -08:00
|
|
|
EAPI int
|
|
|
|
eet_dictionary_count(const Eet_Dictionary *ed)
|
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
int cnt;
|
|
|
|
|
|
|
|
if (!ed) return 0;
|
|
|
|
|
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
|
|
|
cnt = ed->count;
|
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
|
|
|
return cnt;
|
2012-02-10 07:30:33 -08:00
|
|
|
}
|
|
|
|
|
2008-07-17 08:33:40 -07:00
|
|
|
int
|
2010-07-31 11:54:54 -07:00
|
|
|
eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
|
|
|
|
int idx)
|
2008-07-17 08:33:40 -07:00
|
|
|
{
|
2012-05-14 23:43:07 -07:00
|
|
|
int hash = -1;
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2012-05-14 23:43:07 -07:00
|
|
|
if (!ed) goto done;
|
|
|
|
if (idx < 0) goto done;
|
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
2018-11-20 09:15:57 -08:00
|
|
|
if (idx < ed->count) hash = ed->all_hash[idx];
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2018-11-20 09:15:57 -08:00
|
|
|
done:
|
2012-05-14 23:43:07 -07:00
|
|
|
return hash;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-07-17 08:33:40 -07:00
|
|
|
|
2008-03-01 09:37:39 -08:00
|
|
|
const char *
|
2010-07-31 11:54:54 -07:00
|
|
|
eet_dictionary_string_get_char(const Eet_Dictionary *ed,
|
|
|
|
int idx)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2012-05-14 23:43:07 -07:00
|
|
|
const char *s = NULL;
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2012-05-14 23:43:07 -07:00
|
|
|
if (!ed) goto done;
|
|
|
|
if (idx < 0) goto done;
|
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
2010-03-01 03:03:35 -08:00
|
|
|
if (idx < ed->count)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2008-03-06 09:52:59 -08:00
|
|
|
#ifdef _WIN32
|
2010-07-27 18:45:57 -07:00
|
|
|
/* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
|
2018-11-20 09:15:57 -08:00
|
|
|
if (!(ed->all_allocated[idx >> 3] & (1 << (idx & 0x7))))
|
2010-07-27 18:45:57 -07:00
|
|
|
{
|
2011-01-29 09:31:55 -08:00
|
|
|
ed->all[idx].str = eina_stringshare_add(ed->all[idx].str);
|
2013-11-07 00:58:42 -08:00
|
|
|
ed->all_allocated[idx >> 3] |= (1 << (idx & 0x7));
|
2010-07-27 18:45:57 -07:00
|
|
|
}
|
2010-07-30 18:54:48 -07:00
|
|
|
#endif /* ifdef _WIN32 */
|
2012-05-14 23:43:07 -07:00
|
|
|
s = ed->all[idx].str;
|
2008-03-01 09:37:39 -08:00
|
|
|
}
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2018-11-20 09:15:57 -08:00
|
|
|
done:
|
2012-05-14 23:43:07 -07:00
|
|
|
return s;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2009-09-29 06:24:45 -07:00
|
|
|
static inline Eina_Bool
|
2010-07-31 11:54:54 -07:00
|
|
|
_eet_dictionary_string_get_me_cache(const char *s,
|
|
|
|
int len,
|
2010-07-31 11:57:35 -07:00
|
|
|
int *mantisse,
|
|
|
|
int *exponent)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
|
|
|
if ((len == 6) && (s[0] == '0') && (s[1] == 'x') && (s[3] == 'p'))
|
|
|
|
{
|
|
|
|
*mantisse = (s[2] >= 'a') ? (s[2] - 'a' + 10) : (s[2] - '0');
|
|
|
|
*exponent = (s[5] - '0');
|
2009-09-29 06:24:45 -07:00
|
|
|
return EINA_TRUE;
|
2008-03-01 09:37:39 -08:00
|
|
|
}
|
2009-09-29 06:24:45 -07:00
|
|
|
return EINA_FALSE;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2009-09-29 06:24:45 -07:00
|
|
|
static inline Eina_Bool
|
2010-07-31 11:54:54 -07:00
|
|
|
_eet_dictionary_string_get_float_cache(const char *s,
|
|
|
|
int len,
|
2010-07-31 11:57:35 -07:00
|
|
|
float *result)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
int mantisse, exponent;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
|
|
|
if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
|
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
if (s[4] == '+') *result = (float)(mantisse << exponent);
|
|
|
|
else *result = (float)mantisse / (float)(1 << exponent);
|
2009-09-29 06:24:45 -07:00
|
|
|
return EINA_TRUE;
|
2008-03-01 09:37:39 -08:00
|
|
|
}
|
2009-09-29 06:24:45 -07:00
|
|
|
return EINA_FALSE;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2009-09-29 06:24:45 -07:00
|
|
|
static inline Eina_Bool
|
2010-07-31 11:54:54 -07:00
|
|
|
_eet_dictionary_string_get_double_cache(const char *s,
|
|
|
|
int len,
|
2010-07-31 11:57:35 -07:00
|
|
|
double *result)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
int mantisse, exponent;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
|
|
|
if (_eet_dictionary_string_get_me_cache(s, len, &mantisse, &exponent))
|
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
if (s[4] == '+') *result = (double)(mantisse << exponent);
|
|
|
|
else *result = (double)mantisse / (float)(1 << exponent);
|
2009-09-29 06:24:45 -07:00
|
|
|
return EINA_TRUE;
|
2008-03-01 09:37:39 -08:00
|
|
|
}
|
2009-09-29 06:24:45 -07:00
|
|
|
return EINA_FALSE;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2009-09-29 06:24:45 -07:00
|
|
|
static inline Eina_Bool
|
2010-07-31 11:54:54 -07:00
|
|
|
_eet_dictionary_test(const Eet_Dictionary *ed,
|
|
|
|
int idx,
|
2010-07-31 11:57:35 -07:00
|
|
|
void *result)
|
2009-09-29 06:24:45 -07:00
|
|
|
{
|
2012-05-14 23:43:07 -07:00
|
|
|
Eina_Bool limit = EINA_FALSE;
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2012-05-14 23:43:07 -07:00
|
|
|
if (!result) goto done;
|
|
|
|
if (!ed) goto done;
|
|
|
|
if (idx < 0) goto done;
|
2010-07-27 18:45:57 -07:00
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
2012-05-14 23:43:07 -07:00
|
|
|
if (!(idx < ed->count)) goto unlock_done;
|
|
|
|
limit = EINA_TRUE;
|
2018-11-20 09:15:57 -08:00
|
|
|
unlock_done:
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2018-11-20 09:15:57 -08:00
|
|
|
done:
|
2012-05-14 23:43:07 -07:00
|
|
|
return limit;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2009-09-29 06:24:45 -07:00
|
|
|
|
2010-11-26 06:40:53 -08:00
|
|
|
static Eet_Convert *
|
|
|
|
eet_dictionary_convert_get(const Eet_Dictionary *ed,
|
2011-10-20 22:40:01 -07:00
|
|
|
int idx,
|
|
|
|
const char **str)
|
2010-11-26 06:40:53 -08:00
|
|
|
{
|
|
|
|
Eet_Convert *result;
|
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
2010-11-29 06:04:16 -08:00
|
|
|
*str = ed->all[idx].str;
|
2010-11-26 06:40:53 -08:00
|
|
|
|
|
|
|
if (!ed->converts)
|
|
|
|
{
|
2011-10-20 22:40:01 -07:00
|
|
|
((Eet_Dictionary *)ed)->converts = eina_hash_int32_new(free);
|
2010-11-26 06:40:53 -08:00
|
|
|
goto add_convert;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = eina_hash_find(ed->converts, &idx);
|
2012-05-14 23:43:07 -07:00
|
|
|
if (result) goto done;
|
2010-11-26 06:40:53 -08:00
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
add_convert:
|
2010-11-26 06:40:53 -08:00
|
|
|
result = calloc(1, sizeof (Eet_Convert));
|
|
|
|
eina_hash_add(ed->converts, &idx, result);
|
2018-11-20 09:15:57 -08:00
|
|
|
done:
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2010-11-26 06:40:53 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-09-29 06:24:45 -07:00
|
|
|
Eina_Bool
|
2010-07-31 11:54:54 -07:00
|
|
|
eet_dictionary_string_get_float(const Eet_Dictionary *ed,
|
|
|
|
int idx,
|
2010-07-31 11:57:35 -07:00
|
|
|
float *result)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2010-11-26 06:40:53 -08:00
|
|
|
Eet_Convert *convert;
|
|
|
|
const char *str;
|
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2010-11-26 06:40:53 -08:00
|
|
|
convert = eet_dictionary_convert_get(ed, idx, &str);
|
|
|
|
if (!convert) return EINA_FALSE;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2010-11-26 06:40:53 -08:00
|
|
|
if (!(convert->type & EET_D_FLOAT))
|
|
|
|
{
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
2010-07-27 18:45:57 -07:00
|
|
|
if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len,
|
2010-11-26 06:40:53 -08:00
|
|
|
&convert->f))
|
2010-07-27 18:45:57 -07:00
|
|
|
{
|
|
|
|
long long mantisse = 0;
|
|
|
|
long exponent = 0;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2010-07-27 18:45:57 -07:00
|
|
|
if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
|
|
|
|
&exponent) == EINA_FALSE)
|
2012-05-14 23:43:07 -07:00
|
|
|
{
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2012-05-14 23:43:07 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2010-11-26 06:40:53 -08:00
|
|
|
convert->f = ldexpf((float)mantisse, exponent);
|
2010-07-27 18:45:57 -07:00
|
|
|
}
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2010-11-26 06:40:53 -08:00
|
|
|
convert->type |= EET_D_FLOAT;
|
2008-03-01 09:37:39 -08:00
|
|
|
}
|
2010-11-26 06:40:53 -08:00
|
|
|
*result = convert->f;
|
2009-09-29 06:24:45 -07:00
|
|
|
return EINA_TRUE;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2009-09-29 06:24:45 -07:00
|
|
|
Eina_Bool
|
2010-07-31 11:54:54 -07:00
|
|
|
eet_dictionary_string_get_double(const Eet_Dictionary *ed,
|
|
|
|
int idx,
|
2010-07-31 11:57:35 -07:00
|
|
|
double *result)
|
2008-03-01 09:37:39 -08:00
|
|
|
{
|
2010-11-26 06:40:53 -08:00
|
|
|
Eet_Convert *convert;
|
|
|
|
const char *str;
|
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE;
|
2009-09-29 06:24:45 -07:00
|
|
|
|
2010-11-26 06:40:53 -08:00
|
|
|
convert = eet_dictionary_convert_get(ed, idx, &str);
|
|
|
|
if (!convert) return EINA_FALSE;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2010-11-26 06:40:53 -08:00
|
|
|
if (!(convert->type & EET_D_DOUBLE))
|
|
|
|
{
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
2012-05-14 23:43:07 -07:00
|
|
|
|
2010-07-27 18:45:57 -07:00
|
|
|
if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len,
|
2010-11-26 06:40:53 -08:00
|
|
|
&convert->d))
|
2010-07-27 18:45:57 -07:00
|
|
|
{
|
|
|
|
long long mantisse = 0;
|
|
|
|
long exponent = 0;
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2010-07-27 18:45:57 -07:00
|
|
|
if (eina_convert_atod(str, ed->all[idx].len, &mantisse,
|
|
|
|
&exponent) == EINA_FALSE)
|
2012-05-14 23:43:07 -07:00
|
|
|
{
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2012-05-14 23:43:07 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2010-11-26 06:40:53 -08:00
|
|
|
convert->d = ldexp((double)mantisse, exponent);
|
2010-07-27 18:45:57 -07:00
|
|
|
}
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2010-11-26 06:40:53 -08:00
|
|
|
convert->type |= EET_D_DOUBLE;
|
2009-09-29 06:24:45 -07:00
|
|
|
}
|
2008-03-01 09:37:39 -08:00
|
|
|
|
2010-11-26 06:40:53 -08:00
|
|
|
*result = convert->d;
|
2009-09-29 06:24:45 -07:00
|
|
|
return EINA_TRUE;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2009-09-29 06:24:45 -07:00
|
|
|
|
|
|
|
Eina_Bool
|
2010-07-31 11:54:54 -07:00
|
|
|
eet_dictionary_string_get_fp(const Eet_Dictionary *ed,
|
|
|
|
int idx,
|
2010-07-31 11:57:35 -07:00
|
|
|
Eina_F32p32 *result)
|
2009-09-29 06:24:45 -07:00
|
|
|
{
|
2010-11-26 06:40:53 -08:00
|
|
|
Eet_Convert *convert;
|
|
|
|
const char *str;
|
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE;
|
2009-09-29 06:24:45 -07:00
|
|
|
|
2010-11-26 06:40:53 -08:00
|
|
|
convert = eet_dictionary_convert_get(ed, idx, &str);
|
|
|
|
if (!convert) return EINA_FALSE;
|
|
|
|
|
|
|
|
if (!(convert->type & EET_D_FIXED_POINT))
|
2009-09-29 06:24:45 -07:00
|
|
|
{
|
2010-07-27 18:45:57 -07:00
|
|
|
Eina_F32p32 fp;
|
2009-09-29 06:24:45 -07:00
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
2010-07-27 18:45:57 -07:00
|
|
|
if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
|
2012-05-14 23:43:07 -07:00
|
|
|
{
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2012-05-14 23:43:07 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2009-09-29 06:24:45 -07:00
|
|
|
|
2010-11-26 06:40:53 -08:00
|
|
|
convert->fp = fp;
|
|
|
|
convert->type |= EET_D_FIXED_POINT;
|
2008-03-01 09:37:39 -08:00
|
|
|
}
|
2009-09-29 06:24:45 -07:00
|
|
|
|
2010-11-26 06:40:53 -08:00
|
|
|
*result = convert->fp;
|
2009-09-29 06:24:45 -07:00
|
|
|
return EINA_TRUE;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2008-03-06 09:52:59 -08:00
|
|
|
|
|
|
|
EAPI int
|
2010-07-31 11:54:54 -07:00
|
|
|
eet_dictionary_string_check(Eet_Dictionary *ed,
|
2010-07-31 11:57:35 -07:00
|
|
|
const char *string)
|
2008-03-06 09:52:59 -08:00
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
int res = 0, i;
|
2008-03-06 09:52:59 -08:00
|
|
|
|
2018-11-20 09:15:57 -08:00
|
|
|
if ((!ed) || (!string)) return 0;
|
2008-03-06 09:52:59 -08:00
|
|
|
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_take_read((Eina_RWLock *)&ed->rwlock);
|
2018-11-20 09:15:57 -08:00
|
|
|
if ((ed->start <= string) && (string < ed->end)) res = 1;
|
2008-03-06 09:52:59 -08:00
|
|
|
|
2012-05-14 23:43:07 -07:00
|
|
|
if (!res)
|
|
|
|
{
|
2018-11-20 09:15:57 -08:00
|
|
|
for (i = 0; i < ed->count; i++)
|
|
|
|
{
|
|
|
|
if ((ed->all_allocated[i >> 3] & (1 << (i & 0x7))) && ed->all[i].str == string)
|
|
|
|
{
|
|
|
|
res = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-14 23:43:07 -07:00
|
|
|
}
|
2018-11-20 08:55:45 -08:00
|
|
|
eina_rwlock_release((Eina_RWLock *)&ed->rwlock);
|
2012-05-14 23:43:07 -07:00
|
|
|
return res;
|
2011-12-02 06:42:13 -08:00
|
|
|
}
|
2010-07-30 18:54:48 -07:00
|
|
|
|