LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_string.c File Reference

Functions

LG_Stringlg_string_get_root ()
 
zboolean is_lg_string (LG_String *node)
 
LG_Stringlg_string_new (const char *data)
 
const char * lg_string_get_data (LG_String *string)
 
void lg_string_remove (LG_String *node)
 
void lg_string_remove_all ()
 
int lg_string_count (uint32_t *total_size)
 
void lg_string_info (LG_String *node)
 

Detailed Description

Unique global doubly-linked list of dynamically allocated strings used specifically to store path efficiently in struct instances during runtime, similarily to the LG_Texture implementation).

Max string length = LG_STRING_MAX_LEN, defined in lg_string.h

Not to be used to store paths in files or configs, use instead (const char *) lg_string_get_data().

#define LG_STRING_MAX_LEN 2048 // Is this making sense ?
#define LG_STRING_SIG "LG_String"
#define LG_STRING_SIG_LEN 9
typedef struct LG_String LG_String;
struct LG_String {
const char *data; // May be NULL
uint32_t size;
LG_String *prev;
LG_String *next;
uint8_t sig[LG_STRING_SIG_LEN]; // Not NULL-terminated
};

Function Documentation

◆ lg_string_get_root()

LG_String* lg_string_get_root ( )

Returns the first node (RootString0) of the unique global doubly-linked list of dynamically allocated strings

Returns
The first node

◆ is_lg_string()

zboolean is_lg_string ( LG_String node)

Check if a LG_String node is valid, ie non NULL and with a valid signature

Returns
TRUE if OK, FALSE otherwise

◆ lg_string_new()

LG_String* lg_string_new ( const char *  data)

Create a new LG_String instance, set content, AND add it at end of the unique gloabal strings list

=== WARNING: data max size = LG_STRING_MAX_LEN (is this making sense ?) ===

Parameters
dataString data, most probably some text - can't be an empty string, ie ""
Returns
A pointer to a new LG_String instance, NULL on error

◆ lg_string_get_data()

const char* lg_string_get_data ( LG_String string)

Get string data that you can copy in case you need to remove the string (huh ?)

Actually just return string->data

Parameters
stringA pointer to a LG_String instance
Returns
The string data, most probably some text

◆ lg_string_remove()

void lg_string_remove ( LG_String node)

Remove string from the unique gloabal strings list, and free resources

Can't remove the root node

Parameters
nodeA pointer to a LG_String instance

◆ lg_string_remove_all()

void lg_string_remove_all ( )

Remove and free all strings and resources (but the root node)

WARNING:

  • This func should probably never be called directly, unless you know exactly what you are doing
  • Must be called last, ie after freeing modules using it
  • This func is always called by lg_quit()

◆ lg_string_count()

int lg_string_count ( uint32_t *  total_size)

Return total number of strings in the unique gloabal strings list (including the root node)

Parameters
total_sizePointer to uint32_t that will get the total size
Returns
The total number of strings and the total size of the list

◆ lg_string_info()

void lg_string_info ( LG_String node)

Print out LG_String info

Parameters
nodeA pointer to a LG_String instance
LG_String
Definition: lg_string.h:15