EAPI Eo *eo_parent_get(const Eo *obj);
/**
+ * @brief Set the parent of an object
+ * @param obj the object to get the parent of.
+ * @param parent the new parent.
+ * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
+ */
+EAPI Eina_Bool eo_parent_set(Eo *obj, const Eo *parent);
+
+/**
* @brief Get a pointer to the data of an object for a specific class.
* @param obj the object to work on.
* @param klass the klass associated with the data.
struct _Eo {
EINA_MAGIC
+ EINA_INLIST;
Eo *parent;
+ Eina_Inlist *children;
const Eo_Class *klass;
int refcount;
#ifndef NDEBUG
return NULL;
}
+EAPI Eina_Bool
+eo_parent_set(Eo *obj, const Eo *parent)
+{
+ EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
+ if (parent)
+ EO_MAGIC_RETURN_VAL(parent, EO_EINA_MAGIC, EINA_FALSE);
+
+ _eo_ref(obj);
+
+ if (obj->parent)
+ {
+ obj->parent->children =
+ eina_inlist_remove(obj->parent->children, EINA_INLIST_GET(obj));
+// eo_xunref(obj, obj->parent);
+ }
+
+ obj->parent = (Eo *) parent;
+ if (obj->parent)
+ {
+ obj->parent->children =
+ eina_inlist_append(obj->parent->children, EINA_INLIST_GET(obj));
+// eo_xref(obj, obj->parent);
+ }
+
+ _eo_unref(obj);
+
+ return EINA_TRUE;
+}
+
EAPI Eo *
eo_add(const Eo_Class *klass, Eo *parent)
{
Eo *obj = calloc(1, EO_ALIGN_SIZE(sizeof(*obj)) +
(klass->data_offset + EO_ALIGN_SIZE(klass->desc->data_size)) +
klass->extn_data_size);
+ EINA_MAGIC_SET(obj, EO_EINA_MAGIC);
+ obj->refcount++;
obj->klass = klass;
- obj->parent = parent;
- obj->refcount++;
+ eo_parent_set(obj, parent);
Eo_Kls_Itr prev_state;
_eo_kls_itr_init(klass, &obj->mro_itr, EO_NOOP, &prev_state);
_eo_error_unset(obj);
- EINA_MAGIC_SET(obj, EO_EINA_MAGIC);
_eo_ref(obj);
_eo_constructor(obj, klass);
_eo_kls_itr_end(&obj->mro_itr, &prev_state);
/*FIXME: add eo_class_unref(klass) ? - just to clear the caches. */
- Eina_List *itr, *itr_n;
- Eo *emb_obj;
- EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
{
- eo_composite_object_detach(obj, emb_obj);
+ Eina_List *itr, *itr_n;
+ Eo *emb_obj;
+ EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
+ {
+ eo_composite_object_detach(obj, emb_obj);
+ }
+ }
+
+ eo_parent_set(obj, NULL);
+ while (obj->children)
+ {
+ eo_parent_set(EINA_INLIST_CONTAINER_GET(obj->children, Eo), NULL);
}
obj->del = EINA_TRUE;