efl - key/data/value/obj attach to eo objects - make these properties

the key data now is a property so they come out in bindings really
nicely like:

  obj.key_data["blah"] = x;

  x = obj.key_data["blah"];

etc.
This commit is contained in:
Carsten Haitzler 2016-05-18 01:02:37 +09:00
parent 7782c0bcb9
commit 43661180f7
11 changed files with 67 additions and 73 deletions

View File

@ -87,7 +87,7 @@ base_data_get(const Eo *obj, const char *key)
inline void
base_data_del(Eo *obj, const char *key)
{
eo_key_del(obj, key);
eo_key_data_set(obj, key, NULL);
}
inline void

View File

@ -101,7 +101,6 @@ ffi.cdef [[
void eo_key_data_set(const char *key, const void *data,
eo_key_data_free_func free_func);
void *eo_key_data_get(const char *key);
void eo_key_del(const char *key);
Eina_Iterator *eo_children_iterator_new(void);

View File

@ -4,8 +4,7 @@ class Ecore.Audio.In.Tone (Ecore.Audio.In)
eo_prefix: ecore_audio_obj_in_tone;
implements {
Eo.Base.constructor;
Eo.Base.key_data_set;
Eo.Base.key_data_get;
Eo.Base.key_data;
Ecore.Audio.In.length.set;
Ecore.Audio.In.seek;
Ecore.Audio.In.read_internal;

View File

@ -95,8 +95,8 @@ _ecore_audio_in_tone_eo_base_key_data_set(Eo *eo_obj, Ecore_Audio_In_Tone_Data *
}
EOLIAN static void*
_ecore_audio_in_tone_eo_base_key_data_get(const Eo *eo_obj, Ecore_Audio_In_Tone_Data *obj, const char *key)
EOLIAN static void *
_ecore_audio_in_tone_eo_base_key_data_get(Eo *eo_obj, Ecore_Audio_In_Tone_Data *obj, const char *key)
{
if (!strcmp(key, ECORE_AUDIO_ATTR_TONE_FREQ)) {
return (void *) (intptr_t) obj->freq;

View File

@ -575,7 +575,7 @@ end:
pd->items = (Grid_Item *)
eina_inlist_remove(EINA_INLIST_GET(pd->items), EINA_INLIST_GET(gi));
pd->count--;
eo_key_del(subobj, GRID_ITEM_KEY);
eo_key_data_set(subobj, GRID_ITEM_KEY, NULL);
free(gi);
}

View File

@ -4382,7 +4382,7 @@ _local_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
if (!dropable->cbs_list)
{
drops = eina_list_remove(drops, dropable);
eo_key_del(obj, "__elm_dropable");
eo_key_data_set(obj, "__elm_dropable", NULL);
free(dropable);
dropable = NULL;
evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL,

View File

@ -91,7 +91,7 @@ _efl_ui_layout_internal_box_eo_base_finalize(Eo *obj, Efl_Ui_Layout_Box_Data *pd
EOLIAN static void
_efl_ui_layout_internal_box_eo_base_destructor(Eo *obj, Efl_Ui_Layout_Box_Data *pd)
{
eo_key_del(pd->pack, DATA_KEY);
eo_key_data_set(pd->pack, DATA_KEY, NULL);
eo_destructor(eo_super(obj, BOX_CLASS));
}
@ -291,7 +291,7 @@ _efl_ui_layout_internal_table_eo_base_finalize(Eo *obj EINA_UNUSED, Efl_Ui_Layou
EOLIAN static void
_efl_ui_layout_internal_table_eo_base_destructor(Eo *obj, Efl_Ui_Layout_Box_Data *pd)
{
eo_key_del(pd->pack, DATA_KEY);
eo_key_data_set(pd->pack, DATA_KEY, NULL);
eina_stringshare_del(pd->part);
eo_destructor(eo_super(obj, TABLE_CLASS));
}

View File

@ -200,73 +200,66 @@ abstract Eo.Base ()
@in wref: Eo.Base **;
}
}
key_data_set {
[[Set generic data to object.
@property key_data {
[[Generic data with string key on an object.
The user is in change to free the data.
The user is in charge of freeing the data.
]]
params {
@in key: const(char)*; [[the key associated with the data]]
@in data: const(void)*; [[the data to set]]
keys {
key: const(char) *; [[the key associated with the data]]
}
set {
values {
data: const(void) *; [[the data to set]]
}
}
get {
values {
data: void *; [[the data to set]]
}
}
}
key_data_get @const {
[[Get generic data from object.]]
params {
@in key: const(char)*; [[the key associated with the data]]
}
return: void *; [[the data for the key]]
}
key_del {
[[Del generic data from object.]]
params {
@in key: const(char)*; [[the key associated with the data]]
}
}
key_obj_set {
[[Set generic object reference to object.
@property key_obj {
[[Generic object reference with string key to object.
The object will be automatically ref'd when set and unref'd
when replaced or deleted or referring object is deleted. If
the referenced object is deleted then the key is deleted
automatically.
This is the same key store used by key_data_set etc. so keys
This is the same key store used by key_data and key_value so keys
are shared and can store only one thing
]]
params {
@in key: const(char)*; [[the key associated with the object ref]]
@in objdata: Eo.Base *; [[the object to set]]
keys {
key: const(char) *; [[the key associated with the object ref]]
}
set {
values {
objdata: const(Eo.Base) *; [[the object to set]]
}
}
get {
values {
objdata: Eo.Base *; [[the object to set]]
}
}
}
key_obj_get @const {
[[Get generic object reference from object.]]
params {
@in key: const(char)*; [[the key associated with the object ref]]
}
return: Eo.Base *; [[the object reference for the key]]
}
key_value_set {
[[Set value on the object.
@property key_value {
[[Value on with string key on the object.
This stores the value with the given string key on the object
and it will be freed when replaced or deleted or the referring
object is deleted.
This is the same key store used by key_data_set and key_obj_set
etc. so keys are shared and can store only one thing
This is the same key store used by key_data and key_obj so keys
are shared and can store only one thing
]]
params {
@in key: const(char)*; [[the key associated with the value]]
@in value: Eina.Value *; [[the value to set]]
keys {
key: const(char)*; [[the key associated with the value]]
}
}
key_value_get @const {
[[Get generic value from object.]]
params {
@in key: const(char)*; [[the key associated with the value]]
values {
value: Eina.Value *; [[the value to set]]
}
return: Eina.Value *; [[the value for the key]]
}
event_thaw {
[[thaw events of object.

View File

@ -126,14 +126,12 @@ _eo_generic_data_del_all(Eo *obj EINA_UNUSED, Eo_Base_Data *pd)
}
}
EOLIAN static void
_eo_base_key_del(Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *key)
static void
_eo_key_generic_del(const Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *key)
{
Eo_Generic_Data_Node *node;
Eo_Base_Extension *ext = pd->ext;
if (!key) return;
if (!ext) return;
EINA_INLIST_FOREACH(ext->generic_data, node)
{
if (!strcmp(node->key, key))
@ -148,7 +146,7 @@ _eo_base_key_del(Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *key)
/* Return TRUE if the object was newly added. */
static Eina_Bool
_key_generic_set(const Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *key, const void *data, Eo_Generic_Data_Node_Type d_type)
_key_generic_set(const Eo *obj, Eo_Base_Data *pd, const char *key, const void *data, Eo_Generic_Data_Node_Type d_type)
{
Eo_Generic_Data_Node *node;
Eo_Base_Extension *ext = pd->ext;
@ -156,6 +154,11 @@ _key_generic_set(const Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *key, c
if (!key) return EINA_FALSE;
if (ext)
{
if (!data)
{
_eo_key_generic_del(obj, pd, key);
return EINA_TRUE;
}
EINA_INLIST_FOREACH(ext->generic_data, node)
{
if (!strcmp(node->key, key))
@ -223,20 +226,20 @@ _eo_base_key_data_set(Eo *obj, Eo_Base_Data *pd, const char *key, const void *da
}
EOLIAN static void *
_eo_base_key_data_get(const Eo *obj, Eo_Base_Data *pd, const char *key)
_eo_base_key_data_get(Eo *obj, Eo_Base_Data *pd, const char *key)
{
return _key_generic_get(obj, pd, key, DATA_PTR);
}
EOLIAN static void
_eo_base_key_obj_set(Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *key, Eo *objdata)
_eo_base_key_obj_set(Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *key, const Eo *objdata)
{
if (_key_generic_set(obj, pd, key, objdata, DATA_OBJ))
eo_ref(objdata);
}
EOLIAN static Eo *
_eo_base_key_obj_get(const Eo *obj, Eo_Base_Data *pd, const char *key)
_eo_base_key_obj_get(Eo *obj, Eo_Base_Data *pd, const char *key)
{
return _key_generic_get(obj, pd, key, DATA_OBJ);
}
@ -248,7 +251,7 @@ _eo_base_key_value_set(Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *key, E
}
EOLIAN static Eina_Value *
_eo_base_key_value_get(const Eo *obj, Eo_Base_Data *pd, const char *key)
_eo_base_key_value_get(Eo *obj, Eo_Base_Data *pd, const char *key)
{
return _key_generic_get(obj, pd, key, DATA_VAL);
}

View File

@ -30,6 +30,6 @@ evas_object_data_del(Evas_Object *obj, const char *key)
MAGIC_CHECK_END();
void *data = NULL;
data = eo_key_data_get(obj, key);
eo_key_del(obj, key);
eo_key_data_set(obj, key, NULL);
return data;
}

View File

@ -620,7 +620,7 @@ START_TEST(eo_generic_data)
eo_key_data_set(obj, "test1", (void *) 1);
data = eo_key_data_get(obj, "test1");
fail_if(1 != (intptr_t) data);
eo_key_del(obj, "test1");
eo_key_data_set(obj, "test1", NULL);
data = eo_key_data_get(obj, "test1");
fail_if(data);
@ -633,13 +633,13 @@ START_TEST(eo_generic_data)
data = eo_key_data_get(obj, "test2");
fail_if(2 != (intptr_t) data);
eo_key_del(obj, "test2");
eo_key_data_set(obj, "test2", NULL);
data = eo_key_data_get(obj, "test2");
fail_if(data);
data = eo_key_data_get(obj, "test1");
fail_if(1 != (intptr_t) data);
eo_key_del(obj, "test1");
eo_key_data_set(obj, "test1", NULL);
data = eo_key_data_get(obj, "test1");
fail_if(data);
@ -648,7 +648,7 @@ START_TEST(eo_generic_data)
eo_key_obj_set(obj, "test1", obj2);
objtmp = eo_key_obj_get(obj, "test1");
fail_if(obj2 != objtmp);
eo_key_del(obj, "test1");
eo_key_obj_set(obj, "test1", NULL);
objtmp = eo_key_obj_get(obj, "test1");
fail_if(objtmp);
@ -661,13 +661,13 @@ START_TEST(eo_generic_data)
data = eo_key_obj_get(obj, "test2");
fail_if(obj3 != objtmp);
eo_key_del(obj, "test2");
eo_key_obj_set(obj, "test2", NULL);
objtmp = eo_key_obj_get(obj, "test2");
fail_if(objtmp);
objtmp = eo_key_obj_get(obj, "test1");
fail_if(obj2 != objtmp);
eo_key_del(obj, "test1");
eo_key_obj_set(obj, "test1", NULL);
objtmp = eo_key_obj_get(obj, "test1");
fail_if(objtmp);
@ -680,10 +680,10 @@ START_TEST(eo_generic_data)
value2 = eo_key_value_get(obj, "value1");
fail_if(value != value2);
eo_key_del(obj, "value1");
eo_key_value_set(obj, "value1", NULL);
value2 = eo_key_value_get(obj, "value1");
fail_if(value2 != NULL);
eo_key_del(obj, "value1");
eo_key_value_set(obj, "value1", NULL);
eo_unref(obj);
eo_unref(obj2);