Setup an init/shutdown system for shared strings.

SVN revision: 18658
This commit is contained in:
rbdpngn 2005-11-27 08:00:39 +00:00 committed by rbdpngn
parent ec44ab043d
commit 46518fa24f
2 changed files with 47 additions and 7 deletions

View File

@ -419,6 +419,8 @@ extern "C" {
int references;
};
int ecore_string_init(void);
void ecore_string_shutdown(void);
char *ecore_string_instance(char *string);
void ecore_string_release(char *string);

View File

@ -1,7 +1,10 @@
#include "ecore_private.h"
#include "Ecore_Data.h"
static void ecore_string_free_cb(void *data);
static Ecore_Hash *ecore_strings = NULL;
static int ecore_string_init_count = 0;
/**
* @defgroup Ecore_String_Group String Instance Functions
@ -10,6 +13,27 @@ static Ecore_Hash *ecore_strings = NULL;
* 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.
* @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);
/*
* 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
* it.
@ -78,3 +95,24 @@ void ecore_string_release(char *string)
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);
}