1 /* EINA - EFL data type library
2 * Copyright (C) 2012 ProFUSION embedded systems
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
25 #elif defined __GNUC__
26 # define alloca __builtin_alloca
28 # define alloca __alloca
29 #elif defined _MSC_VER
31 # define alloca _alloca
37 void *alloca (size_t);
40 #include <stdio.h> /* asprintf() */
41 #include <inttypes.h> /* PRId64 and PRIu64 */
42 #include <sys/time.h> /* struct timeval */
48 #include "eina_config.h"
49 #include "eina_private.h"
50 #include "eina_error.h"
52 #include "eina_strbuf.h"
53 #include "eina_mempool.h"
54 #include "eina_lock.h"
56 /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
57 #include "eina_safety_checks.h"
58 #include "eina_value.h"
60 #include "eina_model.h" // uses eina_value.h
63 /*============================================================================*
65 *============================================================================*/
71 static Eina_Mempool *_eina_value_mp = NULL;
72 static Eina_Hash *_eina_value_inner_mps = NULL;
73 static Eina_Lock _eina_value_inner_mps_lock;
74 static char *_eina_value_mp_choice = NULL;
75 static int _eina_value_log_dom = -1;
80 #define ERR(...) EINA_LOG_DOM_ERR(_eina_value_log_dom, __VA_ARGS__)
85 #define DBG(...) EINA_LOG_DOM_DBG(_eina_value_log_dom, __VA_ARGS__)
87 static const unsigned char eina_value_uchar_max = 255U;
88 static const char eina_value_char_max = 127;
89 static const char eina_value_char_min = -127 - 1;
91 static const unsigned short eina_value_ushort_max = 65535U;
92 static const short eina_value_short_max = 32767;
93 static const short eina_value_short_min = -32767 - 1;
95 static const unsigned int eina_value_uint_max = 4294967295U;
96 static const int eina_value_int_max = 2147483647;
97 static const int eina_value_int_min = -2147483647 - 1;
99 static const uint64_t eina_value_uint64_max = 18446744073709551615ULL;
100 static const int64_t eina_value_int64_max = 9223372036854775807LL;
101 static const int64_t eina_value_int64_min = -9223372036854775807LL - 1LL;
104 static const unsigned long eina_value_ulong_max = 18446744073709551615ULL;
105 static const long eina_value_long_max = 9223372036854775807LL;
106 static const long eina_value_long_min = -9223372036854775807LL - 1LL;
108 static const unsigned long eina_value_ulong_max = 4294967295U;
109 static const long eina_value_long_max = 2147483647;
110 static const long eina_value_long_min = -2147483647 - 1;
115 _eina_value_type_uchar_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
117 unsigned char *tmem = mem;
123 _eina_value_type_uchar_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
129 _eina_value_type_uchar_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
131 const unsigned char *s = src;
132 unsigned char *d = dst;
138 _eina_value_type_uchar_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
140 const unsigned char *ta = a, *tb = b;
149 _eina_value_type_uchar_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
151 const unsigned char v = *(const unsigned char *)type_mem;
155 if (convert == EINA_VALUE_TYPE_UCHAR)
157 unsigned char other_mem = v;
158 return eina_value_type_pset(convert, convert_mem, &other_mem);
160 else if (convert == EINA_VALUE_TYPE_USHORT)
162 unsigned short other_mem = v;
163 return eina_value_type_pset(convert, convert_mem, &other_mem);
165 else if (convert == EINA_VALUE_TYPE_UINT)
167 unsigned int other_mem = v;
168 return eina_value_type_pset(convert, convert_mem, &other_mem);
170 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
172 unsigned long other_mem = v;
173 return eina_value_type_pset(convert, convert_mem, &other_mem);
175 else if (convert == EINA_VALUE_TYPE_UINT64)
177 uint64_t other_mem = v;
178 return eina_value_type_pset(convert, convert_mem, &other_mem);
180 else if (convert == EINA_VALUE_TYPE_CHAR)
183 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
185 return eina_value_type_pset(convert, convert_mem, &other_mem);
187 else if (convert == EINA_VALUE_TYPE_SHORT)
190 return eina_value_type_pset(convert, convert_mem, &other_mem);
192 else if (convert == EINA_VALUE_TYPE_INT)
195 return eina_value_type_pset(convert, convert_mem, &other_mem);
197 else if (convert == EINA_VALUE_TYPE_LONG)
200 return eina_value_type_pset(convert, convert_mem, &other_mem);
202 else if (convert == EINA_VALUE_TYPE_INT64)
204 int64_t other_mem = v;
205 return eina_value_type_pset(convert, convert_mem, &other_mem);
207 else if (convert == EINA_VALUE_TYPE_FLOAT)
210 return eina_value_type_pset(convert, convert_mem, &other_mem);
212 else if (convert == EINA_VALUE_TYPE_DOUBLE)
214 double other_mem = v;
215 return eina_value_type_pset(convert, convert_mem, &other_mem);
217 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
218 convert == EINA_VALUE_TYPE_STRING)
220 const char *other_mem;
222 snprintf(buf, sizeof(buf), "%hhu", v);
223 other_mem = buf; /* required due &buf == buf */
224 return eina_value_type_pset(convert, convert_mem, &other_mem);
228 eina_error_set(EINA_ERROR_VALUE_FAILED);
236 _eina_value_type_uchar_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
238 unsigned char *tmem = mem;
239 *tmem = va_arg(args, unsigned int); /* char is promoted to int for va_arg */
244 _eina_value_type_uchar_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
246 unsigned char *tmem = mem;
247 const unsigned char *p = ptr;
253 _eina_value_type_uchar_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
255 const unsigned char *tmem = mem;
256 unsigned char *p = ptr;
262 _eina_value_type_ushort_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
264 unsigned short *tmem = mem;
270 _eina_value_type_ushort_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
276 _eina_value_type_ushort_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
278 const unsigned short *s = src;
279 unsigned short *d = dst;
285 _eina_value_type_ushort_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
287 const unsigned short *ta = a, *tb = b;
296 _eina_value_type_ushort_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
298 const unsigned short v = *(const unsigned short *)type_mem;
302 if (convert == EINA_VALUE_TYPE_UCHAR)
304 unsigned char other_mem = v;
305 if (EINA_UNLIKELY(v > eina_value_uchar_max))
307 return eina_value_type_pset(convert, convert_mem, &other_mem);
309 else if (convert == EINA_VALUE_TYPE_USHORT)
311 unsigned short other_mem = v;
312 return eina_value_type_pset(convert, convert_mem, &other_mem);
314 else if (convert == EINA_VALUE_TYPE_UINT)
316 unsigned int other_mem = v;
317 return eina_value_type_pset(convert, convert_mem, &other_mem);
319 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
321 unsigned long other_mem = v;
322 return eina_value_type_pset(convert, convert_mem, &other_mem);
324 else if (convert == EINA_VALUE_TYPE_UINT64)
326 uint64_t other_mem = v;
327 return eina_value_type_pset(convert, convert_mem, &other_mem);
329 else if (convert == EINA_VALUE_TYPE_CHAR)
332 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
334 return eina_value_type_pset(convert, convert_mem, &other_mem);
336 else if (convert == EINA_VALUE_TYPE_SHORT)
339 if (EINA_UNLIKELY(v > (unsigned short)eina_value_short_max))
341 return eina_value_type_pset(convert, convert_mem, &other_mem);
343 else if (convert == EINA_VALUE_TYPE_INT)
346 return eina_value_type_pset(convert, convert_mem, &other_mem);
348 else if (convert == EINA_VALUE_TYPE_LONG)
351 return eina_value_type_pset(convert, convert_mem, &other_mem);
353 else if (convert == EINA_VALUE_TYPE_INT64)
355 int64_t other_mem = v;
356 return eina_value_type_pset(convert, convert_mem, &other_mem);
358 else if (convert == EINA_VALUE_TYPE_FLOAT)
361 return eina_value_type_pset(convert, convert_mem, &other_mem);
363 else if (convert == EINA_VALUE_TYPE_DOUBLE)
365 double other_mem = v;
366 return eina_value_type_pset(convert, convert_mem, &other_mem);
368 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
369 convert == EINA_VALUE_TYPE_STRING)
371 const char *other_mem;
373 snprintf(buf, sizeof(buf), "%hu", v);
374 other_mem = buf; /* required due &buf == buf */
375 return eina_value_type_pset(convert, convert_mem, &other_mem);
379 eina_error_set(EINA_ERROR_VALUE_FAILED);
387 _eina_value_type_ushort_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
389 unsigned short *tmem = mem;
390 *tmem = va_arg(args, unsigned int); /* short is promoted to int for va_arg */
395 _eina_value_type_ushort_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
397 unsigned short *tmem = mem;
398 const unsigned short *p = ptr;
404 _eina_value_type_ushort_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
406 const unsigned short *tmem = mem;
407 unsigned short *p = ptr;
413 _eina_value_type_uint_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
415 unsigned int *tmem = mem;
421 _eina_value_type_uint_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
427 _eina_value_type_uint_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
429 const unsigned int *s = src;
430 unsigned int *d = dst;
436 _eina_value_type_uint_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
438 const unsigned int *ta = a, *tb = b;
447 _eina_value_type_uint_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
449 const unsigned int v = *(const unsigned int *)type_mem;
453 if (convert == EINA_VALUE_TYPE_UCHAR)
455 unsigned char other_mem = v;
456 if (EINA_UNLIKELY(v > eina_value_uchar_max))
458 return eina_value_type_pset(convert, convert_mem, &other_mem);
460 else if (convert == EINA_VALUE_TYPE_USHORT)
462 unsigned short other_mem = v;
463 if (EINA_UNLIKELY(v > eina_value_ushort_max))
465 return eina_value_type_pset(convert, convert_mem, &other_mem);
467 else if (convert == EINA_VALUE_TYPE_UINT)
469 unsigned int other_mem = v;
470 return eina_value_type_pset(convert, convert_mem, &other_mem);
472 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
474 unsigned long other_mem = v;
475 return eina_value_type_pset(convert, convert_mem, &other_mem);
477 else if (convert == EINA_VALUE_TYPE_UINT64)
479 uint64_t other_mem = v;
480 return eina_value_type_pset(convert, convert_mem, &other_mem);
482 else if (convert == EINA_VALUE_TYPE_CHAR)
485 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
487 return eina_value_type_pset(convert, convert_mem, &other_mem);
489 else if (convert == EINA_VALUE_TYPE_SHORT)
492 if (EINA_UNLIKELY(v > (unsigned short)eina_value_short_max))
494 return eina_value_type_pset(convert, convert_mem, &other_mem);
496 else if (convert == EINA_VALUE_TYPE_INT)
499 if (EINA_UNLIKELY(v > (unsigned int)eina_value_int_max))
501 return eina_value_type_pset(convert, convert_mem, &other_mem);
503 else if (convert == EINA_VALUE_TYPE_LONG)
506 return eina_value_type_pset(convert, convert_mem, &other_mem);
508 else if (convert == EINA_VALUE_TYPE_INT64)
510 int64_t other_mem = v;
511 return eina_value_type_pset(convert, convert_mem, &other_mem);
513 else if (convert == EINA_VALUE_TYPE_FLOAT)
516 return eina_value_type_pset(convert, convert_mem, &other_mem);
518 else if (convert == EINA_VALUE_TYPE_DOUBLE)
520 double other_mem = v;
521 return eina_value_type_pset(convert, convert_mem, &other_mem);
523 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
524 convert == EINA_VALUE_TYPE_STRING)
526 const char *other_mem;
528 snprintf(buf, sizeof(buf), "%u", v);
529 other_mem = buf; /* required due &buf == buf */
530 return eina_value_type_pset(convert, convert_mem, &other_mem);
534 eina_error_set(EINA_ERROR_VALUE_FAILED);
542 _eina_value_type_uint_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
544 unsigned int *tmem = mem;
545 *tmem = va_arg(args, unsigned int);
550 _eina_value_type_uint_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
552 unsigned int *tmem = mem;
553 const unsigned int *p = ptr;
559 _eina_value_type_uint_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
561 const unsigned int *tmem = mem;
562 unsigned int *p = ptr;
568 _eina_value_type_ulong_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
570 unsigned long *tmem = mem;
576 _eina_value_type_ulong_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
582 _eina_value_type_ulong_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
584 const unsigned long *s = src;
585 unsigned long *d = dst;
591 _eina_value_type_ulong_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
593 const unsigned long *ta = a, *tb = b;
602 _eina_value_type_ulong_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
604 const unsigned long v = *(const unsigned long *)type_mem;
608 if (convert == EINA_VALUE_TYPE_UCHAR)
610 unsigned char other_mem = v;
611 if (EINA_UNLIKELY(v > eina_value_uchar_max))
613 return eina_value_type_pset(convert, convert_mem, &other_mem);
615 else if (convert == EINA_VALUE_TYPE_USHORT)
617 unsigned short other_mem = v;
618 if (EINA_UNLIKELY(v > eina_value_ushort_max))
620 return eina_value_type_pset(convert, convert_mem, &other_mem);
622 else if (convert == EINA_VALUE_TYPE_UINT)
624 unsigned int other_mem = v;
625 if (EINA_UNLIKELY(v > eina_value_uint_max))
627 return eina_value_type_pset(convert, convert_mem, &other_mem);
629 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
631 unsigned long other_mem = v;
632 return eina_value_type_pset(convert, convert_mem, &other_mem);
634 else if (convert == EINA_VALUE_TYPE_UINT64)
636 uint64_t other_mem = v;
637 return eina_value_type_pset(convert, convert_mem, &other_mem);
639 else if (convert == EINA_VALUE_TYPE_CHAR)
642 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
644 return eina_value_type_pset(convert, convert_mem, &other_mem);
646 else if (convert == EINA_VALUE_TYPE_SHORT)
649 if (EINA_UNLIKELY(v > (unsigned short)eina_value_short_max))
651 return eina_value_type_pset(convert, convert_mem, &other_mem);
653 else if (convert == EINA_VALUE_TYPE_INT)
656 if (EINA_UNLIKELY(v > (unsigned int)eina_value_int_max))
658 return eina_value_type_pset(convert, convert_mem, &other_mem);
660 else if (convert == EINA_VALUE_TYPE_LONG)
663 if (EINA_UNLIKELY(v > (unsigned long)eina_value_long_max))
665 return eina_value_type_pset(convert, convert_mem, &other_mem);
667 else if (convert == EINA_VALUE_TYPE_INT64)
669 int64_t other_mem = v;
670 return eina_value_type_pset(convert, convert_mem, &other_mem);
672 else if (convert == EINA_VALUE_TYPE_FLOAT)
675 return eina_value_type_pset(convert, convert_mem, &other_mem);
677 else if (convert == EINA_VALUE_TYPE_DOUBLE)
679 double other_mem = v;
680 return eina_value_type_pset(convert, convert_mem, &other_mem);
682 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
683 convert == EINA_VALUE_TYPE_STRING)
685 const char *other_mem;
687 snprintf(buf, sizeof(buf), "%lu", v);
688 other_mem = buf; /* required due &buf == buf */
689 return eina_value_type_pset(convert, convert_mem, &other_mem);
693 eina_error_set(EINA_ERROR_VALUE_FAILED);
701 _eina_value_type_ulong_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
703 unsigned long *tmem = mem;
704 *tmem = va_arg(args, unsigned long);
709 _eina_value_type_ulong_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
711 unsigned long *tmem = mem;
712 const unsigned long *p = ptr;
718 _eina_value_type_ulong_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
720 const unsigned long *tmem = mem;
721 unsigned long *p = ptr;
727 _eina_value_type_uint64_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
729 uint64_t *tmem = mem;
735 _eina_value_type_uint64_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
741 _eina_value_type_uint64_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
743 const uint64_t *s = src;
750 _eina_value_type_uint64_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
752 const uint64_t *ta = a, *tb = b;
761 _eina_value_type_uint64_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
763 const uint64_t v = *(const uint64_t *)type_mem;
767 if (convert == EINA_VALUE_TYPE_UCHAR)
769 unsigned char other_mem = v;
770 if (EINA_UNLIKELY(v > eina_value_uchar_max))
772 return eina_value_type_pset(convert, convert_mem, &other_mem);
774 else if (convert == EINA_VALUE_TYPE_USHORT)
776 unsigned short other_mem = v;
777 if (EINA_UNLIKELY(v > eina_value_ushort_max))
779 return eina_value_type_pset(convert, convert_mem, &other_mem);
781 else if (convert == EINA_VALUE_TYPE_UINT)
783 unsigned int other_mem = v;
784 if (EINA_UNLIKELY(v > eina_value_uint_max))
786 return eina_value_type_pset(convert, convert_mem, &other_mem);
788 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
790 unsigned long other_mem = v;
791 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
792 (v > eina_value_ulong_max)))
794 return eina_value_type_pset(convert, convert_mem, &other_mem);
796 else if (convert == EINA_VALUE_TYPE_UINT64)
798 uint64_t other_mem = v;
799 return eina_value_type_pset(convert, convert_mem, &other_mem);
801 else if (convert == EINA_VALUE_TYPE_CHAR)
804 if (EINA_UNLIKELY(v > (unsigned char)eina_value_char_max))
806 return eina_value_type_pset(convert, convert_mem, &other_mem);
808 else if (convert == EINA_VALUE_TYPE_SHORT)
811 if (EINA_UNLIKELY(v > (unsigned short)eina_value_short_max))
813 return eina_value_type_pset(convert, convert_mem, &other_mem);
815 else if (convert == EINA_VALUE_TYPE_INT)
818 if (EINA_UNLIKELY(v > (unsigned int)eina_value_int_max))
820 return eina_value_type_pset(convert, convert_mem, &other_mem);
822 else if (convert == EINA_VALUE_TYPE_LONG)
825 if (EINA_UNLIKELY(v > (unsigned long)eina_value_long_max))
827 return eina_value_type_pset(convert, convert_mem, &other_mem);
829 else if (convert == EINA_VALUE_TYPE_INT64)
831 int64_t other_mem = v;
832 if (EINA_UNLIKELY(v > (uint64_t)eina_value_int64_max))
834 return eina_value_type_pset(convert, convert_mem, &other_mem);
836 else if (convert == EINA_VALUE_TYPE_FLOAT)
839 return eina_value_type_pset(convert, convert_mem, &other_mem);
841 else if (convert == EINA_VALUE_TYPE_DOUBLE)
843 double other_mem = v;
844 return eina_value_type_pset(convert, convert_mem, &other_mem);
846 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
847 convert == EINA_VALUE_TYPE_STRING)
849 const char *other_mem;
851 snprintf(buf, sizeof(buf), "%"PRIu64, v);
852 other_mem = buf; /* required due &buf == buf */
853 return eina_value_type_pset(convert, convert_mem, &other_mem);
857 eina_error_set(EINA_ERROR_VALUE_FAILED);
865 _eina_value_type_uint64_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
867 uint64_t *tmem = mem;
868 *tmem = va_arg(args, uint64_t);
873 _eina_value_type_uint64_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
875 uint64_t *tmem = mem;
876 const uint64_t *p = ptr;
882 _eina_value_type_uint64_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
884 const uint64_t *tmem = mem;
891 _eina_value_type_char_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
899 _eina_value_type_char_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
905 _eina_value_type_char_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
914 _eina_value_type_char_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
916 const char *ta = a, *tb = b;
925 _eina_value_type_char_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
927 const signed char v = *(const signed char *)type_mem;
931 if (convert == EINA_VALUE_TYPE_UCHAR)
933 unsigned char other_mem = v;
934 if (EINA_UNLIKELY(v < 0))
936 return eina_value_type_pset(convert, convert_mem, &other_mem);
938 else if (convert == EINA_VALUE_TYPE_USHORT)
940 unsigned short other_mem = v;
941 if (EINA_UNLIKELY(v < 0))
943 return eina_value_type_pset(convert, convert_mem, &other_mem);
945 else if (convert == EINA_VALUE_TYPE_UINT)
947 unsigned int other_mem = v;
948 if (EINA_UNLIKELY(v < 0))
950 return eina_value_type_pset(convert, convert_mem, &other_mem);
952 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
954 unsigned long other_mem = v;
955 if (EINA_UNLIKELY(v < 0))
957 return eina_value_type_pset(convert, convert_mem, &other_mem);
959 else if (convert == EINA_VALUE_TYPE_UINT64)
961 uint64_t other_mem = v;
962 if (EINA_UNLIKELY(v < 0))
964 return eina_value_type_pset(convert, convert_mem, &other_mem);
966 else if (convert == EINA_VALUE_TYPE_CHAR)
969 return eina_value_type_pset(convert, convert_mem, &other_mem);
971 else if (convert == EINA_VALUE_TYPE_SHORT)
974 return eina_value_type_pset(convert, convert_mem, &other_mem);
976 else if (convert == EINA_VALUE_TYPE_INT)
979 return eina_value_type_pset(convert, convert_mem, &other_mem);
981 else if (convert == EINA_VALUE_TYPE_LONG)
984 return eina_value_type_pset(convert, convert_mem, &other_mem);
986 else if (convert == EINA_VALUE_TYPE_INT64)
988 int64_t other_mem = v;
989 return eina_value_type_pset(convert, convert_mem, &other_mem);
991 else if (convert == EINA_VALUE_TYPE_FLOAT)
994 return eina_value_type_pset(convert, convert_mem, &other_mem);
996 else if (convert == EINA_VALUE_TYPE_DOUBLE)
998 double other_mem = v;
999 return eina_value_type_pset(convert, convert_mem, &other_mem);
1001 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1002 convert == EINA_VALUE_TYPE_STRING)
1004 const char *other_mem;
1006 snprintf(buf, sizeof(buf), "%hhd", v);
1007 other_mem = buf; /* required due &buf == buf */
1008 return eina_value_type_pset(convert, convert_mem, &other_mem);
1012 eina_error_set(EINA_ERROR_VALUE_FAILED);
1020 _eina_value_type_char_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1023 *tmem = va_arg(args, int); /* char is promoted to int for va_arg */
1028 _eina_value_type_char_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1031 const char *p = ptr;
1037 _eina_value_type_char_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1039 const char *tmem = mem;
1046 _eina_value_type_short_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1054 _eina_value_type_short_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1060 _eina_value_type_short_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1062 const short *s = src;
1069 _eina_value_type_short_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1071 const short *ta = a, *tb = b;
1080 _eina_value_type_short_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1082 const short v = *(const short *)type_mem;
1086 if (convert == EINA_VALUE_TYPE_UCHAR)
1088 unsigned char other_mem = v;
1089 if (EINA_UNLIKELY(v < 0))
1091 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1093 return eina_value_type_pset(convert, convert_mem, &other_mem);
1095 else if (convert == EINA_VALUE_TYPE_USHORT)
1097 unsigned short other_mem = v;
1098 if (EINA_UNLIKELY(v < 0))
1100 return eina_value_type_pset(convert, convert_mem, &other_mem);
1102 else if (convert == EINA_VALUE_TYPE_UINT)
1104 unsigned int other_mem = v;
1105 if (EINA_UNLIKELY(v < 0))
1107 return eina_value_type_pset(convert, convert_mem, &other_mem);
1109 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
1111 unsigned long other_mem = v;
1112 if (EINA_UNLIKELY(v < 0))
1114 return eina_value_type_pset(convert, convert_mem, &other_mem);
1116 else if (convert == EINA_VALUE_TYPE_UINT64)
1118 uint64_t other_mem = v;
1119 if (EINA_UNLIKELY(v < 0))
1121 return eina_value_type_pset(convert, convert_mem, &other_mem);
1123 else if (convert == EINA_VALUE_TYPE_CHAR)
1126 if (EINA_UNLIKELY(v < eina_value_char_min))
1128 if (EINA_UNLIKELY(v > eina_value_char_max))
1130 return eina_value_type_pset(convert, convert_mem, &other_mem);
1132 else if (convert == EINA_VALUE_TYPE_SHORT)
1134 short other_mem = v;
1135 return eina_value_type_pset(convert, convert_mem, &other_mem);
1137 else if (convert == EINA_VALUE_TYPE_INT)
1140 return eina_value_type_pset(convert, convert_mem, &other_mem);
1142 else if (convert == EINA_VALUE_TYPE_LONG)
1145 return eina_value_type_pset(convert, convert_mem, &other_mem);
1147 else if (convert == EINA_VALUE_TYPE_INT64)
1149 int64_t other_mem = v;
1150 return eina_value_type_pset(convert, convert_mem, &other_mem);
1152 else if (convert == EINA_VALUE_TYPE_FLOAT)
1154 float other_mem = v;
1155 return eina_value_type_pset(convert, convert_mem, &other_mem);
1157 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1159 double other_mem = v;
1160 return eina_value_type_pset(convert, convert_mem, &other_mem);
1162 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1163 convert == EINA_VALUE_TYPE_STRING)
1165 const char *other_mem;
1167 snprintf(buf, sizeof(buf), "%hd", v);
1168 other_mem = buf; /* required due &buf == buf */
1169 return eina_value_type_pset(convert, convert_mem, &other_mem);
1173 eina_error_set(EINA_ERROR_VALUE_FAILED);
1181 _eina_value_type_short_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1184 *tmem = va_arg(args, int); /* short int is promoted to int for va_arg */
1189 _eina_value_type_short_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1192 const short *p = ptr;
1198 _eina_value_type_short_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1200 const short *tmem = mem;
1207 _eina_value_type_int_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1215 _eina_value_type_int_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1221 _eina_value_type_int_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1230 _eina_value_type_int_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1232 const int *ta = a, *tb = b;
1241 _eina_value_type_int_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1243 const int v = *(const int *)type_mem;
1247 if (convert == EINA_VALUE_TYPE_UCHAR)
1249 unsigned char other_mem = v;
1250 if (EINA_UNLIKELY(v < 0))
1252 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1254 return eina_value_type_pset(convert, convert_mem, &other_mem);
1256 else if (convert == EINA_VALUE_TYPE_USHORT)
1258 unsigned short other_mem = v;
1259 if (EINA_UNLIKELY(v < 0))
1261 if (EINA_UNLIKELY(v > eina_value_ushort_max))
1263 return eina_value_type_pset(convert, convert_mem, &other_mem);
1265 else if (convert == EINA_VALUE_TYPE_UINT)
1267 unsigned int other_mem = v;
1268 if (EINA_UNLIKELY(v < 0))
1270 return eina_value_type_pset(convert, convert_mem, &other_mem);
1272 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
1274 unsigned long other_mem = v;
1275 if (EINA_UNLIKELY(v < 0))
1277 return eina_value_type_pset(convert, convert_mem, &other_mem);
1279 else if (convert == EINA_VALUE_TYPE_UINT64)
1281 uint64_t other_mem = v;
1282 if (EINA_UNLIKELY(v < 0))
1284 return eina_value_type_pset(convert, convert_mem, &other_mem);
1286 else if (convert == EINA_VALUE_TYPE_CHAR)
1289 if (EINA_UNLIKELY(v < eina_value_char_min))
1291 if (EINA_UNLIKELY(v > eina_value_char_max))
1293 return eina_value_type_pset(convert, convert_mem, &other_mem);
1295 else if (convert == EINA_VALUE_TYPE_SHORT)
1297 short other_mem = v;
1298 if (EINA_UNLIKELY(v < eina_value_short_min))
1300 if (EINA_UNLIKELY(v > eina_value_short_max))
1302 return eina_value_type_pset(convert, convert_mem, &other_mem);
1304 else if (convert == EINA_VALUE_TYPE_INT)
1307 return eina_value_type_pset(convert, convert_mem, &other_mem);
1309 else if (convert == EINA_VALUE_TYPE_LONG)
1312 return eina_value_type_pset(convert, convert_mem, &other_mem);
1314 else if (convert == EINA_VALUE_TYPE_INT64)
1316 int64_t other_mem = v;
1317 return eina_value_type_pset(convert, convert_mem, &other_mem);
1319 else if (convert == EINA_VALUE_TYPE_FLOAT)
1321 float other_mem = v;
1322 return eina_value_type_pset(convert, convert_mem, &other_mem);
1324 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1326 double other_mem = v;
1327 return eina_value_type_pset(convert, convert_mem, &other_mem);
1329 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1330 convert == EINA_VALUE_TYPE_STRING)
1332 const char *other_mem;
1334 snprintf(buf, sizeof(buf), "%d", v);
1335 other_mem = buf; /* required due &buf == buf */
1336 return eina_value_type_pset(convert, convert_mem, &other_mem);
1340 eina_error_set(EINA_ERROR_VALUE_FAILED);
1348 _eina_value_type_int_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1351 *tmem = va_arg(args, int);
1356 _eina_value_type_int_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1365 _eina_value_type_int_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1367 const int *tmem = mem;
1374 _eina_value_type_long_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1382 _eina_value_type_long_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1388 _eina_value_type_long_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1390 const long *s = src;
1397 _eina_value_type_long_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1399 const long *ta = a, *tb = b;
1408 _eina_value_type_long_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1410 const long v = *(const long *)type_mem;
1414 if (convert == EINA_VALUE_TYPE_UCHAR)
1416 unsigned char other_mem = v;
1417 if (EINA_UNLIKELY(v < 0))
1419 if (EINA_UNLIKELY((unsigned long) v > eina_value_uchar_max))
1421 return eina_value_type_pset(convert, convert_mem, &other_mem);
1423 else if (convert == EINA_VALUE_TYPE_USHORT)
1425 unsigned short other_mem = v;
1426 if (EINA_UNLIKELY(v < 0))
1428 if (EINA_UNLIKELY((unsigned long) v > eina_value_ushort_max))
1430 return eina_value_type_pset(convert, convert_mem, &other_mem);
1432 else if (convert == EINA_VALUE_TYPE_UINT)
1434 unsigned int other_mem = v;
1435 if (EINA_UNLIKELY(v < 0))
1437 if (EINA_UNLIKELY((unsigned long) v > eina_value_uint_max))
1439 return eina_value_type_pset(convert, convert_mem, &other_mem);
1441 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
1443 unsigned long other_mem = v;
1444 if (EINA_UNLIKELY(v < 0))
1446 return eina_value_type_pset(convert, convert_mem, &other_mem);
1448 else if (convert == EINA_VALUE_TYPE_UINT64)
1450 uint64_t other_mem = v;
1451 if (EINA_UNLIKELY(v < 0))
1453 return eina_value_type_pset(convert, convert_mem, &other_mem);
1455 else if (convert == EINA_VALUE_TYPE_CHAR)
1458 if (EINA_UNLIKELY(v < eina_value_char_min))
1460 if (EINA_UNLIKELY(v > eina_value_char_max))
1462 return eina_value_type_pset(convert, convert_mem, &other_mem);
1464 else if (convert == EINA_VALUE_TYPE_SHORT)
1466 short other_mem = v;
1467 if (EINA_UNLIKELY(v < eina_value_short_min))
1469 if (EINA_UNLIKELY(v > eina_value_short_max))
1471 return eina_value_type_pset(convert, convert_mem, &other_mem);
1473 else if (convert == EINA_VALUE_TYPE_INT)
1476 if (EINA_UNLIKELY(v < eina_value_int_min))
1478 if (EINA_UNLIKELY(v > eina_value_int_max))
1480 return eina_value_type_pset(convert, convert_mem, &other_mem);
1482 else if (convert == EINA_VALUE_TYPE_LONG)
1485 return eina_value_type_pset(convert, convert_mem, &other_mem);
1487 else if (convert == EINA_VALUE_TYPE_INT64)
1489 int64_t other_mem = v;
1490 return eina_value_type_pset(convert, convert_mem, &other_mem);
1492 else if (convert == EINA_VALUE_TYPE_FLOAT)
1494 float other_mem = v;
1495 return eina_value_type_pset(convert, convert_mem, &other_mem);
1497 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1499 double other_mem = v;
1500 return eina_value_type_pset(convert, convert_mem, &other_mem);
1502 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1503 convert == EINA_VALUE_TYPE_STRING)
1505 const char *other_mem;
1507 snprintf(buf, sizeof(buf), "%ld", v);
1508 other_mem = buf; /* required due &buf == buf */
1509 return eina_value_type_pset(convert, convert_mem, &other_mem);
1513 eina_error_set(EINA_ERROR_VALUE_FAILED);
1521 _eina_value_type_long_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1524 *tmem = va_arg(args, long);
1529 _eina_value_type_long_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1532 const long *p = ptr;
1538 _eina_value_type_long_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1540 const long *tmem = mem;
1547 _eina_value_type_int64_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1549 int64_t *tmem = mem;
1555 _eina_value_type_int64_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1561 _eina_value_type_int64_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1563 const int64_t *s = src;
1570 _eina_value_type_int64_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1572 const int64_t *ta = a, *tb = b;
1581 _eina_value_type_int64_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1583 const int64_t v = *(const int64_t *)type_mem;
1587 if (convert == EINA_VALUE_TYPE_UCHAR)
1589 unsigned char other_mem = v;
1590 if (EINA_UNLIKELY(v < 0))
1592 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1594 return eina_value_type_pset(convert, convert_mem, &other_mem);
1596 else if (convert == EINA_VALUE_TYPE_USHORT)
1598 unsigned short other_mem = v;
1599 if (EINA_UNLIKELY(v < 0))
1601 if (EINA_UNLIKELY(v > eina_value_ushort_max))
1603 return eina_value_type_pset(convert, convert_mem, &other_mem);
1605 else if (convert == EINA_VALUE_TYPE_UINT)
1607 unsigned int other_mem = v;
1608 if (EINA_UNLIKELY(v < 0))
1610 if (EINA_UNLIKELY(v > eina_value_uint_max))
1612 return eina_value_type_pset(convert, convert_mem, &other_mem);
1614 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
1616 unsigned long other_mem = v;
1617 if (EINA_UNLIKELY(v < 0))
1619 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
1620 (v > eina_value_ulong_max)))
1622 return eina_value_type_pset(convert, convert_mem, &other_mem);
1624 else if (convert == EINA_VALUE_TYPE_UINT64)
1626 uint64_t other_mem = v;
1627 if (EINA_UNLIKELY(v < 0))
1629 return eina_value_type_pset(convert, convert_mem, &other_mem);
1631 else if (convert == EINA_VALUE_TYPE_CHAR)
1634 if (EINA_UNLIKELY(v < eina_value_char_min))
1636 if (EINA_UNLIKELY(v > eina_value_char_max))
1638 return eina_value_type_pset(convert, convert_mem, &other_mem);
1640 else if (convert == EINA_VALUE_TYPE_SHORT)
1642 short other_mem = v;
1643 if (EINA_UNLIKELY(v < eina_value_short_min))
1645 if (EINA_UNLIKELY(v > eina_value_short_max))
1647 return eina_value_type_pset(convert, convert_mem, &other_mem);
1649 else if (convert == EINA_VALUE_TYPE_INT)
1652 if (EINA_UNLIKELY(v < eina_value_int_min))
1654 if (EINA_UNLIKELY(v > eina_value_int_max))
1656 return eina_value_type_pset(convert, convert_mem, &other_mem);
1658 else if (convert == EINA_VALUE_TYPE_LONG)
1661 if (EINA_UNLIKELY(v < eina_value_long_min))
1663 if (EINA_UNLIKELY(v > eina_value_long_max))
1665 return eina_value_type_pset(convert, convert_mem, &other_mem);
1667 else if (convert == EINA_VALUE_TYPE_INT64)
1669 int64_t other_mem = v;
1670 return eina_value_type_pset(convert, convert_mem, &other_mem);
1672 else if (convert == EINA_VALUE_TYPE_FLOAT)
1674 float other_mem = v;
1675 return eina_value_type_pset(convert, convert_mem, &other_mem);
1677 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1679 double other_mem = v;
1680 return eina_value_type_pset(convert, convert_mem, &other_mem);
1682 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1683 convert == EINA_VALUE_TYPE_STRING)
1685 const char *other_mem;
1687 snprintf(buf, sizeof(buf), "%"PRId64, v);
1688 other_mem = buf; /* required due &buf == buf */
1689 return eina_value_type_pset(convert, convert_mem, &other_mem);
1693 eina_error_set(EINA_ERROR_VALUE_FAILED);
1701 _eina_value_type_int64_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1703 int64_t *tmem = mem;
1704 *tmem = va_arg(args, int64_t);
1709 _eina_value_type_int64_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1711 int64_t *tmem = mem;
1712 const int64_t *p = ptr;
1718 _eina_value_type_int64_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1720 const int64_t *tmem = mem;
1727 _eina_value_type_float_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1735 _eina_value_type_float_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1741 _eina_value_type_float_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1743 const float *s = src;
1750 _eina_value_type_float_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1752 const float *ta = a, *tb = b;
1761 _eina_value_type_float_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1763 const float v = *(const float *)type_mem;
1767 if (convert == EINA_VALUE_TYPE_UCHAR)
1769 unsigned char other_mem = v;
1770 if (EINA_UNLIKELY(v < 0))
1772 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1774 return eina_value_type_pset(convert, convert_mem, &other_mem);
1776 else if (convert == EINA_VALUE_TYPE_USHORT)
1778 unsigned short other_mem = v;
1779 if (EINA_UNLIKELY(v < 0))
1781 if (EINA_UNLIKELY(v > eina_value_ushort_max))
1783 return eina_value_type_pset(convert, convert_mem, &other_mem);
1785 else if (convert == EINA_VALUE_TYPE_UINT)
1787 unsigned int other_mem = v;
1788 if (EINA_UNLIKELY(v < 0))
1790 if (EINA_UNLIKELY(v > eina_value_uint_max))
1792 return eina_value_type_pset(convert, convert_mem, &other_mem);
1794 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
1796 unsigned long other_mem = v;
1797 if (EINA_UNLIKELY(v < 0))
1799 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
1800 (v > eina_value_ulong_max)))
1802 return eina_value_type_pset(convert, convert_mem, &other_mem);
1804 else if (convert == EINA_VALUE_TYPE_UINT64)
1806 uint64_t other_mem = v;
1807 if (EINA_UNLIKELY(v < 0))
1809 if (EINA_UNLIKELY(v > eina_value_uint64_max))
1811 return eina_value_type_pset(convert, convert_mem, &other_mem);
1813 else if (convert == EINA_VALUE_TYPE_CHAR)
1816 if (EINA_UNLIKELY(v < eina_value_char_min))
1818 if (EINA_UNLIKELY(v > eina_value_char_max))
1820 return eina_value_type_pset(convert, convert_mem, &other_mem);
1822 else if (convert == EINA_VALUE_TYPE_SHORT)
1824 short other_mem = v;
1825 if (EINA_UNLIKELY(v < eina_value_short_min))
1827 if (EINA_UNLIKELY(v > eina_value_short_max))
1829 return eina_value_type_pset(convert, convert_mem, &other_mem);
1831 else if (convert == EINA_VALUE_TYPE_INT)
1834 if (EINA_UNLIKELY(v < eina_value_int_min))
1836 if (EINA_UNLIKELY(v > eina_value_int_max))
1838 return eina_value_type_pset(convert, convert_mem, &other_mem);
1840 else if (convert == EINA_VALUE_TYPE_LONG)
1843 if (EINA_UNLIKELY(v < eina_value_long_min))
1845 if (EINA_UNLIKELY(v > eina_value_long_max))
1847 return eina_value_type_pset(convert, convert_mem, &other_mem);
1849 else if (convert == EINA_VALUE_TYPE_INT64)
1851 int64_t other_mem = v;
1852 if (EINA_UNLIKELY(v < eina_value_int64_min))
1854 if (EINA_UNLIKELY(v > eina_value_int64_max))
1856 return eina_value_type_pset(convert, convert_mem, &other_mem);
1858 else if (convert == EINA_VALUE_TYPE_FLOAT)
1860 float other_mem = v;
1861 return eina_value_type_pset(convert, convert_mem, &other_mem);
1863 else if (convert == EINA_VALUE_TYPE_DOUBLE)
1865 double other_mem = v;
1866 return eina_value_type_pset(convert, convert_mem, &other_mem);
1868 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
1869 convert == EINA_VALUE_TYPE_STRING)
1871 const char *other_mem;
1873 snprintf(buf, sizeof(buf), "%f", v);
1874 other_mem = buf; /* required due &buf == buf */
1875 return eina_value_type_pset(convert, convert_mem, &other_mem);
1879 eina_error_set(EINA_ERROR_VALUE_FAILED);
1887 _eina_value_type_float_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
1890 *tmem = va_arg(args, double); /* float is promoted to double for va_args */
1895 _eina_value_type_float_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
1898 const float *p = ptr;
1904 _eina_value_type_float_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
1906 const float *tmem = mem;
1913 _eina_value_type_double_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
1921 _eina_value_type_double_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
1927 _eina_value_type_double_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
1929 const double *s = src;
1936 _eina_value_type_double_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
1938 const double *ta = a, *tb = b;
1947 _eina_value_type_double_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
1949 const double v = *(const double *)type_mem;
1953 if (convert == EINA_VALUE_TYPE_UCHAR)
1955 unsigned char other_mem = v;
1956 if (EINA_UNLIKELY(v < 0))
1958 if (EINA_UNLIKELY(v > eina_value_uchar_max))
1960 return eina_value_type_pset(convert, convert_mem, &other_mem);
1962 else if (convert == EINA_VALUE_TYPE_USHORT)
1964 unsigned short other_mem = v;
1965 if (EINA_UNLIKELY(v < 0))
1967 if (EINA_UNLIKELY(v > eina_value_ushort_max))
1969 return eina_value_type_pset(convert, convert_mem, &other_mem);
1971 else if (convert == EINA_VALUE_TYPE_UINT)
1973 unsigned int other_mem = v;
1974 if (EINA_UNLIKELY(v < 0))
1976 if (EINA_UNLIKELY(v > eina_value_uint_max))
1978 return eina_value_type_pset(convert, convert_mem, &other_mem);
1980 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
1982 unsigned long other_mem = v;
1983 if (EINA_UNLIKELY(v < 0))
1985 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
1986 (v > eina_value_ulong_max)))
1988 return eina_value_type_pset(convert, convert_mem, &other_mem);
1990 else if (convert == EINA_VALUE_TYPE_UINT64)
1992 uint64_t other_mem = v;
1993 if (EINA_UNLIKELY(v < 0))
1995 return eina_value_type_pset(convert, convert_mem, &other_mem);
1997 else if (convert == EINA_VALUE_TYPE_CHAR)
2000 if (EINA_UNLIKELY(v < eina_value_char_min))
2002 if (EINA_UNLIKELY(v > eina_value_char_max))
2004 return eina_value_type_pset(convert, convert_mem, &other_mem);
2006 else if (convert == EINA_VALUE_TYPE_SHORT)
2008 short other_mem = v;
2009 if (EINA_UNLIKELY(v < eina_value_short_min))
2011 if (EINA_UNLIKELY(v > eina_value_short_max))
2013 return eina_value_type_pset(convert, convert_mem, &other_mem);
2015 else if (convert == EINA_VALUE_TYPE_INT)
2018 if (EINA_UNLIKELY(v < eina_value_int_min))
2020 if (EINA_UNLIKELY(v > eina_value_int_max))
2022 return eina_value_type_pset(convert, convert_mem, &other_mem);
2024 else if (convert == EINA_VALUE_TYPE_LONG)
2027 if (EINA_UNLIKELY(v < eina_value_long_min))
2029 if (EINA_UNLIKELY(v > eina_value_long_max))
2031 return eina_value_type_pset(convert, convert_mem, &other_mem);
2033 else if (convert == EINA_VALUE_TYPE_INT64)
2035 int64_t other_mem = v;
2036 return eina_value_type_pset(convert, convert_mem, &other_mem);
2038 else if (convert == EINA_VALUE_TYPE_FLOAT)
2040 float other_mem = v;
2041 return eina_value_type_pset(convert, convert_mem, &other_mem);
2043 else if (convert == EINA_VALUE_TYPE_DOUBLE)
2045 double other_mem = v;
2046 return eina_value_type_pset(convert, convert_mem, &other_mem);
2048 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
2049 convert == EINA_VALUE_TYPE_STRING)
2051 const char *other_mem;
2053 snprintf(buf, sizeof(buf), "%g", (double)v);
2054 other_mem = buf; /* required due &buf == buf */
2055 return eina_value_type_pset(convert, convert_mem, &other_mem);
2059 eina_error_set(EINA_ERROR_VALUE_FAILED);
2067 _eina_value_type_double_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
2070 *tmem = va_arg(args, double);
2075 _eina_value_type_double_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
2078 const double *p = ptr;
2084 _eina_value_type_double_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
2086 const double *tmem = mem;
2093 _eina_value_type_string_common_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
2095 const char **tmem = mem;
2101 _eina_value_type_string_common_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
2103 const char *sa = *(const char **)a;
2104 const char *sb = *(const char **)b;
2111 return strcmp(sa, sb);
2115 _eina_value_type_string_common_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
2117 const char *v = *(const char **)type_mem;
2121 if (convert == EINA_VALUE_TYPE_UCHAR)
2123 unsigned char other_mem;
2124 if ((sscanf(v, "%hhu", &other_mem) != 1) &&
2125 (sscanf(v, "%hhx", &other_mem) != 1) &&
2126 (sscanf(v, "%hho", &other_mem) != 1))
2128 return eina_value_type_pset(convert, convert_mem, &other_mem);
2130 else if (convert == EINA_VALUE_TYPE_USHORT)
2132 unsigned short other_mem;
2133 if ((sscanf(v, "%hu", &other_mem) != 1) &&
2134 (sscanf(v, "%hx", &other_mem) != 1) &&
2135 (sscanf(v, "%ho", &other_mem) != 1))
2137 return eina_value_type_pset(convert, convert_mem, &other_mem);
2139 else if (convert == EINA_VALUE_TYPE_UINT)
2141 unsigned int other_mem;
2142 if ((sscanf(v, "%u", &other_mem) != 1) &&
2143 (sscanf(v, "%x", &other_mem) != 1) &&
2144 (sscanf(v, "%o", &other_mem) != 1))
2146 return eina_value_type_pset(convert, convert_mem, &other_mem);
2148 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
2150 unsigned long other_mem;
2151 if ((sscanf(v, "%lu", &other_mem) != 1) &&
2152 (sscanf(v, "%lx", &other_mem) != 1) &&
2153 (sscanf(v, "%lo", &other_mem) != 1))
2155 return eina_value_type_pset(convert, convert_mem, &other_mem);
2157 else if (convert == EINA_VALUE_TYPE_UINT64)
2160 if ((sscanf(v, "%"SCNu64, &other_mem) != 1) &&
2161 (sscanf(v, "%"SCNx64, &other_mem) != 1) &&
2162 (sscanf(v, "%"SCNo64, &other_mem) != 1))
2164 return eina_value_type_pset(convert, convert_mem, &other_mem);
2166 else if (convert == EINA_VALUE_TYPE_CHAR)
2169 if ((sscanf(v, "%hhd", &other_mem) != 1) &&
2170 (sscanf(v, "%hhx", &other_mem) != 1) &&
2171 (sscanf(v, "%hho", &other_mem) != 1))
2173 return eina_value_type_pset(convert, convert_mem, &other_mem);
2175 else if (convert == EINA_VALUE_TYPE_SHORT)
2178 if ((sscanf(v, "%hd", &other_mem) != 1) &&
2179 (sscanf(v, "%hx", &other_mem) != 1) &&
2180 (sscanf(v, "%ho", &other_mem) != 1))
2182 return eina_value_type_pset(convert, convert_mem, &other_mem);
2184 else if (convert == EINA_VALUE_TYPE_INT)
2187 if ((sscanf(v, "%d", &other_mem) != 1) &&
2188 (sscanf(v, "%x", &other_mem) != 1) &&
2189 (sscanf(v, "%o", &other_mem) != 1))
2191 return eina_value_type_pset(convert, convert_mem, &other_mem);
2193 else if (convert == EINA_VALUE_TYPE_LONG)
2196 if ((sscanf(v, "%ld", &other_mem) != 1) &&
2197 (sscanf(v, "%lx", &other_mem) != 1) &&
2198 (sscanf(v, "%lo", &other_mem) != 1))
2200 return eina_value_type_pset(convert, convert_mem, &other_mem);
2202 else if (convert == EINA_VALUE_TYPE_INT64)
2205 if ((sscanf(v, "%"SCNd64, &other_mem) != 1) &&
2206 (sscanf(v, "%"SCNx64, &other_mem) != 1) &&
2207 (sscanf(v, "%"SCNo64, &other_mem) != 1))
2209 return eina_value_type_pset(convert, convert_mem, &other_mem);
2211 else if (convert == EINA_VALUE_TYPE_FLOAT)
2214 if (sscanf(v, "%f", &other_mem) != 1)
2216 return eina_value_type_pset(convert, convert_mem, &other_mem);
2218 else if (convert == EINA_VALUE_TYPE_DOUBLE)
2221 if (sscanf(v, "%lf", &other_mem) != 1)
2223 return eina_value_type_pset(convert, convert_mem, &other_mem);
2225 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
2226 convert == EINA_VALUE_TYPE_STRING)
2228 return eina_value_type_pset(convert, convert_mem, &v);
2232 eina_error_set(EINA_ERROR_VALUE_FAILED);
2240 _eina_value_type_string_common_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
2242 memcpy(ptr, mem, sizeof(const char *));
2247 _eina_value_type_stringshare_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
2249 const char **tmem = mem;
2252 eina_stringshare_del(*tmem);
2259 _eina_value_type_stringshare_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
2261 const char * const*s = src;
2262 const char **d = dst;
2263 *d = eina_stringshare_add(*s);
2268 _eina_value_type_stringshare_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
2270 const char *str = va_arg(args, const char *);
2271 return eina_stringshare_replace((const char **)mem, str);
2275 _eina_value_type_stringshare_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
2277 const char * const *str = ptr;
2278 return eina_stringshare_replace((const char **)mem, *str);
2282 _eina_value_type_string_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
2294 _eina_value_type_string_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
2296 const char * const *s = src;
2305 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
2313 _eina_value_type_string_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
2316 const char *str = va_arg(args, const char *);
2318 if (str == *tmem) return EINA_TRUE;
2326 char *tmp = strdup(str);
2329 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
2339 _eina_value_type_string_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
2342 const char * const *str = ptr;
2344 if (*str == *tmem) return EINA_TRUE;
2352 char *tmp = strdup(*str);
2355 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
2365 _eina_value_type_array_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
2367 memset(mem, 0, sizeof(Eina_Value_Array));
2372 _eina_value_type_array_flush_elements(Eina_Value_Array *tmem)
2374 const Eina_Value_Type *subtype = tmem->subtype;
2375 Eina_Bool ret = EINA_TRUE;
2377 char *ptr, *ptr_end;
2379 if (!tmem->array) return EINA_TRUE;
2381 sz = tmem->array->member_size;
2382 ptr = tmem->array->members;
2383 ptr_end = ptr + tmem->array->len * sz;
2385 for (; ptr < ptr_end; ptr += sz)
2386 ret &= eina_value_type_flush(subtype, ptr);
2388 eina_inarray_flush(tmem->array);
2393 _eina_value_type_array_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
2395 Eina_Value_Array *tmem = mem;
2396 Eina_Bool ret =_eina_value_type_array_flush_elements(tmem);
2398 if (tmem->array) eina_inarray_free(tmem->array);
2400 tmem->subtype = NULL;
2405 _eina_value_type_array_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
2407 const Eina_Value_Type *subtype;
2408 const Eina_Value_Array *s = src;
2409 Eina_Value_Array *d = dst;
2410 unsigned int i, count, sz;
2411 char *ptr, *ptr_end;
2413 d->subtype = subtype = s->subtype;
2416 if ((!s->array) || (!s->subtype))
2424 eina_error_set(EINA_ERROR_VALUE_FAILED);
2428 d->array = eina_inarray_new(subtype->value_size, s->step);
2432 sz = s->array->member_size;
2434 count = eina_inarray_count(s->array);
2435 ptr = s->array->members;
2436 ptr_end = ptr + (count * sz);
2438 for (i = 0; ptr < ptr_end; ptr += sz, i++)
2440 void *imem = eina_inarray_alloc_at(d->array, i, 1);
2441 if (!imem) goto error;
2442 if (!subtype->copy(subtype, ptr, imem))
2444 eina_inarray_pop(d->array);
2452 _eina_value_type_array_flush_elements(d);
2457 _eina_value_type_array_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
2459 const Eina_Value_Type *subtype;
2460 const Eina_Value_Array *eva_a = a, *eva_b = b;
2461 const char *a_ptr, *a_ptr_end, *b_ptr;
2462 unsigned int count_a, count_b, count, sz;
2465 if (eva_a->subtype != eva_b->subtype)
2467 eina_error_set(EINA_ERROR_VALUE_FAILED);
2471 subtype = eva_a->subtype;
2472 if (!subtype->compare)
2474 eina_error_set(EINA_ERROR_VALUE_FAILED);
2478 if ((!eva_a->array) && (!eva_b->array))
2480 else if (!eva_a->array)
2482 else if (!eva_b->array)
2485 count_a = eina_inarray_count(eva_a->array);
2486 count_b = eina_inarray_count(eva_b->array);
2488 if (count_a <= count_b)
2493 sz = eva_a->array->member_size;
2495 a_ptr = eva_a->array->members;
2496 a_ptr_end = a_ptr + (count * sz);
2497 b_ptr = eva_b->array->members;
2499 for (; (cmp == 0) && (a_ptr < a_ptr_end); a_ptr += sz, b_ptr += sz)
2500 cmp = subtype->compare(subtype, a_ptr, b_ptr);
2504 if (count_a < count_b)
2506 else if (count_a > count_b)
2515 _eina_value_type_array_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
2517 const Eina_Value_Array *tmem = type_mem;
2518 Eina_Bool ret = EINA_FALSE;
2520 if ((convert == EINA_VALUE_TYPE_STRING) ||
2521 (convert == EINA_VALUE_TYPE_STRINGSHARE))
2523 Eina_Strbuf *str = eina_strbuf_new();
2525 if (!tmem->array) eina_strbuf_append(str, "[]");
2528 const Eina_Value_Type *subtype = tmem->subtype;
2530 const char *ptr_end;
2532 Eina_Bool first = EINA_TRUE;
2534 eina_value_setup(&tmp, EINA_VALUE_TYPE_STRING);
2536 eina_strbuf_append_char(str, '[');
2538 sz = tmem->array->member_size;
2539 ptr = tmem->array->members;
2540 ptr_end = ptr + tmem->array->len * sz;
2541 for (; ptr < ptr_end; ptr += sz)
2543 Eina_Bool r = EINA_FALSE;
2544 if (subtype->convert_to)
2546 r = subtype->convert_to(subtype, EINA_VALUE_TYPE_STRING,
2547 ptr, tmp.value.buf);
2550 if (first) first = EINA_FALSE;
2551 else eina_strbuf_append_length(str, ", ", 2);
2552 eina_strbuf_append(str, tmp.value.ptr);
2553 free(tmp.value.ptr);
2554 tmp.value.ptr = NULL;
2563 eina_strbuf_append_char(str, '?');
2566 eina_strbuf_append_length(str, ", ?", 3);
2570 eina_strbuf_append_char(str, ']');
2572 ptr = eina_strbuf_string_get(str);
2573 ret = eina_value_type_pset(convert, convert_mem, &ptr);
2574 eina_strbuf_free(str);
2576 else if ((tmem->array) && (tmem->array->len == 1))
2578 const Eina_Value_Type *subtype = tmem->subtype;
2579 void *imem = tmem->array->members;
2581 if (subtype->convert_to)
2582 ret = subtype->convert_to(subtype, convert, imem, convert_mem);
2583 if ((!ret) && (convert->convert_from))
2584 ret = convert->convert_from(convert, subtype, convert_mem, imem);
2589 eina_error_set(EINA_ERROR_VALUE_FAILED);
2596 _eina_value_type_array_convert_from(const Eina_Value_Type *type, const Eina_Value_Type *convert, void *type_mem, const void *convert_mem)
2598 Eina_Value_Array *tmem = type_mem;
2599 Eina_Value_Array desc = {convert, tmem->step, NULL};
2603 if (!eina_value_type_pset(type, tmem, &desc))
2606 buf = alloca(convert->value_size);
2607 if (!eina_value_type_pget(convert, convert_mem, &buf))
2610 imem = eina_inarray_alloc_at(tmem->array, 0, 1);
2614 if (!eina_value_type_setup(convert, imem)) goto error_setup;
2615 if (!eina_value_type_pset(convert, imem, &buf)) goto error_set;
2619 eina_value_type_flush(convert, imem);
2621 eina_inarray_remove_at(tmem->array, 0);
2626 _eina_value_type_array_pset(const Eina_Value_Type *type, void *mem, const void *ptr)
2628 Eina_Value_Array *tmem = mem;
2629 const Eina_Value_Array *desc = ptr;
2630 Eina_Inarray *desc_array;
2633 if ((!tmem->subtype) && (!desc->subtype))
2636 desc_array = desc->array;
2639 Eina_Value_Array tmp;
2641 EINA_SAFETY_ON_FALSE_RETURN_VAL
2642 (desc_array->member_size == desc->subtype->value_size, EINA_FALSE);
2644 if (desc_array == tmem->array)
2646 tmem->subtype = desc->subtype;
2650 if (!_eina_value_type_array_copy(type, desc, &tmp))
2653 _eina_value_type_array_flush(type, tmem);
2654 memcpy(tmem, &tmp, sizeof(tmp));
2660 _eina_value_type_array_flush_elements(tmem);
2661 eina_inarray_step_set(tmem->array, sizeof (Eina_Inarray), desc->subtype->value_size, desc->step);
2665 tmem->array = eina_inarray_new(desc->subtype->value_size, desc->step);
2670 tmem->subtype = desc->subtype;
2675 _eina_value_type_array_vset(const Eina_Value_Type *type, void *mem, va_list args)
2677 const Eina_Value_Array desc = va_arg(args, Eina_Value_Array);
2678 _eina_value_type_array_pset(type, mem, &desc);
2683 _eina_value_type_array_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
2685 memcpy(ptr, mem, sizeof(Eina_Value_Array));
2689 static const Eina_Value_Type _EINA_VALUE_TYPE_ARRAY = {
2690 EINA_VALUE_TYPE_VERSION,
2691 sizeof(Eina_Value_Array),
2693 _eina_value_type_array_setup,
2694 _eina_value_type_array_flush,
2695 _eina_value_type_array_copy,
2696 _eina_value_type_array_compare,
2697 _eina_value_type_array_convert_to,
2698 _eina_value_type_array_convert_from,
2699 _eina_value_type_array_vset,
2700 _eina_value_type_array_pset,
2701 _eina_value_type_array_pget
2705 _eina_value_type_list_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
2707 memset(mem, 0, sizeof(Eina_Value_List));
2712 _eina_value_type_list_flush_elements(Eina_Value_List *tmem)
2714 const Eina_Value_Type *subtype = tmem->subtype;
2715 Eina_Bool ret = EINA_TRUE;
2717 if (!tmem->list) return EINA_TRUE;
2721 void *mem = eina_value_list_node_memory_get(tmem->subtype, tmem->list);
2722 ret &= eina_value_type_flush(subtype, mem);
2723 eina_value_list_node_memory_flush(tmem->subtype, tmem->list);
2724 tmem->list = eina_list_remove_list(tmem->list, tmem->list);
2731 _eina_value_type_list_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
2733 Eina_Value_List *tmem = mem;
2734 Eina_Bool ret =_eina_value_type_list_flush_elements(tmem);
2736 if (tmem->list) eina_list_free(tmem->list);
2738 tmem->subtype = NULL;
2743 _eina_value_type_list_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
2745 const Eina_Value_Type *subtype;
2746 const Eina_Value_List *s = src;
2747 Eina_Value_List *d = dst;
2748 const Eina_List *snode;
2750 d->subtype = subtype = s->subtype;
2751 if ((!s->list) || (!s->subtype))
2759 eina_error_set(EINA_ERROR_VALUE_FAILED);
2764 for (snode = s->list; snode != NULL; snode = snode->next)
2766 const void *ptr = eina_value_list_node_memory_get(subtype, snode);
2770 d->list = eina_list_append(d->list, (void*)1L);
2771 dnode = eina_list_last(d->list);
2772 EINA_SAFETY_ON_NULL_GOTO(dnode, error);
2773 EINA_SAFETY_ON_FALSE_GOTO(dnode->data == (void*)1L, error);
2775 imem = eina_value_list_node_memory_setup(subtype, dnode);
2776 if (!subtype->copy(subtype, ptr, imem))
2778 eina_value_list_node_memory_flush(subtype, dnode);
2779 d->list = eina_list_remove_list(d->list, dnode);
2786 _eina_value_type_list_flush_elements(d);
2791 _eina_value_type_list_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
2793 const Eina_Value_Type *subtype;
2794 const Eina_Value_List *eva_a = a, *eva_b = b;
2795 const Eina_List *anode, *bnode;
2798 if (eva_a->subtype != eva_b->subtype)
2800 eina_error_set(EINA_ERROR_VALUE_FAILED);
2804 subtype = eva_a->subtype;
2805 if (!subtype->compare)
2807 eina_error_set(EINA_ERROR_VALUE_FAILED);
2811 if ((!eva_a->list) && (!eva_b->list))
2813 else if (!eva_a->list)
2815 else if (!eva_b->list)
2818 for (anode = eva_a->list, bnode = eva_b->list;
2819 (cmp == 0) && (anode) && (bnode);
2820 anode = anode->next, bnode = bnode->next)
2822 const void *amem = eina_value_list_node_memory_get(subtype, anode);
2823 const void *bmem = eina_value_list_node_memory_get(subtype, bnode);
2824 cmp = subtype->compare(subtype, amem, bmem);
2829 if ((!anode) && (bnode))
2831 else if ((anode) && (!bnode))
2840 _eina_value_type_list_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
2842 const Eina_Value_List *tmem = type_mem;
2843 Eina_Bool ret = EINA_FALSE;
2845 if ((convert == EINA_VALUE_TYPE_STRING) ||
2846 (convert == EINA_VALUE_TYPE_STRINGSHARE))
2848 Eina_Strbuf *str = eina_strbuf_new();
2850 if (!tmem->list) eina_strbuf_append(str, "[]");
2853 const Eina_Value_Type *subtype = tmem->subtype;
2854 const Eina_List *node;
2856 Eina_Bool first = EINA_TRUE;
2858 eina_value_setup(&tmp, EINA_VALUE_TYPE_STRING);
2860 eina_strbuf_append_char(str, '[');
2862 for (node = tmem->list; node != NULL; node = node->next)
2864 Eina_Bool r = EINA_FALSE;
2866 if (subtype->convert_to)
2869 ptr = eina_value_list_node_memory_get(subtype, node);
2870 r = subtype->convert_to(subtype, EINA_VALUE_TYPE_STRING,
2871 ptr, tmp.value.buf);
2874 if (first) first = EINA_FALSE;
2875 else eina_strbuf_append_length(str, ", ", 2);
2876 eina_strbuf_append(str, tmp.value.ptr);
2877 free(tmp.value.ptr);
2878 tmp.value.ptr = NULL;
2887 eina_strbuf_append_char(str, '?');
2890 eina_strbuf_append_length(str, ", ?", 3);
2894 eina_strbuf_append_char(str, ']');
2896 s = eina_strbuf_string_get(str);
2897 ret = eina_value_type_pset(convert, convert_mem, &s);
2898 eina_strbuf_free(str);
2900 else if ((tmem->list) && (tmem->list->next == NULL))
2902 const Eina_Value_Type *subtype = tmem->subtype;
2903 void *imem = eina_value_list_node_memory_get(subtype, tmem->list);
2905 if (subtype->convert_to)
2906 ret = subtype->convert_to(subtype, convert, imem, convert_mem);
2907 if ((!ret) && (convert->convert_from))
2908 ret = convert->convert_from(convert, subtype, convert_mem, imem);
2913 eina_error_set(EINA_ERROR_VALUE_FAILED);
2920 _eina_value_type_list_convert_from(const Eina_Value_Type *type, const Eina_Value_Type *convert, void *type_mem, const void *convert_mem)
2922 Eina_Value_List *tmem = type_mem;
2923 Eina_Value_List desc = {convert, NULL};
2928 if (!eina_value_type_pset(type, tmem, &desc))
2931 buf = alloca(convert->value_size);
2932 if (!eina_value_type_pget(convert, convert_mem, &buf))
2935 tmem->list = eina_list_append(tmem->list, (void*)1L);
2936 node = eina_list_last(tmem->list);
2937 EINA_SAFETY_ON_NULL_RETURN_VAL(node, EINA_FALSE);
2938 EINA_SAFETY_ON_FALSE_RETURN_VAL(node->data == (void*)1L, EINA_FALSE);
2940 imem = eina_value_list_node_memory_setup(tmem->subtype, node);
2943 tmem->list = eina_list_remove_list(tmem->list, node);
2947 if (!eina_value_type_setup(tmem->subtype, imem)) goto error_setup;
2948 if (!eina_value_type_pset(tmem->subtype, imem, &buf)) goto error_set;
2952 eina_value_type_flush(tmem->subtype, imem);
2954 eina_value_list_node_memory_flush(tmem->subtype, node);
2955 tmem->list = eina_list_remove_list(tmem->list, node);
2960 _eina_value_type_list_pset(const Eina_Value_Type *type, void *mem, const void *ptr)
2962 Eina_Value_List *tmem = mem;
2963 const Eina_Value_List *desc = ptr;
2966 if ((!tmem->subtype) && (!desc->subtype))
2969 if ((tmem->list) && (tmem->list == desc->list))
2971 tmem->subtype = desc->subtype;
2977 Eina_Value_List tmp;
2979 if (!_eina_value_type_list_copy(type, desc, &tmp))
2982 _eina_value_type_list_flush(type, tmem);
2983 memcpy(tmem, &tmp, sizeof(tmp));
2987 _eina_value_type_list_flush_elements(tmem);
2989 tmem->subtype = desc->subtype;
2994 _eina_value_type_list_vset(const Eina_Value_Type *type, void *mem, va_list args)
2996 const Eina_Value_List desc = va_arg(args, Eina_Value_List);
2997 _eina_value_type_list_pset(type, mem, &desc);
3002 _eina_value_type_list_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
3004 memcpy(ptr, mem, sizeof(Eina_Value_List));
3008 static const Eina_Value_Type _EINA_VALUE_TYPE_LIST = {
3009 EINA_VALUE_TYPE_VERSION,
3010 sizeof(Eina_Value_List),
3012 _eina_value_type_list_setup,
3013 _eina_value_type_list_flush,
3014 _eina_value_type_list_copy,
3015 _eina_value_type_list_compare,
3016 _eina_value_type_list_convert_to,
3017 _eina_value_type_list_convert_from,
3018 _eina_value_type_list_vset,
3019 _eina_value_type_list_pset,
3020 _eina_value_type_list_pget
3024 _eina_value_type_hash_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
3026 memset(mem, 0, sizeof(Eina_Value_Hash));
3030 struct _eina_value_type_hash_flush_each_ctx
3032 const Eina_Value_Type *subtype;
3037 _eina_value_type_hash_flush_each(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *mem, void *user_data)
3039 struct _eina_value_type_hash_flush_each_ctx *ctx = user_data;
3040 ctx->ret &= eina_value_type_flush(ctx->subtype, mem);
3046 _eina_value_type_hash_flush_elements(Eina_Value_Hash *tmem)
3048 struct _eina_value_type_hash_flush_each_ctx ctx = {
3053 if (!tmem->hash) return EINA_TRUE;
3055 eina_hash_foreach(tmem->hash, _eina_value_type_hash_flush_each, &ctx);
3056 eina_hash_free(tmem->hash);
3062 _eina_value_type_hash_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
3064 Eina_Value_Hash *tmem = mem;
3065 Eina_Bool ret =_eina_value_type_hash_flush_elements(tmem);
3066 tmem->subtype = NULL;
3071 _eina_value_hash_key_length(const void *key)
3075 return (int)strlen(key) + 1;
3079 _eina_value_hash_key_cmp(const void *key1, int key1_len, const void *key2, int key2_len)
3081 int r = key1_len - key2_len;
3084 return strcmp(key1, key2);
3088 _eina_value_type_hash_create(Eina_Value_Hash *desc)
3090 if (!desc->buckets_power_size)
3091 desc->buckets_power_size = 5;
3093 desc->hash = eina_hash_new(_eina_value_hash_key_length,
3094 _eina_value_hash_key_cmp,
3095 EINA_KEY_HASH(eina_hash_superfast),
3096 NULL, desc->buckets_power_size);
3097 return !!desc->hash;
3100 struct _eina_value_type_hash_copy_each_ctx
3102 const Eina_Value_Type *subtype;
3103 Eina_Value_Hash *dest;
3108 _eina_value_type_hash_copy_each(const Eina_Hash *hash __UNUSED__, const void *key, void *_ptr, void *user_data)
3110 struct _eina_value_type_hash_copy_each_ctx *ctx = user_data;
3111 const void *ptr = _ptr;
3112 void *imem = malloc(ctx->subtype->value_size);
3115 ctx->ret = EINA_FALSE;
3118 if (!ctx->subtype->copy(ctx->subtype, ptr, imem))
3121 ctx->ret = EINA_FALSE;
3124 if (!eina_hash_add(ctx->dest->hash, key, imem))
3126 eina_value_type_flush(ctx->subtype, imem);
3128 ctx->ret = EINA_FALSE;
3135 _eina_value_type_hash_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
3137 const Eina_Value_Hash *s = src;
3138 Eina_Value_Hash *d = dst;
3139 struct _eina_value_type_hash_copy_each_ctx ctx = {s->subtype, d, EINA_TRUE};
3141 d->subtype = s->subtype;
3142 d->buckets_power_size = s->buckets_power_size;
3144 if ((!s->hash) || (!s->subtype))
3150 if (!s->subtype->copy)
3152 eina_error_set(EINA_ERROR_VALUE_FAILED);
3156 if (!_eina_value_type_hash_create(d))
3159 eina_hash_foreach(s->hash, _eina_value_type_hash_copy_each, &ctx);
3162 _eina_value_type_hash_flush_elements(d);
3168 struct _eina_value_type_hash_compare_each_ctx
3170 const Eina_Value_Type *subtype;
3171 const Eina_Hash *other;
3176 _eina_value_type_hash_compare_each(const Eina_Hash *hash __UNUSED__, const void *key, void *_ptr, void *user_data)
3178 struct _eina_value_type_hash_compare_each_ctx *ctx = user_data;
3179 const void *self_ptr = _ptr;
3180 const void *other_ptr = eina_hash_find(ctx->other, key);
3181 if (!other_ptr) return EINA_TRUE;
3182 ctx->cmp = ctx->subtype->compare(ctx->subtype, self_ptr, other_ptr);
3183 return ctx->cmp == 0;
3187 _eina_value_type_hash_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
3189 const Eina_Value_Hash *eva_a = a, *eva_b = b;
3190 struct _eina_value_type_hash_compare_each_ctx ctx = {
3191 eva_a->subtype, eva_b->hash, 0
3194 if (eva_a->subtype != eva_b->subtype)
3196 eina_error_set(EINA_ERROR_VALUE_FAILED);
3200 if (!eva_a->subtype->compare)
3202 eina_error_set(EINA_ERROR_VALUE_FAILED);
3206 if ((!eva_a->hash) && (!eva_b->hash))
3208 else if (!eva_a->hash)
3210 else if (!eva_b->hash)
3213 eina_hash_foreach(eva_a->hash, _eina_value_type_hash_compare_each, &ctx);
3216 unsigned int count_a = eina_hash_population(eva_a->hash);
3217 unsigned int count_b = eina_hash_population(eva_b->hash);
3218 if (count_a < count_b)
3220 else if (count_a > count_b)
3229 _eina_value_type_hash_find_first(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *ptr, void *user_data)
3231 void **ret = user_data;
3236 struct _eina_value_type_hash_convert_to_string_each_ctx
3238 const Eina_Value_Type *subtype;
3245 _eina_value_type_hash_convert_to_string_each(const Eina_Hash *hash __UNUSED__, const void *_key, void *_ptr, void *user_data)
3247 struct _eina_value_type_hash_convert_to_string_each_ctx *ctx = user_data;
3248 const char *key = _key;
3249 const void *ptr = _ptr;
3250 Eina_Bool r = EINA_FALSE;
3252 if (ctx->first) ctx->first = EINA_FALSE;
3253 else eina_strbuf_append_length(ctx->str, ", ", 2);
3255 eina_strbuf_append(ctx->str, key);
3256 eina_strbuf_append_length(ctx->str, ": ", 2);
3258 if (ctx->subtype->convert_to)
3260 r = ctx->subtype->convert_to(ctx->subtype, EINA_VALUE_TYPE_STRING,
3261 ptr, ctx->tmp.value.buf);
3264 eina_strbuf_append(ctx->str, ctx->tmp.value.ptr);
3265 free(ctx->tmp.value.ptr);
3266 ctx->tmp.value.ptr = NULL;
3271 eina_strbuf_append_char(ctx->str, '?');
3277 _eina_value_type_hash_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
3279 const Eina_Value_Hash *tmem = type_mem;
3280 Eina_Bool ret = EINA_FALSE;
3282 if ((convert == EINA_VALUE_TYPE_STRING) ||
3283 (convert == EINA_VALUE_TYPE_STRINGSHARE))
3285 Eina_Strbuf *str = eina_strbuf_new();
3287 if (!tmem->hash) eina_strbuf_append(str, "{}");
3290 struct _eina_value_type_hash_convert_to_string_each_ctx ctx;
3292 ctx.subtype = tmem->subtype;
3294 ctx.first = EINA_TRUE;
3295 eina_value_setup(&ctx.tmp, EINA_VALUE_TYPE_STRING);
3297 eina_strbuf_append_char(str, '{');
3299 eina_hash_foreach(tmem->hash,
3300 _eina_value_type_hash_convert_to_string_each,
3303 eina_strbuf_append_char(str, '}');
3305 s = eina_strbuf_string_get(str);
3306 ret = eina_value_type_pset(convert, convert_mem, &s);
3307 eina_strbuf_free(str);
3309 else if ((tmem->hash) && (eina_hash_population(tmem->hash) == 1))
3311 const Eina_Value_Type *subtype = tmem->subtype;
3314 eina_hash_foreach(tmem->hash, _eina_value_type_hash_find_first, &imem);
3315 if (!imem) /* shouldn't happen... */
3319 if (subtype->convert_to)
3320 ret = subtype->convert_to(subtype, convert, imem, convert_mem);
3321 if ((!ret) && (convert->convert_from))
3322 ret = convert->convert_from(convert, subtype, convert_mem, imem);
3328 eina_error_set(EINA_ERROR_VALUE_FAILED);
3335 _eina_value_type_hash_pset(const Eina_Value_Type *type, void *mem, const void *ptr)
3337 Eina_Value_Hash *tmem = mem;
3338 const Eina_Value_Hash *desc = ptr;
3341 if ((!tmem->subtype) && (!desc->subtype))
3344 if ((tmem->hash) && (tmem->hash == desc->hash))
3346 tmem->subtype = desc->subtype;
3352 Eina_Value_Hash tmp;
3354 if (!_eina_value_type_hash_copy(type, desc, &tmp))
3357 _eina_value_type_hash_flush(type, tmem);
3358 memcpy(tmem, &tmp, sizeof(tmp));
3362 if (tmem->hash) _eina_value_type_hash_flush_elements(tmem);
3364 tmem->subtype = desc->subtype;
3365 if (!_eina_value_type_hash_create(tmem))
3372 _eina_value_type_hash_vset(const Eina_Value_Type *type, void *mem, va_list args)
3374 const Eina_Value_Hash desc = va_arg(args, Eina_Value_Hash);
3375 _eina_value_type_hash_pset(type, mem, &desc);
3380 _eina_value_type_hash_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
3382 memcpy(ptr, mem, sizeof(Eina_Value_Hash));
3386 static const Eina_Value_Type _EINA_VALUE_TYPE_HASH = {
3387 EINA_VALUE_TYPE_VERSION,
3388 sizeof(Eina_Value_Hash),
3390 _eina_value_type_hash_setup,
3391 _eina_value_type_hash_flush,
3392 _eina_value_type_hash_copy,
3393 _eina_value_type_hash_compare,
3394 _eina_value_type_hash_convert_to,
3395 NULL, /* no convert from */
3396 _eina_value_type_hash_vset,
3397 _eina_value_type_hash_pset,
3398 _eina_value_type_hash_pget
3402 _eina_value_type_timeval_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
3404 memset(mem, 0, sizeof(struct timeval));
3409 _eina_value_type_timeval_flush(const Eina_Value_Type *type __UNUSED__, void *mem __UNUSED__)
3415 _eina_value_type_timeval_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
3417 const struct timeval *s = src;
3418 struct timeval *d = dst;
3423 static inline struct timeval _eina_value_type_timeval_fix(const struct timeval *input)
3425 struct timeval ret = *input;
3426 if (EINA_UNLIKELY(ret.tv_usec < 0))
3435 _eina_value_type_timeval_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
3437 struct timeval va = _eina_value_type_timeval_fix(a);
3438 struct timeval vb = _eina_value_type_timeval_fix(b);
3440 if (va.tv_sec < vb.tv_sec)
3442 else if (va.tv_sec > vb.tv_sec)
3445 if (va.tv_usec < vb.tv_usec)
3447 else if (va.tv_usec > vb.tv_usec)
3454 _eina_value_type_timeval_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
3456 struct timeval v = _eina_value_type_timeval_fix(type_mem);
3460 if (convert == EINA_VALUE_TYPE_UCHAR)
3462 unsigned char other_mem = v.tv_sec;
3463 if (EINA_UNLIKELY(v.tv_sec < 0))
3465 if (EINA_UNLIKELY(v.tv_sec > eina_value_uchar_max))
3467 return eina_value_type_pset(convert, convert_mem, &other_mem);
3469 else if (convert == EINA_VALUE_TYPE_USHORT)
3471 unsigned short other_mem = v.tv_sec;
3472 if (EINA_UNLIKELY(v.tv_sec < 0))
3474 if (EINA_UNLIKELY(v.tv_sec > eina_value_ushort_max))
3476 return eina_value_type_pset(convert, convert_mem, &other_mem);
3478 else if (convert == EINA_VALUE_TYPE_UINT)
3480 unsigned int other_mem = v.tv_sec;
3481 if (EINA_UNLIKELY(v.tv_sec < 0))
3483 if (EINA_UNLIKELY((unsigned long) v.tv_sec > eina_value_uint_max))
3485 return eina_value_type_pset(convert, convert_mem, &other_mem);
3487 else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
3489 unsigned long other_mem = v.tv_sec;
3490 if (EINA_UNLIKELY(v.tv_sec < 0))
3492 if (EINA_UNLIKELY((sizeof(other_mem) != sizeof(v)) &&
3493 ((unsigned long)v.tv_sec > eina_value_ulong_max)))
3495 return eina_value_type_pset(convert, convert_mem, &other_mem);
3497 else if (convert == EINA_VALUE_TYPE_UINT64)
3499 uint64_t other_mem = v.tv_sec;
3500 if (EINA_UNLIKELY(v.tv_sec < 0))
3502 return eina_value_type_pset(convert, convert_mem, &other_mem);
3504 else if (convert == EINA_VALUE_TYPE_CHAR)
3506 char other_mem = v.tv_sec;
3507 if (EINA_UNLIKELY(v.tv_sec < eina_value_char_min))
3509 if (EINA_UNLIKELY(v.tv_sec > eina_value_char_max))
3511 return eina_value_type_pset(convert, convert_mem, &other_mem);
3513 else if (convert == EINA_VALUE_TYPE_SHORT)
3515 short other_mem = v.tv_sec;
3516 if (EINA_UNLIKELY(v.tv_sec < eina_value_short_min))
3518 if (EINA_UNLIKELY(v.tv_sec > eina_value_short_max))
3520 return eina_value_type_pset(convert, convert_mem, &other_mem);
3522 else if (convert == EINA_VALUE_TYPE_INT)
3524 int other_mem = v.tv_sec;
3525 if (EINA_UNLIKELY(v.tv_sec < eina_value_int_min))
3527 if (EINA_UNLIKELY(v.tv_sec > eina_value_int_max))
3529 return eina_value_type_pset(convert, convert_mem, &other_mem);
3531 else if (convert == EINA_VALUE_TYPE_LONG)
3533 long other_mem = v.tv_sec;
3534 if (EINA_UNLIKELY(v.tv_sec < eina_value_long_min))
3536 if (EINA_UNLIKELY(v.tv_sec > eina_value_long_max))
3538 return eina_value_type_pset(convert, convert_mem, &other_mem);
3540 else if (convert == EINA_VALUE_TYPE_INT64)
3542 int64_t other_mem = v.tv_sec;
3543 return eina_value_type_pset(convert, convert_mem, &other_mem);
3545 else if (convert == EINA_VALUE_TYPE_FLOAT)
3547 float other_mem = (float)v.tv_sec + (float)v.tv_usec / 1.0e6;
3548 return eina_value_type_pset(convert, convert_mem, &other_mem);
3550 else if (convert == EINA_VALUE_TYPE_DOUBLE)
3552 double other_mem = (double)v.tv_sec + (double)v.tv_usec / 1.0e6;
3553 return eina_value_type_pset(convert, convert_mem, &other_mem);
3555 else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
3556 convert == EINA_VALUE_TYPE_STRING)
3558 const char *other_mem;
3560 snprintf(buf, sizeof(buf), "%ld.%06ld", v.tv_sec, v.tv_usec);
3561 other_mem = buf; /* required due &buf == buf */
3562 return eina_value_type_pset(convert, convert_mem, &other_mem);
3566 eina_error_set(EINA_ERROR_VALUE_FAILED);
3572 _eina_value_type_timeval_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
3574 struct timeval *tmem = mem;
3575 *tmem = _eina_value_type_timeval_fix(ptr);
3580 _eina_value_type_timeval_vset(const Eina_Value_Type *type, void *mem, va_list args)
3582 const struct timeval desc = va_arg(args, struct timeval);
3583 _eina_value_type_timeval_pset(type, mem, &desc);
3588 _eina_value_type_timeval_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
3590 memcpy(ptr, mem, sizeof(struct timeval));
3594 static const Eina_Value_Type _EINA_VALUE_TYPE_TIMEVAL = {
3595 EINA_VALUE_TYPE_VERSION,
3596 sizeof(struct timeval),
3598 _eina_value_type_timeval_setup,
3599 _eina_value_type_timeval_flush,
3600 _eina_value_type_timeval_copy,
3601 _eina_value_type_timeval_compare,
3602 _eina_value_type_timeval_convert_to,
3603 NULL, /* no convert from */
3604 _eina_value_type_timeval_vset,
3605 _eina_value_type_timeval_pset,
3606 _eina_value_type_timeval_pget
3610 _eina_value_type_blob_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
3612 memset(mem, 0, sizeof(Eina_Value_Blob));
3616 static inline const Eina_Value_Blob_Operations *
3617 _eina_value_type_blob_ops_get(const Eina_Value_Blob *blob)
3619 if (!blob) return NULL;
3620 if (!blob->ops) return NULL;
3621 EINA_SAFETY_ON_FALSE_RETURN_VAL
3622 (blob->ops->version == EINA_VALUE_BLOB_OPERATIONS_VERSION, NULL);
3627 _eina_value_type_blob_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
3629 const Eina_Value_Blob_Operations *ops = _eina_value_type_blob_ops_get(mem);
3630 Eina_Value_Blob *tmem = mem;
3631 if ((ops) && (ops->free))
3632 ops->free(ops, (void *)tmem->memory, tmem->size);
3633 tmem->memory = NULL;
3639 _eina_value_type_blob_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
3641 const Eina_Value_Blob_Operations *ops = _eina_value_type_blob_ops_get(src);
3642 const Eina_Value_Blob *s = src;
3643 Eina_Value_Blob *d = dst;
3647 if ((ops) && (ops->copy))
3649 d->memory = ops->copy(ops, s->memory, s->size);
3650 if ((d->memory == NULL) && (s->size > 0))
3658 _eina_value_type_blob_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
3660 const Eina_Value_Blob_Operations *ops = _eina_value_type_blob_ops_get(a);
3661 const Eina_Value_Blob *ta = a, *tb = b;
3663 if (ta->ops != tb->ops)
3665 eina_error_set(EINA_ERROR_VALUE_FAILED);
3668 if ((ops) && (ops->compare))
3669 return ops->compare(ops, ta->memory, ta->size, tb->memory, tb->size);
3671 if (ta->size < tb->size)
3676 return memcmp(ta->memory, tb->memory, minsize);
3680 _eina_value_type_blob_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
3682 const Eina_Value_Blob *tmem = type_mem;
3685 if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
3686 convert == EINA_VALUE_TYPE_STRING)
3688 const Eina_Value_Blob_Operations *ops;
3690 const char *other_mem;
3691 Eina_Bool ret = EINA_FALSE, first = EINA_TRUE;
3692 const unsigned char *ptr, *ptr_end;
3694 ops = _eina_value_type_blob_ops_get(tmem);
3695 if ((ops) && (ops->to_string))
3697 char *x = ops->to_string(ops, tmem->memory, tmem->size);
3700 ret = eina_value_type_pset(convert, convert_mem, &x);
3706 str = eina_strbuf_new();
3710 if (!eina_strbuf_append_printf(str, "BLOB(%u, [", tmem->size))
3714 ptr_end = ptr + tmem->size;
3715 for (; ptr < ptr_end; ptr++)
3720 if (!eina_strbuf_append_printf(str, "%02hhx", *ptr))
3725 if (!eina_strbuf_append_printf(str, " %02hhx", *ptr))
3730 if (!eina_strbuf_append(str, "])"))
3733 other_mem = eina_strbuf_string_get(str);
3734 ret = eina_value_type_pset(convert, convert_mem, &other_mem);
3737 eina_strbuf_free(str);
3742 eina_error_set(EINA_ERROR_VALUE_FAILED);
3748 _eina_value_type_blob_convert_from(const Eina_Value_Type *type, const Eina_Value_Type *convert, void *type_mem, const void *convert_mem)
3750 Eina_Value_Blob desc;
3753 desc.ops = EINA_VALUE_BLOB_OPERATIONS_MALLOC;
3755 if ((convert == EINA_VALUE_TYPE_STRING) ||
3756 (convert == EINA_VALUE_TYPE_STRINGSHARE))
3758 const char *str = *(const char **)convert_mem;
3766 desc.size = strlen(str) + 1;
3767 desc.memory = buf = malloc(desc.size);
3770 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
3773 memcpy(buf, str, desc.size);
3776 else if (convert == EINA_VALUE_TYPE_ARRAY)
3778 const Eina_Value_Array *a = convert_mem;
3779 if ((!a->array) || (a->array->len == 0))
3786 desc.size = a->array->len * a->array->member_size;
3787 desc.memory = buf = malloc(desc.size);
3790 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
3793 memcpy(buf, a->array->members, desc.size);
3796 else if (convert == EINA_VALUE_TYPE_BLOB)
3798 const Eina_Value_Blob *b = convert_mem;
3806 desc.size = b->size;
3807 desc.memory = buf = malloc(desc.size);
3810 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
3813 memcpy(buf, b->memory, desc.size);
3818 desc.size = convert->value_size;
3819 desc.memory = buf = malloc(convert->value_size);
3822 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
3825 if (!eina_value_type_pget(convert, convert_mem, buf))
3831 return eina_value_type_pset(type, type_mem, &desc);
3835 _eina_value_type_blob_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
3837 const Eina_Value_Blob_Operations *ops = _eina_value_type_blob_ops_get(mem);
3838 Eina_Value_Blob *tmem = mem;
3839 const Eina_Value_Blob *desc = ptr;
3842 if ((tmem->memory) && (tmem->memory == desc->memory))
3844 tmem->ops = desc->ops;
3845 tmem->size = desc->size;
3849 if ((ops) && (ops->free))
3850 ops->free(ops, (void *)tmem->memory, tmem->size);
3857 _eina_value_type_blob_vset(const Eina_Value_Type *type, void *mem, va_list args)
3859 const Eina_Value_Blob desc = va_arg(args, Eina_Value_Blob);
3860 _eina_value_type_blob_pset(type, mem, &desc);
3865 _eina_value_type_blob_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
3867 memcpy(ptr, mem, sizeof(Eina_Value_Blob));
3871 static const Eina_Value_Type _EINA_VALUE_TYPE_BLOB = {
3872 EINA_VALUE_TYPE_VERSION,
3873 sizeof(Eina_Value_Blob),
3875 _eina_value_type_blob_setup,
3876 _eina_value_type_blob_flush,
3877 _eina_value_type_blob_copy,
3878 _eina_value_type_blob_compare,
3879 _eina_value_type_blob_convert_to,
3880 _eina_value_type_blob_convert_from,
3881 _eina_value_type_blob_vset,
3882 _eina_value_type_blob_pset,
3883 _eina_value_type_blob_pget
3887 _eina_value_struct_operations_binsearch_cmp(const void *pa, const void *pb)
3889 const Eina_Value_Struct_Member *a = pa, *b = pb;
3890 return strcmp(a->name, b->name);
3893 static const Eina_Value_Struct_Member *
3894 _eina_value_struct_operations_binsearch_find_member(const Eina_Value_Struct_Operations *ops __UNUSED__, const Eina_Value_Struct_Desc *desc, const char *name)
3896 unsigned int count = desc->member_count;
3897 Eina_Value_Struct_Member search;
3900 const Eina_Value_Struct_Member *itr = desc->members;
3901 for (; itr->name != NULL; itr++)
3906 return bsearch(&search, desc->members, count,
3907 sizeof(Eina_Value_Struct_Member),
3908 _eina_value_struct_operations_binsearch_cmp);
3911 static Eina_Value_Struct_Operations _EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH = {
3912 EINA_VALUE_STRUCT_OPERATIONS_VERSION,
3913 NULL, /* default alloc */
3914 NULL, /* default free */
3915 NULL, /* default copy */
3916 NULL, /* default compare */
3917 _eina_value_struct_operations_binsearch_find_member
3920 static const Eina_Value_Struct_Member *
3921 _eina_value_struct_operations_stringshare_find_member(const Eina_Value_Struct_Operations *ops __UNUSED__, const Eina_Value_Struct_Desc *desc, const char *name)
3923 const Eina_Value_Struct_Member *itr = desc->members;
3925 /* assumes name is stringshared.
3927 * we do this because it's the recommended usage pattern, moreover
3928 * we expect to find the member, as users shouldn't look for
3929 * non-existent members!
3931 if (desc->member_count > 0)
3933 const Eina_Value_Struct_Member *itr_end = itr + desc->member_count;
3934 for (; itr < itr_end; itr++)
3935 if (itr->name == name)
3940 for (; itr->name != NULL; itr++)
3941 if (itr->name == name)
3945 itr = desc->members;
3946 name = eina_stringshare_add(name);
3947 eina_stringshare_del(name); /* we'll not use the contents, this is fine */
3948 /* stringshare and look again */
3949 if (desc->member_count > 0)
3951 const Eina_Value_Struct_Member *itr_end = itr + desc->member_count;
3952 for (; itr < itr_end; itr++)
3953 if (itr->name == name)
3958 for (; itr->name != NULL; itr++)
3959 if (itr->name == name)
3966 static Eina_Value_Struct_Operations _EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE = {
3967 EINA_VALUE_STRUCT_OPERATIONS_VERSION,
3968 NULL, /* default alloc */
3969 NULL, /* default free */
3970 NULL, /* default copy */
3971 NULL, /* default compare */
3972 _eina_value_struct_operations_stringshare_find_member
3975 static inline const Eina_Value_Struct_Operations *
3976 _eina_value_type_struct_ops_get(const Eina_Value_Struct *st)
3978 if (!st) return NULL;
3979 if (!st->desc) return NULL;
3980 if (!st->desc->ops) return NULL;
3981 EINA_SAFETY_ON_FALSE_RETURN_VAL
3982 (st->desc->ops->version == EINA_VALUE_STRUCT_OPERATIONS_VERSION, NULL);
3983 return st->desc->ops;
3986 EAPI const Eina_Value_Struct_Member *
3987 eina_value_struct_member_find(const Eina_Value_Struct *st, const char *name)
3989 const Eina_Value_Struct_Operations *ops;
3990 const Eina_Value_Struct_Member *itr;
3992 EINA_SAFETY_ON_NULL_RETURN_VAL(st, NULL);
3993 EINA_SAFETY_ON_NULL_RETURN_VAL(st->desc, NULL);
3995 ops = _eina_value_type_struct_ops_get(st);
3996 if ((ops) && (ops->find_member))
3997 return ops->find_member(ops, st->desc, name);
3999 itr = st->desc->members;
4000 if (st->desc->member_count)
4002 const Eina_Value_Struct_Member *itr_end = itr + st->desc->member_count;
4003 for (; itr < itr_end; itr++)
4005 if (strcmp(name, itr->name) == 0)
4012 for (; itr->name != NULL; itr++)
4014 if (strcmp(name, itr->name) == 0)
4022 _eina_value_type_struct_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
4024 memset(mem, 0, sizeof(Eina_Value_Struct));
4029 _eina_value_type_struct_setup_member(const Eina_Value_Struct_Member *member, Eina_Value_Struct *st)
4031 unsigned char *base = st->memory;
4032 return eina_value_type_setup(member->type, base + member->offset);
4036 _eina_value_type_struct_flush_member(const Eina_Value_Struct_Member *member, Eina_Value_Struct *st)
4038 unsigned char *base = st->memory;
4039 return eina_value_type_flush(member->type, base + member->offset);
4043 _eina_value_type_struct_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
4045 const Eina_Value_Struct_Operations *ops;
4046 const Eina_Value_Struct_Member *itr;
4047 Eina_Value_Struct *tmem = mem;
4048 Eina_Bool ret = EINA_TRUE;
4050 if ((!tmem->desc) || (!tmem->memory))
4053 itr = tmem->desc->members;
4054 if (tmem->desc->member_count > 0)
4056 const Eina_Value_Struct_Member *itr_end;
4057 itr_end = itr + tmem->desc->member_count;
4058 for (; itr < itr_end; itr++)
4059 ret &= _eina_value_type_struct_flush_member(itr, tmem);
4063 for (; itr->name != NULL; itr++)
4064 ret &= _eina_value_type_struct_flush_member(itr, tmem);
4067 ops = _eina_value_type_struct_ops_get(mem);
4068 if ((ops) && (ops->free))
4069 ops->free(ops, tmem->desc, tmem->memory);
4073 tmem->memory = NULL;
4080 _eina_value_type_struct_copy_member(const Eina_Value_Struct_Member *member, const Eina_Value_Struct *s, Eina_Value_Struct *d)
4082 const unsigned char *base_s = s->memory;
4083 unsigned char *base_d = d->memory;
4084 return eina_value_type_copy(member->type,
4085 base_s + member->offset,
4086 base_d + member->offset);
4090 _eina_value_type_struct_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
4092 const Eina_Value_Struct_Operations *ops;
4093 const Eina_Value_Struct_Member *itr;
4094 const Eina_Value_Struct *s = src;
4095 Eina_Value_Struct *d = dst;
4099 if ((!s->desc) || (!s->memory))
4102 ops = _eina_value_type_struct_ops_get(src);
4103 if ((ops) && (ops->copy))
4105 d->memory = ops->copy(ops, s->desc, s->memory);
4106 if (d->memory == NULL)
4111 if ((ops) && (ops->alloc))
4112 d->memory = ops->alloc(ops, s->desc);
4114 d->memory = malloc(s->desc->size);
4117 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
4121 itr = s->desc->members;
4122 if (s->desc->member_count > 0)
4124 const Eina_Value_Struct_Member *itr_end = itr + s->desc->member_count;
4125 for (; itr < itr_end; itr++)
4126 if (!_eina_value_type_struct_copy_member(itr, s, d))
4131 for (; itr->name != NULL; itr++)
4132 if (!_eina_value_type_struct_copy_member(itr, s, d))
4140 for (; itr >= s->desc->members; itr--)
4141 _eina_value_type_struct_flush_member(itr, d);
4143 if ((ops) && (ops->free))
4144 ops->free(ops, s->desc, d->memory);
4151 _eina_value_type_struct_compare_member(const Eina_Value_Struct_Member *member, const Eina_Value_Struct *ta, const Eina_Value_Struct *tb)
4153 const unsigned char *base_a = ta->memory;
4154 const unsigned char *base_b = tb->memory;
4155 return eina_value_type_compare(member->type,
4156 base_a + member->offset,
4157 base_b + member->offset);
4161 _eina_value_type_struct_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
4163 const Eina_Value_Struct_Operations *ops = _eina_value_type_struct_ops_get(a);
4164 const Eina_Value_Struct *ta = a, *tb = b;
4165 const Eina_Value_Struct_Member *itr;
4168 if ((!ta->desc) && (!tb->desc))
4170 else if (ta->desc != tb->desc)
4172 eina_error_set(EINA_ERROR_VALUE_FAILED);
4175 if (ta->desc->ops != tb->desc->ops)
4177 eina_error_set(EINA_ERROR_VALUE_FAILED);
4180 if ((!ta->memory) && (!tb->memory))
4182 else if (!ta->memory)
4184 else if (!tb->memory)
4187 if ((ops) && (ops->compare))
4188 return ops->compare(ops, ta->desc, ta->memory, tb->memory);
4190 itr = ta->desc->members;
4191 if (ta->desc->member_count > 0)
4193 const Eina_Value_Struct_Member *itr_end = itr + ta->desc->member_count;
4194 for (; (cmp == 0) && (itr < itr_end); itr++)
4195 cmp = _eina_value_type_struct_compare_member(itr, ta, tb);
4199 for (; (cmp == 0) && (itr->name != NULL); itr++)
4200 cmp = _eina_value_type_struct_compare_member(itr, ta, tb);
4206 _eina_value_type_struct_convert_to_string_member(const Eina_Value_Struct *st, const Eina_Value_Struct_Member *member, Eina_Strbuf *str)
4208 const unsigned char *p = st->memory;
4209 Eina_Bool first = st->desc->members == member;
4210 Eina_Bool r = EINA_FALSE;
4212 if (first) eina_strbuf_append_printf(str, "%s: ", member->name);
4213 else eina_strbuf_append_printf(str, ", %s: ", member->name);
4215 if ((member->type) && (member->type->convert_to))
4217 const Eina_Value_Type *type = member->type;
4220 r = eina_value_type_convert_to(type, EINA_VALUE_TYPE_STRING,
4221 p + member->offset, &conv);
4224 eina_strbuf_append(str, conv);
4230 eina_strbuf_append_char(str, '?');
4234 _eina_value_type_struct_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
4236 const Eina_Value_Struct *tmem = type_mem;
4239 if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
4240 convert == EINA_VALUE_TYPE_STRING)
4242 Eina_Strbuf *str = eina_strbuf_new();
4246 if (!tmem->memory) eina_strbuf_append(str, "{}");
4249 const Eina_Value_Struct_Member *itr = tmem->desc->members;
4251 eina_strbuf_append_char(str, '{');
4253 if (tmem->desc->member_count > 0)
4255 const Eina_Value_Struct_Member *itr_end;
4257 itr_end = itr + tmem->desc->member_count;
4258 for (; itr < itr_end; itr++)
4259 _eina_value_type_struct_convert_to_string_member
4264 for (; itr->name != NULL; itr++)
4265 _eina_value_type_struct_convert_to_string_member
4269 eina_strbuf_append_char(str, '}');
4271 s = eina_strbuf_string_get(str);
4272 ret = eina_value_type_pset(convert, convert_mem, &s);
4273 eina_strbuf_free(str);
4278 eina_error_set(EINA_ERROR_VALUE_FAILED);
4284 _eina_value_type_struct_desc_check(const Eina_Value_Struct_Desc *desc)
4286 unsigned int minsize = 0;
4287 const Eina_Value_Struct_Member *itr;
4289 EINA_SAFETY_ON_NULL_RETURN_VAL(desc, EINA_FALSE);
4290 EINA_SAFETY_ON_FALSE_RETURN_VAL
4291 (desc->version == EINA_VALUE_STRUCT_DESC_VERSION, EINA_FALSE);
4293 itr = desc->members;
4294 if (desc->member_count > 0)
4296 const Eina_Value_Struct_Member *itr_end = itr + desc->member_count;
4297 for (; itr < itr_end; itr++)
4299 unsigned int member_end;
4301 EINA_SAFETY_ON_FALSE_RETURN_VAL
4302 (eina_value_type_check(itr->type), EINA_FALSE);
4303 EINA_SAFETY_ON_FALSE_RETURN_VAL
4304 (itr->type->value_size > 0, EINA_FALSE);
4306 member_end = itr->offset + itr->type->value_size;
4307 if (minsize < member_end)
4308 minsize = member_end;
4313 for (; itr->name != NULL; itr++)
4315 unsigned int member_end;
4317 EINA_SAFETY_ON_FALSE_RETURN_VAL
4318 (eina_value_type_check(itr->type), EINA_FALSE);
4319 EINA_SAFETY_ON_FALSE_RETURN_VAL
4320 (itr->type->value_size > 0, EINA_FALSE);
4322 member_end = itr->offset + itr->type->value_size;
4323 if (minsize < member_end)
4324 minsize = member_end;
4328 EINA_SAFETY_ON_FALSE_RETURN_VAL(minsize > 0, EINA_FALSE);
4329 EINA_SAFETY_ON_FALSE_RETURN_VAL(desc->size >= minsize, EINA_FALSE);
4334 _eina_value_type_struct_pset(const Eina_Value_Type *type, void *mem, const void *ptr)
4336 const Eina_Value_Struct_Operations *ops;
4337 Eina_Value_Struct *tmem = mem;
4338 const Eina_Value_Struct *desc = ptr;
4339 const Eina_Value_Struct_Member *itr;
4341 if (!_eina_value_type_struct_desc_check(desc->desc))
4343 eina_error_set(EINA_ERROR_VALUE_FAILED);
4348 if ((tmem->memory) && (tmem->memory == desc->memory))
4350 tmem->desc = desc->desc;
4356 Eina_Value_Struct tmp;
4358 if (!_eina_value_type_struct_copy(type, desc, &tmp))
4361 _eina_value_type_struct_flush(type, tmem);
4362 memcpy(tmem, &tmp, sizeof(tmp));
4366 if (tmem->memory) _eina_value_type_struct_flush(type, mem);
4368 tmem->desc = desc->desc;
4370 ops = _eina_value_type_struct_ops_get(desc);
4371 if ((ops) && (ops->alloc))
4372 tmem->memory = ops->alloc(ops, tmem->desc);
4374 tmem->memory = malloc(tmem->desc->size);
4378 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
4382 itr = tmem->desc->members;
4383 if (tmem->desc->member_count > 0)
4385 const Eina_Value_Struct_Member *itr_end;
4386 itr_end = itr + tmem->desc->member_count;
4387 for (; itr < itr_end; itr++)
4388 if (!_eina_value_type_struct_setup_member(itr, tmem))
4393 for (; itr->name != NULL; itr++)
4394 if (!_eina_value_type_struct_setup_member(itr, tmem))
4402 for (; itr >= tmem->desc->members; itr--)
4403 _eina_value_type_struct_flush_member(itr, tmem);
4405 if ((ops) && (ops->free))
4406 ops->free(ops, tmem->desc, tmem->memory);
4409 tmem->memory = NULL;
4415 _eina_value_type_struct_vset(const Eina_Value_Type *type, void *mem, va_list args)
4417 const Eina_Value_Struct desc = va_arg(args, Eina_Value_Struct);
4418 _eina_value_type_struct_pset(type, mem, &desc);
4423 _eina_value_type_struct_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
4425 memcpy(ptr, mem, sizeof(Eina_Value_Struct));
4429 static const Eina_Value_Type _EINA_VALUE_TYPE_STRUCT = {
4430 EINA_VALUE_TYPE_VERSION,
4431 sizeof(Eina_Value_Struct),
4432 "Eina_Value_Struct",
4433 _eina_value_type_struct_setup,
4434 _eina_value_type_struct_flush,
4435 _eina_value_type_struct_copy,
4436 _eina_value_type_struct_compare,
4437 _eina_value_type_struct_convert_to,
4438 NULL, /* no convert from */
4439 _eina_value_type_struct_vset,
4440 _eina_value_type_struct_pset,
4441 _eina_value_type_struct_pget
4446 _eina_value_type_model_setup(const Eina_Value_Type *type __UNUSED__, void *mem)
4448 Eina_Model **tmem = mem;
4454 _eina_value_type_model_flush(const Eina_Value_Type *type __UNUSED__, void *mem)
4456 Eina_Model **tmem = mem;
4459 eina_model_unref(*tmem);
4466 _eina_value_type_model_copy(const Eina_Value_Type *type __UNUSED__, const void *src, void *dst)
4468 const Eina_Model * const *s = src;
4469 Eina_Model **d = dst;
4471 *d = eina_model_copy(*s); // is it better to deep-copy?
4478 _eina_value_type_model_compare(const Eina_Value_Type *type __UNUSED__, const void *a, const void *b)
4480 const Eina_Model * const *ta = a;
4481 const Eina_Model * const *tb = b;
4483 if ((!*ta) && (!*tb)) return 0;
4484 else if (!*ta) return 1;
4485 else if (!*tb) return -1;
4486 else return eina_model_compare(*ta, *tb);
4490 _eina_value_type_model_convert_to(const Eina_Value_Type *type __UNUSED__, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
4492 const Eina_Model *v = *(const Eina_Model **)type_mem;
4496 if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
4497 convert == EINA_VALUE_TYPE_STRING)
4499 char *other_mem = v ? eina_model_to_string(v) : NULL;
4500 Eina_Bool ret = eina_value_type_pset(convert, convert_mem, &other_mem);
4506 eina_error_set(EINA_ERROR_VALUE_FAILED);
4514 _eina_value_type_model_vset(const Eina_Value_Type *type __UNUSED__, void *mem, va_list args)
4516 Eina_Model **tmem = mem, *tmp;
4518 tmp = va_arg(args, Eina_Model *);
4520 if (tmp) eina_model_ref(tmp);
4521 if (*tmem) eina_model_unref(*tmem);
4529 _eina_value_type_model_pset(const Eina_Value_Type *type __UNUSED__, void *mem, const void *ptr)
4531 Eina_Model **tmem = mem;
4532 Eina_Model **p = (Eina_Model **)ptr;
4535 if (*tmem == *p) return EINA_TRUE;
4537 if (*p) eina_model_ref(*p);
4538 if (*tmem) eina_model_unref(*tmem);
4546 _eina_value_type_model_pget(const Eina_Value_Type *type __UNUSED__, const void *mem, void *ptr)
4548 Eina_Model **tmem = (Eina_Model **)mem;
4549 Eina_Model **p = ptr;
4554 static const Eina_Value_Type _EINA_VALUE_TYPE_MODEL = {
4555 EINA_VALUE_TYPE_VERSION,
4556 sizeof(Eina_Model *),
4558 _eina_value_type_model_setup,
4559 _eina_value_type_model_flush,
4560 _eina_value_type_model_copy,
4561 _eina_value_type_model_compare,
4562 _eina_value_type_model_convert_to,
4563 NULL, // no convert from
4564 _eina_value_type_model_vset,
4565 _eina_value_type_model_pset,
4566 _eina_value_type_model_pget
4570 /* keep all basic types inlined in an array so we can compare if it's
4571 * a basic type using pointer arithmetic.
4573 * NOTE-1: JUST BASIC TYPES, DO NOT ADD MORE TYPES HERE!!!
4574 * NOTE-2: KEEP ORDER, see eina_value_init()
4576 static const Eina_Value_Type _EINA_VALUE_TYPE_BASICS[] = {
4578 EINA_VALUE_TYPE_VERSION,
4579 sizeof(unsigned char),
4581 _eina_value_type_uchar_setup,
4582 _eina_value_type_uchar_flush,
4583 _eina_value_type_uchar_copy,
4584 _eina_value_type_uchar_compare,
4585 _eina_value_type_uchar_convert_to,
4586 NULL, /* no convert from */
4587 _eina_value_type_uchar_vset,
4588 _eina_value_type_uchar_pset,
4589 _eina_value_type_uchar_pget
4592 EINA_VALUE_TYPE_VERSION,
4593 sizeof(unsigned short),
4595 _eina_value_type_ushort_setup,
4596 _eina_value_type_ushort_flush,
4597 _eina_value_type_ushort_copy,
4598 _eina_value_type_ushort_compare,
4599 _eina_value_type_ushort_convert_to,
4600 NULL, /* no convert from */
4601 _eina_value_type_ushort_vset,
4602 _eina_value_type_ushort_pset,
4603 _eina_value_type_ushort_pget
4606 EINA_VALUE_TYPE_VERSION,
4607 sizeof(unsigned int),
4609 _eina_value_type_uint_setup,
4610 _eina_value_type_uint_flush,
4611 _eina_value_type_uint_copy,
4612 _eina_value_type_uint_compare,
4613 _eina_value_type_uint_convert_to,
4614 NULL, /* no convert from */
4615 _eina_value_type_uint_vset,
4616 _eina_value_type_uint_pset,
4617 _eina_value_type_uint_pget
4620 EINA_VALUE_TYPE_VERSION,
4621 sizeof(unsigned long),
4623 _eina_value_type_ulong_setup,
4624 _eina_value_type_ulong_flush,
4625 _eina_value_type_ulong_copy,
4626 _eina_value_type_ulong_compare,
4627 _eina_value_type_ulong_convert_to,
4628 NULL, /* no convert from */
4629 _eina_value_type_ulong_vset,
4630 _eina_value_type_ulong_pset,
4631 _eina_value_type_ulong_pget
4634 EINA_VALUE_TYPE_VERSION,
4637 _eina_value_type_uint64_setup,
4638 _eina_value_type_uint64_flush,
4639 _eina_value_type_uint64_copy,
4640 _eina_value_type_uint64_compare,
4641 _eina_value_type_uint64_convert_to,
4642 NULL, /* no convert from */
4643 _eina_value_type_uint64_vset,
4644 _eina_value_type_uint64_pset,
4645 _eina_value_type_uint64_pget
4648 EINA_VALUE_TYPE_VERSION,
4651 _eina_value_type_char_setup,
4652 _eina_value_type_char_flush,
4653 _eina_value_type_char_copy,
4654 _eina_value_type_char_compare,
4655 _eina_value_type_char_convert_to,
4656 NULL, /* no convert from */
4657 _eina_value_type_char_vset,
4658 _eina_value_type_char_pset,
4659 _eina_value_type_char_pget
4662 EINA_VALUE_TYPE_VERSION,
4665 _eina_value_type_short_setup,
4666 _eina_value_type_short_flush,
4667 _eina_value_type_short_copy,
4668 _eina_value_type_short_compare,
4669 _eina_value_type_short_convert_to,
4670 NULL, /* no convert from */
4671 _eina_value_type_short_vset,
4672 _eina_value_type_short_pset,
4673 _eina_value_type_short_pget
4676 EINA_VALUE_TYPE_VERSION,
4679 _eina_value_type_int_setup,
4680 _eina_value_type_int_flush,
4681 _eina_value_type_int_copy,
4682 _eina_value_type_int_compare,
4683 _eina_value_type_int_convert_to,
4684 NULL, /* no convert from */
4685 _eina_value_type_int_vset,
4686 _eina_value_type_int_pset,
4687 _eina_value_type_int_pget
4690 EINA_VALUE_TYPE_VERSION,
4693 _eina_value_type_long_setup,
4694 _eina_value_type_long_flush,
4695 _eina_value_type_long_copy,
4696 _eina_value_type_long_compare,
4697 _eina_value_type_long_convert_to,
4698 NULL, /* no convert from */
4699 _eina_value_type_long_vset,
4700 _eina_value_type_long_pset,
4701 _eina_value_type_long_pget
4704 EINA_VALUE_TYPE_VERSION,
4707 _eina_value_type_int64_setup,
4708 _eina_value_type_int64_flush,
4709 _eina_value_type_int64_copy,
4710 _eina_value_type_int64_compare,
4711 _eina_value_type_int64_convert_to,
4712 NULL, /* no convert from */
4713 _eina_value_type_int64_vset,
4714 _eina_value_type_int64_pset,
4715 _eina_value_type_int64_pget
4718 EINA_VALUE_TYPE_VERSION,
4721 _eina_value_type_float_setup,
4722 _eina_value_type_float_flush,
4723 _eina_value_type_float_copy,
4724 _eina_value_type_float_compare,
4725 _eina_value_type_float_convert_to,
4726 NULL, /* no convert from */
4727 _eina_value_type_float_vset,
4728 _eina_value_type_float_pset,
4729 _eina_value_type_float_pget
4732 EINA_VALUE_TYPE_VERSION,
4735 _eina_value_type_double_setup,
4736 _eina_value_type_double_flush,
4737 _eina_value_type_double_copy,
4738 _eina_value_type_double_compare,
4739 _eina_value_type_double_convert_to,
4740 NULL, /* no convert from */
4741 _eina_value_type_double_vset,
4742 _eina_value_type_double_pset,
4743 _eina_value_type_double_pget
4746 EINA_VALUE_TYPE_VERSION,
4747 sizeof(const char *),
4749 _eina_value_type_string_common_setup,
4750 _eina_value_type_stringshare_flush,
4751 _eina_value_type_stringshare_copy,
4752 _eina_value_type_string_common_compare,
4753 _eina_value_type_string_common_convert_to,
4754 NULL, /* no convert from */
4755 _eina_value_type_stringshare_vset,
4756 _eina_value_type_stringshare_pset,
4757 _eina_value_type_string_common_pget
4760 EINA_VALUE_TYPE_VERSION,
4763 _eina_value_type_string_common_setup,
4764 _eina_value_type_string_flush,
4765 _eina_value_type_string_copy,
4766 _eina_value_type_string_common_compare,
4767 _eina_value_type_string_common_convert_to,
4768 NULL, /* no convert from */
4769 _eina_value_type_string_vset,
4770 _eina_value_type_string_pset,
4771 _eina_value_type_string_common_pget
4774 EINA_VALUE_TYPE_VERSION,
4775 sizeof(unsigned long),
4777 _eina_value_type_ulong_setup,
4778 _eina_value_type_ulong_flush,
4779 _eina_value_type_ulong_copy,
4780 _eina_value_type_ulong_compare,
4781 _eina_value_type_ulong_convert_to,
4782 NULL, /* no convert from */
4783 _eina_value_type_ulong_vset,
4784 _eina_value_type_ulong_pset,
4785 _eina_value_type_ulong_pget
4790 _eina_value_blob_operations_malloc_free(const Eina_Value_Blob_Operations *ops __UNUSED__, void *memory, size_t size __UNUSED__)
4796 _eina_value_blob_operations_malloc_copy(const Eina_Value_Blob_Operations *ops __UNUSED__, const void *memory, size_t size)
4798 void *ret = malloc(size);
4801 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
4804 memcpy(ret, memory, size);
4808 static const Eina_Value_Blob_Operations _EINA_VALUE_BLOB_OPERATIONS_MALLOC = {
4809 EINA_VALUE_BLOB_OPERATIONS_VERSION,
4810 _eina_value_blob_operations_malloc_free,
4811 _eina_value_blob_operations_malloc_copy,
4816 typedef struct _Eina_Value_Inner_Mp Eina_Value_Inner_Mp;
4817 struct _Eina_Value_Inner_Mp
4819 Eina_Mempool *mempool;
4827 static const char EINA_ERROR_VALUE_FAILED_STR[] = "Value check failed.";
4833 _eina_value_inner_mp_dispose(int size, Eina_Value_Inner_Mp *imp)
4835 EINA_SAFETY_ON_FALSE_RETURN(imp->references == 0);
4837 eina_hash_del_by_key(_eina_value_inner_mps, &size);
4838 eina_mempool_del(imp->mempool);
4842 static inline Eina_Value_Inner_Mp *
4843 _eina_value_inner_mp_get(int size)
4845 Eina_Value_Inner_Mp *imp = eina_hash_find(_eina_value_inner_mps, &size);
4846 if (imp) return imp;
4848 imp = malloc(sizeof(Eina_Value_Inner_Mp));
4852 imp->references = 0;
4854 imp->mempool = eina_mempool_add(_eina_value_mp_choice,
4855 "Eina_Value_Inner_Mp", NULL, size, 128);
4862 if (!eina_hash_add(_eina_value_inner_mps, &size, imp))
4864 eina_mempool_del(imp->mempool);
4872 static inline void *
4873 _eina_value_inner_alloc_internal(int size)
4875 Eina_Value_Inner_Mp *imp;
4878 imp = _eina_value_inner_mp_get(size);
4879 if (!imp) return NULL;
4881 mem = eina_mempool_malloc(imp->mempool, size);
4882 if (mem) imp->references++;
4883 else if (imp->references == 0) _eina_value_inner_mp_dispose(size, imp);
4889 _eina_value_inner_free_internal(int size, void *mem)
4891 Eina_Value_Inner_Mp *imp = eina_hash_find(_eina_value_inner_mps, &size);
4892 EINA_SAFETY_ON_NULL_RETURN(imp);
4894 eina_mempool_free(imp->mempool, mem);
4897 if (imp->references > 0) return;
4898 _eina_value_inner_mp_dispose(size, imp);
4902 eina_value_inner_alloc(size_t size)
4906 if (size > 256) return malloc(size);
4908 eina_lock_take(&_eina_value_inner_mps_lock);
4909 mem = _eina_value_inner_alloc_internal(size);
4910 eina_lock_release(&_eina_value_inner_mps_lock);
4916 eina_value_inner_free(size_t size, void *mem)
4924 eina_lock_take(&_eina_value_inner_mps_lock);
4925 _eina_value_inner_free_internal(size, mem);
4926 eina_lock_release(&_eina_value_inner_mps_lock);
4931 * @brief Initialize the value module.
4933 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
4935 * This function sets up the value module of Eina. It is called
4941 eina_value_init(void)
4943 const char *choice, *tmp;
4945 _eina_value_log_dom = eina_log_domain_register("eina_value",
4946 EINA_LOG_COLOR_DEFAULT);
4947 if (_eina_value_log_dom < 0)
4949 EINA_LOG_ERR("Could not register log domain: eina_value");
4953 #ifdef EINA_DEFAULT_MEMPOOL
4954 choice = "pass_through";
4956 choice = "chained_mempool";
4958 tmp = getenv("EINA_MEMPOOL");
4963 _eina_value_mp_choice = strdup(choice);
4965 _eina_value_mp = eina_mempool_add
4966 (_eina_value_mp_choice, "value", NULL, sizeof(Eina_Value), 320);
4967 if (!_eina_value_mp)
4969 ERR("Mempool for value cannot be allocated in value init.");
4970 goto on_init_fail_mp;
4973 if (!eina_lock_new(&_eina_value_inner_mps_lock))
4975 ERR("Cannot create lock in value init.");
4976 goto on_init_fail_lock;
4978 _eina_value_inner_mps = eina_hash_int32_new(NULL);
4979 if (!_eina_value_inner_mps)
4981 ERR("Cannot create hash for inner mempools in value init.");
4982 goto on_init_fail_hash;
4985 EINA_ERROR_VALUE_FAILED = eina_error_msg_static_register(
4986 EINA_ERROR_VALUE_FAILED_STR);
4988 EINA_VALUE_TYPE_UCHAR = _EINA_VALUE_TYPE_BASICS + 0;
4989 EINA_VALUE_TYPE_USHORT = _EINA_VALUE_TYPE_BASICS + 1;
4990 EINA_VALUE_TYPE_UINT = _EINA_VALUE_TYPE_BASICS + 2;
4991 EINA_VALUE_TYPE_ULONG = _EINA_VALUE_TYPE_BASICS + 3;
4992 EINA_VALUE_TYPE_UINT64 = _EINA_VALUE_TYPE_BASICS + 4;
4993 EINA_VALUE_TYPE_CHAR = _EINA_VALUE_TYPE_BASICS + 5;
4994 EINA_VALUE_TYPE_SHORT = _EINA_VALUE_TYPE_BASICS + 6;
4995 EINA_VALUE_TYPE_INT = _EINA_VALUE_TYPE_BASICS + 7;
4996 EINA_VALUE_TYPE_LONG = _EINA_VALUE_TYPE_BASICS + 8;
4997 EINA_VALUE_TYPE_INT64 = _EINA_VALUE_TYPE_BASICS + 9;
4998 EINA_VALUE_TYPE_FLOAT = _EINA_VALUE_TYPE_BASICS + 10;
4999 EINA_VALUE_TYPE_DOUBLE = _EINA_VALUE_TYPE_BASICS + 11;
5000 EINA_VALUE_TYPE_STRINGSHARE = _EINA_VALUE_TYPE_BASICS + 12;
5001 EINA_VALUE_TYPE_STRING = _EINA_VALUE_TYPE_BASICS + 13;
5002 EINA_VALUE_TYPE_TIMESTAMP = _EINA_VALUE_TYPE_BASICS + 14;
5004 _EINA_VALUE_TYPE_BASICS_START = _EINA_VALUE_TYPE_BASICS + 0;
5005 _EINA_VALUE_TYPE_BASICS_END = _EINA_VALUE_TYPE_BASICS + 14;
5007 EINA_SAFETY_ON_FALSE_RETURN_VAL((sizeof(_EINA_VALUE_TYPE_BASICS)/sizeof(_EINA_VALUE_TYPE_BASICS[0])) == 15, EINA_FALSE);
5010 EINA_VALUE_TYPE_ARRAY = &_EINA_VALUE_TYPE_ARRAY;
5011 EINA_VALUE_TYPE_LIST = &_EINA_VALUE_TYPE_LIST;
5012 EINA_VALUE_TYPE_HASH = &_EINA_VALUE_TYPE_HASH;
5013 EINA_VALUE_TYPE_TIMEVAL = &_EINA_VALUE_TYPE_TIMEVAL;
5014 EINA_VALUE_TYPE_BLOB = &_EINA_VALUE_TYPE_BLOB;
5015 EINA_VALUE_TYPE_STRUCT = &_EINA_VALUE_TYPE_STRUCT;
5017 EINA_VALUE_TYPE_MODEL = &_EINA_VALUE_TYPE_MODEL;
5020 EINA_VALUE_BLOB_OPERATIONS_MALLOC = &_EINA_VALUE_BLOB_OPERATIONS_MALLOC;
5022 EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH = &_EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH;
5023 EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE = &_EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE;
5028 eina_lock_free(&_eina_value_inner_mps_lock);
5030 eina_mempool_del(_eina_value_mp);
5032 free(_eina_value_mp_choice);
5033 _eina_value_mp_choice = NULL;
5034 eina_log_domain_unregister(_eina_value_log_dom);
5035 _eina_value_log_dom = -1;
5041 * @brief Shut down the value module.
5043 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
5045 * This function shuts down the value module set up by
5046 * eina_value_init(). It is called by eina_shutdown().
5048 * @see eina_shutdown()
5051 eina_value_shutdown(void)
5053 eina_lock_take(&_eina_value_inner_mps_lock);
5054 if (eina_hash_population(_eina_value_inner_mps) != 0)
5055 ERR("Cannot free eina_value internal memory pools -- still in use!");
5057 eina_hash_free(_eina_value_inner_mps);
5058 eina_lock_release(&_eina_value_inner_mps_lock);
5059 eina_lock_free(&_eina_value_inner_mps_lock);
5061 free(_eina_value_mp_choice);
5062 _eina_value_mp_choice = NULL;
5063 eina_mempool_del(_eina_value_mp);
5064 eina_log_domain_unregister(_eina_value_log_dom);
5065 _eina_value_log_dom = -1;
5069 /*============================================================================*
5071 *============================================================================*/
5073 /*============================================================================*
5075 *============================================================================*/
5077 EAPI const Eina_Value_Type *_EINA_VALUE_TYPE_BASICS_START = NULL;
5078 EAPI const Eina_Value_Type *_EINA_VALUE_TYPE_BASICS_END = NULL;
5080 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_UCHAR = NULL;
5081 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_USHORT = NULL;
5082 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_UINT = NULL;
5083 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_ULONG = NULL;
5084 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_TIMESTAMP = NULL;
5085 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_UINT64 = NULL;
5086 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_CHAR = NULL;
5087 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_SHORT = NULL;
5088 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_INT = NULL;
5089 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_LONG = NULL;
5090 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_INT64 = NULL;
5091 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_FLOAT = NULL;
5092 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_DOUBLE = NULL;
5093 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_STRINGSHARE = NULL;
5094 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_STRING = NULL;
5095 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_ARRAY = NULL;
5096 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_LIST = NULL;
5097 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_HASH = NULL;
5098 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_TIMEVAL = NULL;
5099 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_BLOB = NULL;
5100 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_STRUCT = NULL;
5102 EAPI const Eina_Value_Type *EINA_VALUE_TYPE_MODEL = NULL;
5105 EAPI const Eina_Value_Blob_Operations *EINA_VALUE_BLOB_OPERATIONS_MALLOC = NULL;
5107 EAPI const Eina_Value_Struct_Operations *EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH = NULL;
5108 EAPI const Eina_Value_Struct_Operations *EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE = NULL;
5110 EAPI Eina_Error EINA_ERROR_VALUE_FAILED = 0;
5112 EAPI const unsigned int eina_prime_table[] =
5114 17, 31, 61, 127, 257, 509, 1021,
5115 2053, 4093, 8191, 16381, 32771, 65537, 131071, 262147, 524287, 1048573,
5116 2097143, 4194301, 8388617, 16777213
5120 eina_value_new(const Eina_Value_Type *type)
5122 Eina_Value *value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
5125 eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
5128 if (!eina_value_setup(value, type))
5137 eina_value_free(Eina_Value *value)
5139 EINA_SAFETY_ON_NULL_RETURN(value);
5140 eina_value_flush(value);
5141 eina_mempool_free(_eina_value_mp, value);
5146 eina_value_copy(const Eina_Value *value, Eina_Value *copy)
5148 const Eina_Value_Type *type;
5153 EINA_SAFETY_ON_NULL_RETURN_VAL(value, EINA_FALSE);
5154 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(value->type),
5156 EINA_SAFETY_ON_NULL_RETURN_VAL(copy, EINA_FALSE);
5157 EINA_SAFETY_ON_NULL_RETURN_VAL(value->type->copy, EINA_FALSE);
5160 if (!eina_value_setup(copy, type))
5163 src = eina_value_memory_get(value);
5164 dst = eina_value_memory_get(copy);
5165 ret = type->copy(type, src, dst);
5167 eina_value_flush(copy);
5173 eina_value_convert(const Eina_Value *value, Eina_Value *convert)
5175 Eina_Bool ret = EINA_FALSE;
5176 const Eina_Value_Type *type, *convert_type;
5177 const void *type_mem;
5180 EINA_SAFETY_ON_NULL_RETURN_VAL(value, EINA_FALSE);
5181 EINA_SAFETY_ON_NULL_RETURN_VAL(convert, EINA_FALSE);
5182 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(value->type),
5184 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(convert->type),
5188 convert_type = convert->type;
5190 type_mem = eina_value_memory_get(value);
5191 convert_mem = eina_value_memory_get(convert);
5193 if (type->convert_to)
5194 ret = type->convert_to(type, convert_type, type_mem, convert_mem);
5196 if ((!ret) && (convert_type->convert_from))
5197 ret = convert_type->convert_from(convert_type, type, convert_mem,
5204 eina_value_to_string(const Eina_Value *value)
5208 EINA_SAFETY_ON_NULL_RETURN_VAL(value, NULL);
5209 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(value->type), NULL);
5211 if (!eina_value_setup(&tmp, EINA_VALUE_TYPE_STRING))
5213 if (!eina_value_convert(value, &tmp))
5216 return tmp.value.ptr; /* steal value */
5220 eina_value_array_new(const Eina_Value_Type *subtype, unsigned int step)
5224 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(subtype), EINA_FALSE);
5226 value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
5230 if (!eina_value_array_setup(value, subtype, step))
5232 eina_mempool_free(_eina_value_mp, value);
5240 eina_value_list_new(const Eina_Value_Type *subtype)
5244 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(subtype), EINA_FALSE);
5246 value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
5250 if (!eina_value_list_setup(value, subtype))
5252 eina_mempool_free(_eina_value_mp, value);
5260 eina_value_hash_new(const Eina_Value_Type *subtype, unsigned int buckets_power_size)
5264 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(subtype), EINA_FALSE);
5266 value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
5270 if (!eina_value_hash_setup(value, subtype, buckets_power_size))
5272 eina_mempool_free(_eina_value_mp, value);
5280 eina_value_struct_new(const Eina_Value_Struct_Desc *desc)
5284 value = eina_mempool_malloc(_eina_value_mp, sizeof(Eina_Value));;
5288 if (!eina_value_struct_setup(value, desc))
5290 eina_mempool_free(_eina_value_mp, value);
5298 eina_value_type_check(const Eina_Value_Type *type)
5300 EINA_SAFETY_ON_NULL_RETURN_VAL(type, EINA_FALSE);
5301 return type->version == EINA_VALUE_TYPE_VERSION;
5305 eina_value_type_name_get(const Eina_Value_Type *type)
5307 EINA_SAFETY_ON_FALSE_RETURN_VAL(eina_value_type_check(type), NULL);