wofi-map(3)

✨ NAME ✨

wofi β€” the Map API functions and docs, bestie πŸ’– (this is the wofi-map(3) page, in case the vibe check didn't tell you)


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so. the functions we're about to spill about are the ones you use to vibe with wofi's config and map. they live in map.h, no cap. πŸ“βœ¨


πŸ‘‘ MAP FUNCTIONS πŸ‘‘

these are the girlies you call to mess with a struct map* πŸ’…

  • struct map* map_init(void) β€” allocates and hands you back a brand new string map. heads up tho: string maps only support string values, that's the whole thing, periodt. πŸŽ€
  • struct map* map_init_void(void) β€” allocates and hands you back a brand new void map. a void map is the flexible one, she supports values of any type. main character energy fr fr. 🌈
  • void map_free(struct map* map) β€” frees the map you gave it plus all its keys. now listen: values only get freed if it's a string map. so if you're on a void map, the values are your problem, not hers. 😭
  • bool map_put(struct map* map, const char* key, char* value) β€” returns true if the map you passed is a string map. otherwise it returns false and prints a message to stderr. πŸ’€
    • struct map* map β€” the map you're inserting into.
    • const char* key β€” the key the value gets stored under. this key gets handed to strdup() before it's saved, and it'll be freed when you run map_free().
    • char* value β€” the value you're storing. this value gets handed to strdup() before it's saved and will be freed when you run map_free(). if the value is NULL it will not be given to strdup(). πŸ™ˆ
  • bool map_put_void(struct map* map, const char* key, void* value) β€” returns true if the map you passed is a void map. otherwise false plus a message printed to stderr. πŸ’€
    • struct map* map β€” the map you're inserting into.
    • const char* key β€” the key the value gets stored under. it's given to strdup() before being saved and will be freed when you run map_free().
    • void* value β€” the value to store. this pointer just gets stored in the map, so it's on the caller to free this and it will not be freed when you run map_free(). lowkey important, don't forget her. 🫢
  • void* map_get(struct map* map, const char* key) β€” returns the value stored under key, or NULL if no such key exists. also: NULL can come back even when it was stored there via map_put() or map_put_void(). so yeah, NULL is giving ambiguous, sorry bestie. 😭
    • struct map* map β€” the map you're getting the value from.
    • const char* key β€” the key to look up.
  • bool map_contains(struct map* map, const char* key) β€” returns true if the key exists, false otherwise. this one is implemented as a value != NULL check, which means a NULL value is considered to not exist. yes really. that's the rule. ⭐
    • struct map* map β€” the map you're checking against.
    • const char* key β€” the key you're checking for.
  • size_t map_size(struct map* map) β€” returns the number of entries in this map. the headcount, the roster, the guest list. πŸ”₯
    • struct map* map β€” the map you want the size of.

tiny reminder that map_put only slays on string maps and map_put_void only slays on void maps β€” mismatch means false plus a lil message on stderr, so read your errors, i'm begging πŸ₯Ί

and that's the whole page, babe! this was wofi-map(3) from the Library Functions Manual β€” signed, sealed, and dated as wofi-map(3) at the bottom. go forth and map responsibly πŸ’œβœ¨