raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=96142eef963014d1c92a24188a7cfb81afe2d42e

commit 96142eef963014d1c92a24188a7cfb81afe2d42e
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Tue Apr 19 17:21:21 2016 +0900

    eo - add object comments - esp useful for erigo and gui builders
    
    also useful for debugging and more. this also makes both name/id and
    comment an extension blob of ram so objects dont keep growing
    boundlessly in memory usage/size
    
    @feature
---
 src/lib/eo/eo_base.eo                | 15 ++++++
 src/lib/eo/eo_base_class.c           | 93 ++++++++++++++++++++++++++++++++++--
 src/tests/eo/suite/eo_test_general.c | 31 ++++++++++++
 3 files changed, 134 insertions(+), 5 deletions(-)

diff --git a/src/lib/eo/eo_base.eo b/src/lib/eo/eo_base.eo
index b1a24fc..0cd1354 100644
--- a/src/lib/eo/eo_base.eo
+++ b/src/lib/eo/eo_base.eo
@@ -90,6 +90,21 @@ abstract Eo.Base ()
            id: const(char)* @nullable; [[the id/name]]
          }
       }
+      @property comment {
+         [[ A human readable comment for the object
+
+           Every object can have a string comment intended for developers
+           and debugging. An empty string is considered the same as a NULL
+           string or no string for the comment at all.
+         ]]
+         set {
+         }
+         get {
+         }
+         values {
+           comment: const(char)* @nullable; [[the comment]]
+         }
+      }
       @property event_global_freeze_count @class {
          get {
             [[Return freeze events of object.
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index 1b16ba3..5baf582 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -16,6 +16,12 @@ typedef struct _Eo_Callback_Description 
Eo_Callback_Description;
 
 typedef struct
 {
+   const char *id;
+   const char *comment;
+} Eo_Base_Extension;
+
+typedef struct
+{
    Eina_List *children;
    Eo *parent;
    Eina_List *parent_list;
@@ -23,7 +29,7 @@ typedef struct
    Eina_Inlist *generic_data;
    Eo ***wrefs;
 
-   const char *id;
+   Eo_Base_Extension *extension;
    Eo_Callback_Description *callbacks;
    unsigned short walking_list;
    unsigned short event_freeze_count;
@@ -38,6 +44,23 @@ typedef struct
    Eina_Bool         data_is_obj : 1;
 } Eo_Generic_Data_Node;
 
+
+
+static Eo_Base_Extension *
+_eo_base_extension_new(void)
+{
+   Eo_Base_Extension *extension = calloc(1, sizeof(Eo_Base_Extension));
+   return extension;
+}
+
+static void
+_eo_base_extension_free(Eo_Base_Extension *extension)
+{
+   free(extension);
+}
+
+
+
 static void
 _eo_generic_data_node_free(Eo_Generic_Data_Node *node)
 {
@@ -266,13 +289,66 @@ EOLIAN static void
 _eo_base_id_set(Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char *id)
 {
    if ((id) && (!id[0])) id = NULL;
-   eina_stringshare_replace(&(pd->id), id);
+   if (id)
+     {
+        if (!pd->extension)
+          pd->extension = _eo_base_extension_new();
+        if (pd->extension)
+          eina_stringshare_replace(&(pd->extension->id), id);
+     }
+   else
+     {
+        if (!pd->extension) return;
+        if (pd->extension->id)
+          {
+             eina_stringshare_replace(&(pd->extension->id), id);
+             if (!pd->extension->comment)
+               {
+                  _eo_base_extension_free(pd->extension);
+                  pd->extension = NULL;
+               }
+          }
+     }
 }
 
 EOLIAN static const char *
 _eo_base_id_get(Eo *obj EINA_UNUSED, Eo_Base_Data *pd)
 {
-   return pd->id;
+   if (!pd->extension) return NULL;
+   return pd->extension->id;
+}
+
+EOLIAN static void
+_eo_base_comment_set(Eo *obj EINA_UNUSED, Eo_Base_Data *pd, const char 
*comment)
+{
+   if ((comment) && (!comment[0])) comment = NULL;
+   if (comment)
+     {
+        if (!pd->extension)
+          pd->extension = _eo_base_extension_new();
+        if (pd->extension)
+          eina_stringshare_replace(&(pd->extension->comment), comment);
+     }
+   else
+     {
+        if (!pd->extension) return;
+        if (pd->extension->comment)
+          {
+             eina_stringshare_replace(&(pd->extension->comment), comment);
+             if (!pd->extension->id)
+               {
+                  _eo_base_extension_free(pd->extension);
+                  pd->extension = NULL;
+               }
+          }
+     }
+}
+
+EOLIAN static const char *
+_eo_base_comment_get(Eo *obj EINA_UNUSED, Eo_Base_Data *pd)
+{
+   if (!pd->extension) return NULL;
+   return pd->extension->comment;
 }
 
 
@@ -1161,8 +1237,15 @@ _eo_base_destructor(Eo *obj, Eo_Base_Data *pd)
    _wref_destruct(pd);
    _eo_callback_remove_all(pd);
 
-   eina_stringshare_del(pd->id);
-   pd->id = NULL;
+   if (pd->extension)
+     {
+        eina_stringshare_del(pd->extension->id);
+        pd->extension->id = NULL;
+        eina_stringshare_del(pd->extension->comment);
+        pd->extension->comment = NULL;
+        _eo_base_extension_free(pd->extension);
+        pd->extension = NULL;
+     }
 
    _eo_condtor_done(obj);
 }
diff --git a/src/tests/eo/suite/eo_test_general.c 
b/src/tests/eo/suite/eo_test_general.c
index d4fb693..9b19210 100644
--- a/src/tests/eo/suite/eo_test_general.c
+++ b/src/tests/eo/suite/eo_test_general.c
@@ -1067,6 +1067,36 @@ START_TEST(eo_name)
 }
 END_TEST
 
+START_TEST(eo_comment)
+{
+   eo_init();
+   Eo *obj = eo_add(SIMPLE_CLASS, NULL);
+   const char *comment;
+
+   comment = eo_comment_get(obj);
+   fail_if(NULL != comment);
+
+   eo_comment_set(obj, "Hello");
+   comment = eo_comment_get(obj);
+   fail_if(NULL == comment);
+   fail_if(!!strcmp(comment, "Hello"));
+
+   eo_comment_set(obj, "Hello");
+   eo_comment_set(obj, "");
+   comment = eo_comment_get(obj);
+   fail_if(NULL != comment);
+
+   eo_comment_set(obj, "Hello");
+   eo_comment_set(obj, NULL);
+   comment = eo_comment_get(obj);
+   fail_if(NULL != comment);
+
+   eo_del(obj);
+
+   eo_shutdown();
+}
+END_TEST
+
 void eo_test_general(TCase *tc)
 {
    tcase_add_test(tc, eo_simple);
@@ -1086,4 +1116,5 @@ void eo_test_general(TCase *tc)
    tcase_add_test(tc, eo_add_failures);
    tcase_add_test(tc, eo_del_intercept);
    tcase_add_test(tc, eo_name);
+   tcase_add_test(tc, eo_comment);
 }

-- 


Reply via email to