summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2017-09-11 03:52:47 +0200
committerCedric BAIL <cedric@osg.samsung.com>2017-09-12 17:03:49 -0700
commit966577ffedec4f1d92265a7c17b1e633c345eb09 (patch)
treec0a471a0fa47da2addd25cb787c838420225d826
parentda7876a9b80f6fb96f642612d115345254a617d9 (diff)
eina: add an Eina_Value helper for Eina_Rectangle.
-rw-r--r--configure.ac3
-rw-r--r--src/lib/eina/eina_value.c119
-rw-r--r--src/lib/eina/eina_value.h9
3 files changed, 130 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 2d4e048..c202d0d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -969,6 +969,7 @@ case "$host_os" in
969 [ 969 [
970 have_socket="yes" 970 have_socket="yes"
971 requirement_socket="-lsocket" 971 requirement_socket="-lsocket"
972 requirement_nsl="-lnsl"
972 ], 973 ],
973 [have_socket="no"]) 974 [have_socket="no"])
974 ;; 975 ;;
@@ -3119,7 +3120,7 @@ fi
3119AM_CONDITIONAL([EFL_NET_CONTROL_BACKEND_CONNMAN], [test "${EFL_NET_CONTROL_BACKEND}" = "connman"]) 3120AM_CONDITIONAL([EFL_NET_CONTROL_BACKEND_CONNMAN], [test "${EFL_NET_CONTROL_BACKEND}" = "connman"])
3120AM_CONDITIONAL([EFL_NET_CONTROL_BACKEND_NONE], [test "${EFL_NET_CONTROL_BACKEND}" = "none"]) 3121AM_CONDITIONAL([EFL_NET_CONTROL_BACKEND_NONE], [test "${EFL_NET_CONTROL_BACKEND}" = "none"])
3121 3122
3122EFL_ADD_LIBS([ECORE_CON], [-lm]) 3123EFL_ADD_LIBS([ECORE_CON], [${requirement_nsl} -lm])
3123 3124
3124EFL_OPTIONAL_DEPEND_PKG([ECORE_CON], [${want_systemd}], [SYSTEMD], [libsystemd]) 3125EFL_OPTIONAL_DEPEND_PKG([ECORE_CON], [${want_systemd}], [SYSTEMD], [libsystemd])
3125 3126
diff --git a/src/lib/eina/eina_value.c b/src/lib/eina/eina_value.c
index 22b3f50..1fa84de 100644
--- a/src/lib/eina/eina_value.c
+++ b/src/lib/eina/eina_value.c
@@ -36,6 +36,7 @@
36#include "eina_mempool.h" 36#include "eina_mempool.h"
37#include "eina_lock.h" 37#include "eina_lock.h"
38#include "eina_file.h" 38#include "eina_file.h"
39#include "eina_rectangle.h"
39 40
40/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ 41/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
41#include "eina_safety_checks.h" 42#include "eina_safety_checks.h"
@@ -4782,6 +4783,122 @@ EAPI const Eina_Value_Type _EINA_VALUE_TYPE_FILE = {
4782 _eina_value_type_file_pget 4783 _eina_value_type_file_pget
4783}; 4784};
4784 4785
4786static Eina_Bool
4787_eina_value_type_rectangle_setup(const Eina_Value_Type *type EINA_UNUSED, void *mem)
4788{
4789 memset(mem, 0, sizeof(Eina_Rectangle));
4790 return EINA_TRUE;
4791}
4792
4793static Eina_Bool
4794_eina_value_type_rectangle_flush(const Eina_Value_Type *type EINA_UNUSED,
4795 void *mem EINA_UNUSED)
4796{
4797 return EINA_TRUE;
4798}
4799
4800static Eina_Bool
4801_eina_value_type_rectangle_copy(const Eina_Value_Type *type EINA_UNUSED, const void *src, void *dst)
4802{
4803 memcpy(dst, src, sizeof (Eina_Rectangle));
4804
4805 return EINA_TRUE;
4806}
4807
4808static int
4809_eina_value_type_rectangle_compare(const Eina_Value_Type *type EINA_UNUSED, const void *a, const void *b)
4810{
4811 const Eina_Rectangle *ra = a;
4812 const Eina_Rectangle *rb = b;
4813
4814 if (eina_rectangle_equal(ra, rb)) return 0;
4815 return -1;
4816}
4817
4818static Eina_Bool
4819_eina_value_type_rectangle_convert_to(const Eina_Value_Type *type EINA_UNUSED, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
4820{
4821 const Eina_Rectangle *tr = type_mem;
4822 Eina_Bool ret = EINA_FALSE;
4823
4824 if ((convert == EINA_VALUE_TYPE_STRING) ||
4825 (convert == EINA_VALUE_TYPE_STRINGSHARE))
4826 {
4827 Eina_Strbuf *buf;
4828 const char *str;
4829
4830 buf = eina_strbuf_new();
4831 eina_strbuf_append_printf(buf, "[ %i, %i, %i, %i ]",
4832 tr->x, tr->y, tr->w, tr->h);
4833 str = eina_strbuf_string_get(buf);
4834 ret = eina_value_type_pset(convert, convert_mem, &str);
4835 }
4836
4837 return ret;
4838}
4839
4840static Eina_Bool
4841_eina_value_type_rectangle_convert_from(const Eina_Value_Type *type EINA_UNUSED, const Eina_Value_Type *convert, void *type_mem, const void *convert_mem)
4842{
4843 Eina_Rectangle *r = type_mem;
4844
4845 if ((convert == EINA_VALUE_TYPE_STRING) ||
4846 (convert == EINA_VALUE_TYPE_STRINGSHARE))
4847 {
4848 const char *buf = *(const char **)convert_mem;
4849 int ret;
4850
4851 ret = sscanf(buf, "[ %i, %i, %i, %i ]",
4852 &r->x, &r->y, &r->w, &r->h);
4853
4854 if (ret <= 0) return EINA_FALSE;
4855 return EINA_TRUE;
4856 }
4857
4858 return EINA_FALSE;
4859}
4860
4861static Eina_Bool
4862_eina_value_type_rectangle_pset(const Eina_Value_Type *type EINA_UNUSED, void *mem, const void *ptr)
4863{
4864 const Eina_Rectangle *r = ptr;
4865 Eina_Rectangle *tr = mem;
4866
4867 *tr = *r;
4868 return EINA_TRUE;
4869}
4870
4871static Eina_Bool
4872_eina_value_type_rectangle_vset(const Eina_Value_Type *type, void *mem, va_list args)
4873{
4874 const Eina_Rectangle *r = va_arg(args, Eina_Rectangle *);
4875 return _eina_value_type_rectangle_pset(type, mem, r);
4876}
4877
4878static Eina_Bool
4879_eina_value_type_rectangle_pget(const Eina_Value_Type *type EINA_UNUSED, const void *mem, void *ptr)
4880{
4881 const Eina_Rectangle *tr = mem;
4882
4883 memcpy(ptr, &tr, sizeof (void*));
4884 return EINA_TRUE;
4885}
4886
4887EAPI const Eina_Value_Type _EINA_VALUE_TYPE_RECTANGLE = {
4888 EINA_VALUE_TYPE_VERSION,
4889 sizeof (Eina_Rectangle),
4890 "Eina_Value_Rectangle",
4891 _eina_value_type_rectangle_setup,
4892 _eina_value_type_rectangle_flush,
4893 _eina_value_type_rectangle_copy,
4894 _eina_value_type_rectangle_compare,
4895 _eina_value_type_rectangle_convert_to,
4896 _eina_value_type_rectangle_convert_from,
4897 _eina_value_type_rectangle_vset,
4898 _eina_value_type_rectangle_pset,
4899 _eina_value_type_rectangle_pget
4900};
4901
4785/* keep all basic types inlined in an array so we can compare if it's 4902/* keep all basic types inlined in an array so we can compare if it's
4786 * a basic type using pointer arithmetic. 4903 * a basic type using pointer arithmetic.
4787 * 4904 *
@@ -5236,6 +5353,7 @@ eina_value_init(void)
5236 5353
5237 EINA_VALUE_TYPE_OPTIONAL = &_EINA_VALUE_TYPE_OPTIONAL; 5354 EINA_VALUE_TYPE_OPTIONAL = &_EINA_VALUE_TYPE_OPTIONAL;
5238 EINA_VALUE_TYPE_FILE = &_EINA_VALUE_TYPE_FILE; 5355 EINA_VALUE_TYPE_FILE = &_EINA_VALUE_TYPE_FILE;
5356 EINA_VALUE_TYPE_RECTANGLE = &_EINA_VALUE_TYPE_RECTANGLE;
5239 5357
5240 EINA_VALUE_BLOB_OPERATIONS_MALLOC = &_EINA_VALUE_BLOB_OPERATIONS_MALLOC; 5358 EINA_VALUE_BLOB_OPERATIONS_MALLOC = &_EINA_VALUE_BLOB_OPERATIONS_MALLOC;
5241 5359
@@ -5325,6 +5443,7 @@ EAPI const Eina_Value_Type *EINA_VALUE_TYPE_BLOB = NULL;
5325EAPI const Eina_Value_Type *EINA_VALUE_TYPE_STRUCT = NULL; 5443EAPI const Eina_Value_Type *EINA_VALUE_TYPE_STRUCT = NULL;
5326EAPI const Eina_Value_Type *EINA_VALUE_TYPE_OPTIONAL = NULL; 5444EAPI const Eina_Value_Type *EINA_VALUE_TYPE_OPTIONAL = NULL;
5327EAPI const Eina_Value_Type *EINA_VALUE_TYPE_FILE = NULL; 5445EAPI const Eina_Value_Type *EINA_VALUE_TYPE_FILE = NULL;
5446EAPI const Eina_Value_Type *EINA_VALUE_TYPE_RECTANGLE = NULL;
5328 5447
5329 5448
5330EAPI const Eina_Value_Blob_Operations *EINA_VALUE_BLOB_OPERATIONS_MALLOC = NULL; 5449EAPI const Eina_Value_Blob_Operations *EINA_VALUE_BLOB_OPERATIONS_MALLOC = NULL;
diff --git a/src/lib/eina/eina_value.h b/src/lib/eina/eina_value.h
index c1b6dee..d698043 100644
--- a/src/lib/eina/eina_value.h
+++ b/src/lib/eina/eina_value.h
@@ -26,6 +26,7 @@
26#include "eina_inarray.h" 26#include "eina_inarray.h"
27#include "eina_list.h" 27#include "eina_list.h"
28#include "eina_hash.h" 28#include "eina_hash.h"
29#include "eina_rectangle.h"
29 30
30/** 31/**
31 * @page eina_value_example_01_page Eina_Value usage 32 * @page eina_value_example_01_page Eina_Value usage
@@ -3677,6 +3678,14 @@ static inline const Eina_Value_Type *eina_value_optional_type_get(Eina_Value *va
3677EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_FILE; 3678EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_FILE;
3678 3679
3679/** 3680/**
3681 * @var EINA_VALUE_TYPE_RECTANGLE
3682 * manages optional type.
3683 *
3684 * @since 1.21
3685 */
3686EAPI extern const Eina_Value_Type *EINA_VALUE_TYPE_RECTANGLE;
3687
3688/**
3680 * @} 3689 * @}
3681 */ 3690 */
3682 3691