Declaration of the MapOfStrings structure and supporting functions for managing a map of strings keyed by another string. More...
Go to the source code of this file.
Classes | |
struct | MapOfStringsEntry |
Represents an entry in the MapOfStrings structure, associating a string "key" with a StringList "value". More... | |
struct | MapOfStrings |
Represents a list of structures that map strings to ConstStringList objects. More... | |
Macros | |
#define | __MAPOFSTRINGS_H__ |
Functions | |
void | MapOfStrings_Initialize (MapOfStrings *map) |
Initialize the given MapOfStrings structure so it is ready for use. | |
void | MapOfStrings_Clear (MapOfStrings *map) |
Clear the given MapOfStrings object, releasing all memory associated with it. Leaves the object in an initialize state to be reused, if desired. | |
bool | MapOfStrings_AddStringList (MapOfStrings *map, const char *key, ConstStringList *value) |
Add a key/value association to the given MapOfStrings object. The MapOfStrings object takes ownership of the key and value arguments and will free them when MapOfStrings_Clear() is called in the object. | |
bool | MapOfStrings_AddArray (MapOfStrings *map, const char *key, const char **value) |
Add a key/value association to the given MapOfStrings object, where the value is provided as a NULL-terminated array of string pointer. This array is copied into a StringList object for storage in the map. | |
int | MapOfStrings_Find (MapOfStrings *map, const char *key) |
Find the specified key in the given MapOfStrings object, returning an index into the object. | |
Declaration of the MapOfStrings structure and supporting functions for managing a map of strings keyed by another string.
Definition in file helpers/mapofstrings.h.
#define __MAPOFSTRINGS_H__ |
Definition at line 8 of file helpers/mapofstrings.h.
bool MapOfStrings_AddArray | ( | MapOfStrings * | map, |
const char * | key, | ||
const char ** | value | ||
) |
Add a key/value association to the given MapOfStrings object, where the value is provided as a NULL-terminated array of string pointer. This array is copied into a StringList object for storage in the map.
map | The MapOfStrings object to add to. |
key | The key value to be added. This must be allocated, directly or indirectly, with malloc() as it will be freed when the MapOfStrings object is cleared. |
value | An array of string pointers terminated by a NULL pointer. |
Definition at line 77 of file mapofstrings.c.
References ConstStringList_AddStrings(), and MapOfStrings_AddStringList().
Referenced by Village_Load().
bool MapOfStrings_AddStringList | ( | MapOfStrings * | map, |
const char * | key, | ||
ConstStringList * | value | ||
) |
Add a key/value association to the given MapOfStrings object. The MapOfStrings object takes ownership of the key and value arguments and will free them when MapOfStrings_Clear() is called in the object.
map | The MapOfStrings object to add to. |
key | The key value to be added. This must be allocated, directly or indirectly, with malloc() as it will be freed when the MapOfStrings object is cleared. |
value | The ConstStringList object to add as the value. This must be allocated with malloc() as it will be freed when the MapOfStrings object is cleared. |
Definition at line 44 of file mapofstrings.c.
References MapOfStrings::entries, MapOfStrings::entries_count, MapOfStringsEntry::key, and MapOfStringsEntry::value.
Referenced by MapOfStrings_AddArray().
void MapOfStrings_Clear | ( | MapOfStrings * | map | ) |
Clear the given MapOfStrings object, releasing all memory associated with it. Leaves the object in an initialize state to be reused, if desired.
map | The MapOfStrings object to clear. |
Definition at line 28 of file mapofstrings.c.
References ConstStringList_Clear(), MapOfStrings::entries, MapOfStrings::entries_count, MapOfStrings_Initialize(), and MapOfStringsEntry::value.
Referenced by Shop_Destroy().
int MapOfStrings_Find | ( | MapOfStrings * | map, |
const char * | key | ||
) |
Find the specified key in the given MapOfStrings object, returning an index into the object.
map | The MapOfStrings object to search. |
key | The key to search for. |
Definition at line 105 of file mapofstrings.c.
References MapOfStrings::entries, MapOfStrings::entries_count, and MapOfStringsEntry::key.
Referenced by Shop_DoesShopSellItem(), and Shop_PlaceOrder().
void MapOfStrings_Initialize | ( | MapOfStrings * | map | ) |
Initialize the given MapOfStrings structure so it is ready for use.
Alternatively, declare the MapOfStrings instance like this:
map | The MapOfStrings object to initialize. |
Definition at line 16 of file mapofstrings.c.
References MapOfStrings::entries, and MapOfStrings::entries_count.
Referenced by MapOfStrings_Clear(), and Shop_Create().