forked from enlightenment/efl
Setup an init/shutdown system for shared strings.
SVN revision: 18658
This commit is contained in:
parent
ec44ab043d
commit
46518fa24f
|
@ -419,6 +419,8 @@ extern "C" {
|
||||||
int references;
|
int references;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int ecore_string_init(void);
|
||||||
|
void ecore_string_shutdown(void);
|
||||||
char *ecore_string_instance(char *string);
|
char *ecore_string_instance(char *string);
|
||||||
void ecore_string_release(char *string);
|
void ecore_string_release(char *string);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#include "ecore_private.h"
|
#include "ecore_private.h"
|
||||||
#include "Ecore_Data.h"
|
#include "Ecore_Data.h"
|
||||||
|
|
||||||
|
static void ecore_string_free_cb(void *data);
|
||||||
|
|
||||||
static Ecore_Hash *ecore_strings = NULL;
|
static Ecore_Hash *ecore_strings = NULL;
|
||||||
|
static int ecore_string_init_count = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup Ecore_String_Group String Instance Functions
|
* @defgroup Ecore_String_Group String Instance Functions
|
||||||
|
@ -10,6 +13,27 @@ static Ecore_Hash *ecore_strings = NULL;
|
||||||
* throughout your program.
|
* throughout your program.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the ecore string internal structure.
|
||||||
|
* @return Zero on failure, non-zero on successful initialization.
|
||||||
|
*/
|
||||||
|
int ecore_string_init()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* No strings have been loaded at this point, so create the hash
|
||||||
|
* table for storing string info for later.
|
||||||
|
*/
|
||||||
|
if (!ecore_string_init_count) {
|
||||||
|
ecore_strings = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
||||||
|
if (!ecore_strings)
|
||||||
|
return 0;
|
||||||
|
ecore_hash_set_free_value(ecore_strings, ecore_string_free_cb);
|
||||||
|
}
|
||||||
|
ecore_string_init_count++;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an instance of a string for use in an ecore program.
|
* Retrieves an instance of a string for use in an ecore program.
|
||||||
* @param string The string to retrieve an instance of.
|
* @param string The string to retrieve an instance of.
|
||||||
|
@ -23,13 +47,6 @@ char *ecore_string_instance(char *string)
|
||||||
|
|
||||||
CHECK_PARAM_POINTER_RETURN("string", string, NULL);
|
CHECK_PARAM_POINTER_RETURN("string", string, NULL);
|
||||||
|
|
||||||
/*
|
|
||||||
* No strings have been loaded at this point, so create the hash
|
|
||||||
* table for storing string info for later.
|
|
||||||
*/
|
|
||||||
if (!ecore_strings)
|
|
||||||
ecore_strings = ecore_hash_new(ecore_str_hash, ecore_str_compare);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for a previous instance of the string, if not found, create
|
* Check for a previous instance of the string, if not found, create
|
||||||
* it.
|
* it.
|
||||||
|
@ -78,3 +95,24 @@ void ecore_string_release(char *string)
|
||||||
FREE(str);
|
FREE(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutdown the ecore string internal structures
|
||||||
|
*/
|
||||||
|
void ecore_string_shutdown()
|
||||||
|
{
|
||||||
|
--ecore_string_init_count;
|
||||||
|
if (!ecore_string_init_count) {
|
||||||
|
ecore_hash_destroy(ecore_strings);
|
||||||
|
ecore_strings = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ecore_string_free_cb(void *data)
|
||||||
|
{
|
||||||
|
Ecore_String *str;
|
||||||
|
|
||||||
|
str = data;
|
||||||
|
FREE(str->string);
|
||||||
|
FREE(str);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue