eo: add the ability to get the size of object of a certain class.
authorCedric BAIL <cedric.bail@free.fr>
Fri, 7 Dec 2018 00:36:59 +0000 (16:36 -0800)
committerJiyoun Park <jy0703.park@samsung.com>
Wed, 16 Jan 2019 02:13:21 +0000 (11:13 +0900)
Their was two different way to implement this, either like this with
a simple function that work on Efl_Class, or by a function on
Efl.Object. I leaned on the first one, but I could easily be convinced
it should be done on Efl.Object actually.

Reviewed-by: Xavi Artigas <xavierartigas@yahoo.es>
Differential Revision: https://phab.enlightenment.org/D7441

src/lib/eo/Eo.h
src/lib/eo/eo.c

index 6221044..a6aa5b9 100644 (file)
@@ -918,7 +918,7 @@ EAPI Eina_Bool efl_isa(const Eo *obj, const Efl_Class *klass);
 
 /**
  * @brief Gets the name of the passed class.
- * @param klass the class to work on.
+ * @param[in] klass The class (or object) to work on.
  * @return The class' name.
  *
  * @see efl_class_get()
@@ -926,6 +926,15 @@ EAPI Eina_Bool efl_isa(const Eo *obj, const Efl_Class *klass);
 EAPI const char *efl_class_name_get(const Efl_Class *klass);
 
 /**
+ * @brief Gets the amount of memory this class object would use.
+ * @param[in] klass The class (or object) to work on.
+ * @return The amount of memory in Bytes.
+ *
+ * @see efl_class_get()
+ */
+EAPI size_t efl_class_memory_size_get(const Efl_Class *klass);
+
+/**
  * @brief Gets a debug name for this object
  * @param obj_id The object (or class)
  * @return A name to use in logs and for other debugging purposes
index 3fb7fd6..ed0f371 100644 (file)
@@ -1150,6 +1150,31 @@ err_obj:
    return NULL;
 }
 
+EAPI const size_t
+efl_class_memory_size_get(const Efl_Class *eo_id)
+{
+   const _Efl_Class *klass;
+
+   if (_eo_is_a_class(eo_id))
+     {
+        EO_CLASS_POINTER_GOTO(eo_id, _klass, err_klass);
+        klass = _klass;
+     }
+   else
+     {
+        EO_OBJ_POINTER_GOTO(eo_id, obj, err_obj);
+        klass = obj->klass;
+        EO_OBJ_DONE(eo_id);
+     }
+   return klass->obj_size;
+
+err_klass:
+   _EO_POINTER_ERR(eo_id, "Class (%p) is an invalid ref.", eo_id);
+err_obj:
+   return 0;
+}
+
+
 static void
 _vtable_init(Eo_Vtable *vtable, size_t size)
 {