Add e_config_data files

Signed-off-by: Chris Michael <cp.michael@samsung.com>
This commit is contained in:
Chris Michael 2013-04-24 10:15:57 +01:00
parent b2390319fa
commit 27c88d42cc
2 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,41 @@
#include "e.h"
static Eina_Hash *config_hash = NULL;
EAPI void
e_config_descriptor_free(E_Config_DD *edd)
{
#if (EET_VERSION_MAJOR > 1) || (EET_VERSION_MINOR >= 8)
eina_hash_del_by_key(config_hash, eet_data_descriptor_name_get((Eet_Data_Descriptor*)edd));
#else
eina_hash_del_by_data(config_hash, edd);
#endif
eet_data_descriptor_free((Eet_Data_Descriptor*)edd);
}
EAPI E_Config_DD *
e_config_descriptor_new(const char *name, int size)
{
Eet_Data_Descriptor_Class eddc;
E_Config_DD *edd;
if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), name, size))
return NULL;
/* FIXME: We can directly map string inside an Eet_File and reuse it.
But this need a break in all user of config every where in E.
*/
edd = (E_Config_DD *)eet_data_descriptor_stream_new(&eddc);
if (!config_hash) config_hash = eina_hash_string_superfast_new(NULL);
eina_hash_set(config_hash, name, edd);
return edd;
}
EAPI E_Config_DD *
e_config_descriptor_find(const char *name)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
return eina_hash_find(config_hash, name);
}

View File

@ -0,0 +1,69 @@
#ifdef E_TYPEDEFS
/** \def E_CONFIG_DD_NEW(str, typ)
* is used to create definition of a struct
* \str str name to give to struct
* \typ typ the actual struct type
*/
#define E_CONFIG_DD_NEW(str, typ) \
e_config_descriptor_new(str, sizeof(typ))
/** \def E_CONFIG_DD_FREE(eed)
* is used to free definition of a struct
* \eed eed the pointer created by \link #E_CONFIG_DD_NEW
*/
#define E_CONFIG_DD_FREE(eed) \
if (eed) { e_config_descriptor_free((eed)); (eed) = NULL; }
#define E_CONFIG_DD_FIND(type) \
e_config_descriptor_find(type)
#define E_CONFIG_VAL(edd, type, member, dtype) \
EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype)
#define E_CONFIG_SUB(edd, type, member, eddtype) \
EET_DATA_DESCRIPTOR_ADD_SUB(edd, type, #member, member, eddtype)
/** \def E_CONFIG_LIST(edd, type, member, eddtype)
* declares a struct member to be included definition
* list type must be Evas_List and not Ecore_List
* \edd edd the pointer created by \link #E_CONFIG_DD_NEW
* \type type struct type
* \member member member of struct
* \eddtype struct definition to use for each entry in the list
*/
#define E_CONFIG_LIST(edd, type, member, eddtype) \
EET_DATA_DESCRIPTOR_ADD_LIST(edd, type, #member, member, eddtype)
/** \def E_CONFIG_HASH(edd, type, member, eddtype)
* declares a struct member to be included definition
* list type must be Evas_Hash and not Ecore_Hash
* \edd edd the pointer created by \link #E_CONFIG_DD_NEW
* \type type struct type
* \member member member of struct
* \eddtype struct definition to use for each entry in the hash
*/
#define E_CONFIG_HASH(edd, type, member, eddtype) \
EET_DATA_DESCRIPTOR_ADD_HASH(edd, type, #member, member, eddtype)
#define CHAR EET_T_CHAR
#define SHORT EET_T_SHORT
#define INT EET_T_INT
#define LL EET_T_LONG_LONG
#define FLOAT EET_T_FLOAT
#define DOUBLE EET_T_DOUBLE
#define UCHAR EET_T_UCHAR
#define USHORT EET_T_USHORT
#define UINT EET_T_UINT
#define ULL EET_T_ULONG_LONG
#define STR EET_T_STRING
typedef Eet_Data_Descriptor E_Config_DD;
#else
#ifndef E_CONFIG_DATA_H
#define E_CONFIG_DATA_H
EAPI E_Config_DD *e_config_descriptor_new(const char *name, int size);
EAPI void e_config_descriptor_free(E_Config_DD *edd);
EAPI E_Config_DD *e_config_descriptor_find(const char *name);
#endif
#endif