summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-01-22 11:59:23 +0000
committerCedric BAIL <cedric.bail@free.fr>2019-01-23 10:54:05 -0800
commit1150cce0bf306958ab2b7ae560f26700fd35f38c (patch)
tree957c1e14cfc8aa04726109db5a988b82c1c47c81 /src/lib/eina
parentd4ab2119681fec87bf1f755d9a0e225b6dbcaa72 (diff)
eina: add Eina_Value helper that convert efficiently to a target native C type.
Reviewed-by: SangHyeon Jade Lee <sh10233.lee@samsung.com> Differential Revision: https://phab.enlightenment.org/D7650
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_inline_value_util.x59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/lib/eina/eina_inline_value_util.x b/src/lib/eina/eina_inline_value_util.x
index f755b4bf1c..5dc2a9b8df 100644
--- a/src/lib/eina/eina_inline_value_util.x
+++ b/src/lib/eina/eina_inline_value_util.x
@@ -16,6 +16,10 @@
16 * if not, see <http://www.gnu.org/licenses/>. 16 * if not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19/**
20 * @addtogroup Eina_Value_Value_group
21 * @{
22 */
19 23
20#ifndef EINA_INLINE_VALUE_UTIL_X_ 24#ifndef EINA_INLINE_VALUE_UTIL_X_
21#define EINA_INLINE_VALUE_UTIL_X_ 25#define EINA_INLINE_VALUE_UTIL_X_
@@ -977,6 +981,57 @@ eina_value_error_get(const Eina_Value *v, Eina_Error *err)
977 return EINA_FALSE; 981 return EINA_FALSE;
978} 982}
979 983
984/// @brief For internal use only.
985/// @hideinitializer
986#define EINA_VALUE_CONVERT(Compress_Type, Uppercase_Compress_Type, Type) \
987/**
988 @brief Check value type and convert contents.
989 @param v The value to check type and convert contents.
990 @param c Where to store the value contents.
991 @return #EINA_TRUE if type matches and fetched contents,
992 #EINA_FALSE on different type or failures.
993 @since 1.22
994 */ \
995static inline Eina_Bool \
996eina_value_##Compress_Type##_convert(const Eina_Value *v, Type *c) \
997{ \
998 Eina_Value dst = EINA_VALUE_EMPTY; \
999 Eina_Bool r = EINA_FALSE; \
1000 \
1001 EINA_SAFETY_ON_NULL_RETURN_VAL(c, EINA_FALSE); \
1002 EINA_SAFETY_ON_NULL_RETURN_VAL(v, EINA_FALSE); \
1003 \
1004 /* Try no conversion first */ \
1005 if (eina_value_##Compress_Type##_get(v, c)) return EINA_TRUE; \
1006 \
1007 if (!eina_value_setup(&dst, EINA_VALUE_TYPE_##Uppercase_Compress_Type)) return EINA_FALSE; \
1008 if (!eina_value_convert(v, &dst)) goto on_error; \
1009 if (!eina_value_##Compress_Type##_get(&dst, c)) goto on_error; \
1010 r = EINA_TRUE; \
1011 \
1012 on_error: \
1013 eina_value_flush(&dst); \
1014 return r; \
1015}
1016
1017EINA_VALUE_CONVERT(uchar, UCHAR, unsigned char);
1018EINA_VALUE_CONVERT(ushort, USHORT, unsigned short);
1019EINA_VALUE_CONVERT(uint, UINT, unsigned int);
1020EINA_VALUE_CONVERT(ulong, ULONG, unsigned long);
1021EINA_VALUE_CONVERT(uint64, UINT64, uint64_t);
1022EINA_VALUE_CONVERT(char, CHAR, char);
1023EINA_VALUE_CONVERT(short, SHORT, short);
1024EINA_VALUE_CONVERT(int, INT, int);
1025EINA_VALUE_CONVERT(long, LONG, long);
1026EINA_VALUE_CONVERT(int64, INT64, int64_t);
1027EINA_VALUE_CONVERT(float, FLOAT, float);
1028EINA_VALUE_CONVERT(double, DOUBLE, double);
1029EINA_VALUE_CONVERT(bool, BOOL, Eina_Bool);
1030EINA_VALUE_CONVERT(string, STRING, const char *);
1031EINA_VALUE_CONVERT(stringshare, STRINGSHARE, const char *);
1032EINA_VALUE_CONVERT(time, TIMESTAMP, time_t);
1033EINA_VALUE_CONVERT(error, ERROR, Eina_Error);
1034
980/** 1035/**
981 * @brief Create a new #Eina_Value containing the passed parameter 1036 * @brief Create a new #Eina_Value containing the passed parameter
982 * @param val The value to use 1037 * @param val The value to use
@@ -1058,3 +1113,7 @@ eina_value_string_copy(const Eina_Value *val, char **str)
1058} 1113}
1059 1114
1060#endif 1115#endif
1116
1117/**
1118 * @}
1119 */