Implementation of the supporting functions for the MapOfStrings structure for managing a map of strings keyed by another string. More...
#include <memory.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "mapofstrings.h"
Go to the source code of this file.
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. | |
Implementation of the supporting functions for the MapOfStrings structure for managing a map of strings keyed by another string.
Definition in file mapofstrings.c.
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().