Implementation of the supporting functions for the MapOfInt structure for managing a map of integers keyed by a string. More...
#include <memory.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "mapofint.h"
Go to the source code of this file.
Functions | |
void | MapOfInt_Initialize (MapOfInt *map) |
Initialize the given MapOfInt structure so it is ready for use. | |
void | MapOfInt_Clear (MapOfInt *map) |
Clear the given MapOfInt object, releasing all memory associated with it. Leaves the object in an initialize state to be reused, if desired. | |
bool | MapOfInt_Add (MapOfInt *map, const char *key, int value) |
Add a key/value association to the given MapOfInt object. The MapOfInt object takes ownership of the key and value arguments and will free them when MapOfInt_Clear() is called in the object. | |
int | MapOfInt_Find (MapOfInt *map, const char *key) |
Find the specified key in the given MapOfInt object, returning an index into the object. | |
Implementation of the supporting functions for the MapOfInt structure for managing a map of integers keyed by a string.
Definition in file mapofint.c.
bool MapOfInt_Add | ( | MapOfInt * | map, |
const char * | key, | ||
int | value | ||
) |
Add a key/value association to the given MapOfInt object. The MapOfInt object takes ownership of the key and value arguments and will free them when MapOfInt_Clear() is called in the object.
map | The MapOfInt 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 MapOfInt object is cleared. |
value | The integer being mapped to the key. |
Definition at line 40 of file mapofint.c.
References MapOfInt::entries, MapOfInt::entries_count, MapOfIntEntry::key, and MapOfIntEntry::value.
Referenced by Shop_AddItemToInventory().
void MapOfInt_Clear | ( | MapOfInt * | map | ) |
Clear the given MapOfInt object, releasing all memory associated with it. Leaves the object in an initialize state to be reused, if desired.
map | The MapOfInt object to clear. |
Definition at line 28 of file mapofint.c.
References MapOfInt::entries, and MapOfInt_Initialize().
Referenced by Shop_Destroy().
int MapOfInt_Find | ( | MapOfInt * | map, |
const char * | key | ||
) |
Find the specified key in the given MapOfInt object, returning an index into the object.
map | The MapOfInt object to search. |
key | The key to search for. |
Definition at line 72 of file mapofint.c.
References MapOfInt::entries, MapOfInt::entries_count, and MapOfIntEntry::key.
Referenced by Shop_AddItemToInventory(), Shop_IsItemInStock(), and Shop_PickupOrder().
void MapOfInt_Initialize | ( | MapOfInt * | map | ) |
Initialize the given MapOfInt structure so it is ready for use.
Alternatively, declare the MapOfInt instance like this:
map | The MapOfInt object to initialize. |
Definition at line 16 of file mapofint.c.
References MapOfInt::entries, and MapOfInt::entries_count.
Referenced by MapOfInt_Clear(), and Shop_Create().