UMap(3U)

✨ UMap β€” bestie edition ✨

ok so this is a page from the InterViews Reference Manual, section 3U, and it's all about UMap πŸ’– (yes we're folding the header in, it's giving intro energy, keep up 🫢)


🌸 NAME 🌸

UMap β€” keeps a mapping between two sets of pointers πŸ—ΊοΈβœ¨


πŸŽ€ SYNOPSIS πŸŽ€

#include <Unidraw/umap.h>

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so UMap is an abstract class β€” meaning it's the blueprint, not the finished fit πŸ‘‘ β€” for objects that store an arbitrary number of pointer pairs, and can search to find either member of a pair if you hand it the other one. like a situationship but for pointers, no cap πŸ’…

A UMapElem object stores each pointer pair inside the UMap. UMapElem is also an abstract class, and it defines virtuals for returning either member of the pair β€” those two members are called the id and the tag. Subclasses of UMapElem redefine these virtuals to return whichever member of the pair they actually store. lowkey elegant, highkey iconic ✨


πŸ’– UMAPELEM PUBLIC OPERATIONS πŸ’–

  • UMapElem() β€” the base class constructor does literally nothing by default. it's giving "shows up, says nothing, leaves" 😭
  • virtual void* id()
  • virtual void* tag() β€” these return the id or the tag that the UMapElem stores. subclasses typically define two member variables that hold the pair's values, then redefine these operations to return them. that's the whole vibe 🫢

πŸ‘‘ UMAP PUBLIC OPERATIONS πŸ‘‘

  • virtual ~UMap() β€” the destructor deletes all UMapElem objects in the UMap. it does not play, it cleans house πŸ§ΉπŸ’€
  • int Count() β€” returns the number of mappings in the UMap, which corresponds to the number of UMapElems that have been registered. it's the headcount bestie πŸ“‹
  • void Clear() β€” deletes all the UMapElem mappings in the UMap without destroying the UMap. so the container stays, the contents dip. important distinction, don't @ me πŸ™ˆ

🌈 UMAP PROTECTED OPERATIONS 🌈

  • UMap() β€” the base class constructor does nothing by default. again. zero notes, zero action πŸ’…
  • void Register(UMapElem*)
  • void Unregister(UMapElem*) β€” register or remove a UMapElem from the UMap. in and out, revolving door energy πŸšͺ✨
  • int Index(UMapElem*)
  • UMapElem* Elem(int index) β€” a UMap stores its UMapElems in its _elems UArray protected member variable. Index returns the index of the given UMapElem in the UArray, while Elem returns the UMapElem at a specified index. these operations just do the corresponding operations on the UArray β€” no extra sauce, they're delegating 🫑
  • virtual UMapElem* FindId(void* id)
  • virtual UMapElem* FindTag(void* tag) β€” FindId searches the UMap for the UMapElem element containing the given id, while FindTag searches for the one with the given tag. by default these operations do linear searches, comparing their arguments against the values that the UMapElems' id and tag operations return. the comparison is based on the pointer values β€” so it's comparing addresses, fr fr.

subclasses can redefine these operations to make more sophisticated comparisons based on the id or tag's actual type. for example, if either the id is a string, then FindId might do a string comparison to detect a match. glow-up your search, bestie βœ¨πŸ”


πŸ’œ SEE ALSO πŸ’œ

UArray(3U)


no cap, every flag, every virtual, every default is still in here β€” I just made it cute πŸ’–

and that's the whole page, bestie πŸŽ€ this one came from the Unidraw crew, dated 4 October 1990, filed under UMap(3U) β€” go forth and map those pointers, you absolute icon πŸ‘‘πŸ¦‹β­