forked from enlightenment/efl
eet: add a helper to setup hash with generic value storage
Summary: add a macro to setup eet_data_descriptor for hash with generic value storage. Test Plan: make check (test case is included in eet test suite) Reviewers: cedric, raster Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D3925 Signed-off-by: Cedric Bail <cedric@osg.samsung.com>
This commit is contained in:
parent
fa5abb2967
commit
557381a070
|
@ -3578,6 +3578,29 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
|
|||
0, /* 0, */ NULL, NULL); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* Add a hash of generic value storage to a data descriptor
|
||||
* @param edd The data descriptor to add the type to.
|
||||
* @param struct_type The type of the struct.
|
||||
* @param name The string name to use to encode/decode this member
|
||||
* (must be a constant global and never change).
|
||||
* @param member The struct member itself to be encoded.
|
||||
*
|
||||
* This macro lets you easily add a hash of value elements. All the
|
||||
* parameters are the same as for EET_DATA_DESCRIPTOR_ADD_HASH().
|
||||
*
|
||||
* @since 1.18
|
||||
* @ingroup Eet_Data_Group
|
||||
*/
|
||||
#define EET_DATA_DESCRIPTOR_ADD_HASH_VALUE(edd, struct_type, name, member) \
|
||||
do { \
|
||||
struct_type ___ett; \
|
||||
eet_data_descriptor_element_add(edd, name, EET_T_VALUE, EET_G_HASH, \
|
||||
(char *)(& (___ett.member)) - \
|
||||
(char *)(& (___ett)), \
|
||||
0, /* 0, */ NULL, NULL); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* Add an array of basic data elements to a data descriptor.
|
||||
* @param edd The data descriptor to add the type to.
|
||||
|
|
|
@ -632,6 +632,7 @@ static int _eet_data_words_bigendian = -1;
|
|||
#define EET_I_STRING 1 << 4
|
||||
#define EET_I_INLINED_STRING 2 << 4
|
||||
#define EET_I_NULL 3 << 4
|
||||
#define EET_I_VALUE 4 << 4
|
||||
|
||||
#define EET_MAGIC_VARIANT 0xF1234BC
|
||||
/*---*/
|
||||
|
@ -1281,7 +1282,7 @@ _eet_type_to_eina_value_get(int eet_type)
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
_eina_value_to_eet_type_get(const Eina_Value_Type *eina_type)
|
||||
{
|
||||
|
@ -1361,7 +1362,7 @@ eet_data_put_value(Eet_Dictionary *ed,
|
|||
const void *src,
|
||||
int *size_ret)
|
||||
{
|
||||
const Eina_Value *value = *(void**)src;
|
||||
const Eina_Value *value = *(Eina_Value **)src;
|
||||
const Eina_Value_Type *value_type;
|
||||
void *int_data;
|
||||
void *type_data;
|
||||
|
@ -1522,6 +1523,7 @@ case EET_I_ ## Type: chnk->type = EET_T_ ## Type; break;
|
|||
|
||||
EET_UNMATCH_TYPE(STRING);
|
||||
EET_UNMATCH_TYPE(INLINED_STRING);
|
||||
EET_UNMATCH_TYPE(VALUE);
|
||||
EET_UNMATCH_TYPE(NULL);
|
||||
|
||||
default:
|
||||
|
@ -1701,6 +1703,7 @@ case EET_T_ ## Type: type += EET_I_ ## Type; break;
|
|||
|
||||
EET_MATCH_TYPE(STRING);
|
||||
EET_MATCH_TYPE(INLINED_STRING);
|
||||
EET_MATCH_TYPE(VALUE);
|
||||
EET_MATCH_TYPE(NULL);
|
||||
|
||||
default:
|
||||
|
@ -2221,7 +2224,8 @@ eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
|
|||
if ((group_type > EET_G_UNKNOWN)
|
||||
&& (group_type < EET_G_LAST)
|
||||
&& (((type > EET_T_UNKNOW) && (type < EET_T_STRING))
|
||||
|| ((type > EET_T_NULL) && (type < EET_T_LAST)))
|
||||
|| ((type > EET_T_NULL) && (type < EET_T_VALUE))
|
||||
|| ((type > EET_T_VALUE) && (type < EET_T_LAST)))
|
||||
&& (!subtype))
|
||||
{
|
||||
subtype = calloc(1, sizeof (Eet_Data_Descriptor));
|
||||
|
|
|
@ -18,6 +18,7 @@ typedef struct _Eet_St1 Eet_St1;
|
|||
typedef struct _Eet_St2 Eet_St2;
|
||||
typedef struct _Eet_St3 Eet_St3;
|
||||
typedef struct _Eet_List Eet_List;
|
||||
typedef struct _Eet_Hash Eet_Hash;
|
||||
|
||||
typedef enum _Eet_Union
|
||||
{
|
||||
|
@ -102,6 +103,11 @@ struct _Eet_List
|
|||
Eina_List *list;
|
||||
};
|
||||
|
||||
struct _Eet_Hash
|
||||
{
|
||||
Eina_Hash *hash;
|
||||
};
|
||||
|
||||
static const char *
|
||||
_eet_union_type_get(const void *data,
|
||||
Eina_Bool *unknow)
|
||||
|
@ -752,6 +758,64 @@ START_TEST(eet_test_data_variant)
|
|||
} /* START_TEST */
|
||||
END_TEST
|
||||
|
||||
START_TEST(eet_test_data_hash_value)
|
||||
{
|
||||
Eet_Hash *h;
|
||||
Eina_Value *val;
|
||||
Eet_Data_Descriptor_Class eddc;
|
||||
Eet_Data_Descriptor *edd;
|
||||
void *blob;
|
||||
int size;
|
||||
int i;
|
||||
double d;
|
||||
char *s;
|
||||
|
||||
eina_init();
|
||||
eet_init();
|
||||
|
||||
EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Hash);
|
||||
edd = eet_data_descriptor_stream_new(&eddc);
|
||||
|
||||
EET_DATA_DESCRIPTOR_ADD_HASH_VALUE(edd, Eet_Hash, "hash", hash);
|
||||
|
||||
h = calloc(1, sizeof(Eet_Hash));
|
||||
h->hash = eina_hash_string_small_new((Eina_Free_Cb)eina_value_free);
|
||||
|
||||
val = eina_value_new(EINA_VALUE_TYPE_INT);
|
||||
eina_value_set(val, EET_TEST_INT);
|
||||
eina_hash_direct_add(h->hash, "val/int", val);
|
||||
|
||||
val = eina_value_new(EINA_VALUE_TYPE_DOUBLE);
|
||||
eina_value_set(val, EET_TEST_DOUBLE);
|
||||
eina_hash_direct_add(h->hash, "val/double", val);
|
||||
|
||||
val = eina_value_new(EINA_VALUE_TYPE_STRING);
|
||||
eina_value_set(val, EET_TEST_STRING);
|
||||
eina_hash_direct_add(h->hash, "val/string", val);
|
||||
|
||||
blob = eet_data_descriptor_encode(edd, h, &size);
|
||||
fail_if((!blob) || (size <= 0));
|
||||
|
||||
h = eet_data_descriptor_decode(edd, blob, size);
|
||||
fail_if(!h);
|
||||
|
||||
val = (Eina_Value *)eina_hash_find(h->hash, "val/int");
|
||||
eina_value_get(val, &i);
|
||||
fail_if((!val) || (i != EET_TEST_INT));
|
||||
|
||||
val = (Eina_Value *)eina_hash_find(h->hash, "val/double");
|
||||
eina_value_get(val, &d);
|
||||
fail_if((!val) || (d != EET_TEST_DOUBLE));
|
||||
|
||||
val = (Eina_Value *)eina_hash_find(h->hash, "val/string");
|
||||
eina_value_get(val, &s);
|
||||
fail_if((!val) || strcmp(s, EET_TEST_STRING));
|
||||
|
||||
eet_shutdown();
|
||||
eina_shutdown();
|
||||
} /* START_TEST */
|
||||
END_TEST
|
||||
|
||||
void eet_test_data(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, eet_test_data_basic_type_encoding_decoding);
|
||||
|
@ -761,4 +825,5 @@ void eet_test_data(TCase *tc)
|
|||
tcase_add_test(tc, eet_test_data_fp);
|
||||
tcase_add_test(tc, eet_test_data_union);
|
||||
tcase_add_test(tc, eet_test_data_variant);
|
||||
tcase_add_test(tc, eet_test_data_hash_value);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue