batch register/unregister of external types, faster and lighter on memory.
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 1 Dec 2009 17:58:17 +0000 (17:58 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 1 Dec 2009 17:58:17 +0000 (17:58 +0000)
This is the recommended way to register a batch of types, it will not
do check (hash lookup) before adding and keys are added as "direct"
(not copied), thus lighter on memory.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/edje@44102 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/Edje.h
src/lib/edje_external.c

index 2e21327..679a207 100644 (file)
@@ -328,6 +328,15 @@ struct _Edje_External_Type
 typedef struct _Edje_External_Type Edje_External_Type;
 
 
+struct _Edje_External_Type_Info
+{
+   const char *name;
+   const Edje_External_Type *info;
+};
+typedef struct _Edje_External_Type_Info Edje_External_Type_Info;
+
+
+
 typedef void (*Edje_Signal_Cb) (void *data, Evas_Object *obj, const char *emission, const char *source);
 typedef void (*Edje_Text_Change_Cb) (void *data, Evas_Object *obj, const char *part);
 typedef void (*Edje_Message_Handler_Cb) (void *data, Evas_Object *obj, Edje_Message_Type type, int id, void *msg);
@@ -482,6 +491,10 @@ extern "C" {
    /* edje_external.c */
   EAPI Eina_Bool edje_external_type_register(const char *type_name, const Edje_External_Type *type_info);
   EAPI Eina_Bool edje_external_type_unregister(const char *type_name);
+
+  EAPI void      edje_external_type_array_register(const Edje_External_Type_Info *array);
+  EAPI void      edje_external_type_array_unregister(const Edje_External_Type_Info *array);
+
   EAPI Eina_Iterator *edje_external_iterator_get(void);
   EAPI Edje_External_Param *edje_external_param_find(const Eina_List *params, const char *key);
   EAPI Eina_Bool edje_external_param_int_get(const Eina_List *params, const char *key, int *ret);
index 3ca02ca..093ce1a 100644 (file)
@@ -7,6 +7,18 @@
 static Eina_Hash *type_registry = NULL;
 static int init_count = 0;
 
+/**
+ * Register given type name to return the given information.
+ *
+ * @param type_name name to register and be known by edje's "source:"
+ *        parameter of "type: EXTERNAL" parts.
+ * @param type_info meta-information describing how to interact with it.
+ *
+ * @return @c EINA_TRUE on success, @c EINA_FALSE on failure (like
+ *         type already registered).
+ *
+ * @see edje_external_type_array_register()
+ */
 EAPI Eina_Bool
 edje_external_type_register(const char *type_name, const Edje_External_Type *type_info)
 {
@@ -18,12 +30,77 @@ edje_external_type_register(const char *type_name, const Edje_External_Type *typ
    return eina_hash_add(type_registry, type_name, type_info);
 }
 
+/**
+ * Unregister given type name previously registered.
+ *
+ * @param type_name name to unregister. It should be registered with
+ *        edje_external_type_register() before.
+ *
+ * @return @c EINA_TRUE on success, @c EINA_FALSE on failure (like
+ *         type_name did not exist).
+ *
+ * @see edje_external_type_array_unregister()
+ */
 EAPI Eina_Bool
 edje_external_type_unregister(const char *type_name)
 {
    return eina_hash_del_by_key(type_registry, type_name);
 }
 
+/**
+ * Register a batch of types and their information.
+ *
+ * This is the recommended function to add information as it's faster
+ * than the single version edje_external_type_register().
+ *
+ * @note the given array is not modified, but the type name strings
+ *       are @b not duplicated! That is, all type names must be @b
+ *       live until they are unregistered! This was choosen to save
+ *       some memory and most people will just define the array as a
+ *       global static const type anyway.
+ *
+ * @param arrray @c NULL terminated array with type name and
+ *        information. Note that type name or information are not
+ *        modified by are @b referenced, so they must keep alive after
+ *        this function returns!
+ *
+ * @return @c EINA_TRUE on success, @c EINA_FALSE on failure (like
+ *         type already registered).
+ *
+ * @see edje_external_type_register()
+ */
+EAPI void
+edje_external_type_array_register(const Edje_External_Type_Info *array)
+{
+   const Edje_External_Type_Info *itr;
+
+   if (!array)
+     return;
+
+   for (itr = array; itr->name; itr++)
+     eina_hash_direct_add(type_registry, itr->name, itr->info);
+}
+
+/**
+ * Unregister a batch of given external type previously registered.
+ *
+ * @param array @c NULL terminated array, should be the same as the
+ *        one used to register with edje_external_type_array_register()
+ *
+ * @see edje_external_type_unregister()
+ */
+EAPI void
+edje_external_type_array_unregister(const Edje_External_Type_Info *array)
+{
+   const Edje_External_Type_Info *itr;
+
+   if (!array)
+     return;
+
+   for (itr = array; itr->name; itr++)
+     eina_hash_del(type_registry, itr->name, itr->info);
+}
+
 EAPI Eina_Iterator *
 edje_external_iterator_get(void)
 {