Files
ss/include/c/c_owner_set.h
T
lepelog 42880ec9ae init
2023-08-09 16:59:04 +02:00

55 lines
1.4 KiB
C++

#pragma once
// This file was ported from https://github.com/NSMBW-Community/NSMBW-Decomp/blob/master/include/dol/cLib/c_owner_set.hpp
#include <types.h>
/// @file
/// @brief A set node with a pointer to the owning container. See cOwnerSetMg_c.
/// @note Unofficial name.
class cOwnerSetNd_c {
public:
void *getOwner() const { return mpOwner; }
cOwnerSetNd_c *getNext() const { return mpNext; }
private:
void* mpOwner; ///< The set that contains this node.
cOwnerSetNd_c* mpNext; ///< The next node in the set.
friend class cOwnerSetMg_c;
};
/// @brief A set container. See cOwnerSetNd_c.
/// @details The set is implemented as a singly-linked list.
/// @note Unofficial name.
class cOwnerSetMg_c {
public:
/// @brief Constructs a new set container.
cOwnerSetMg_c() : mpRoot(nullptr) {}
/// @brief Destroys the set.
~cOwnerSetMg_c() { clear(); };
/**
* @brief Adds a node to the set.
*
* @param nd The node to add.
* @param owner The owner of the node.
*/
void add(cOwnerSetNd_c *nd, void *owner);
/**
* @brief Removes a node from the set.
*
* @param nd The node to remove.
* @param owner The owner of the node.
*/
void remove(cOwnerSetNd_c *nd, void *owner);
private:
/// @brief Clears out the set and unlinks all child nodes.
void clear();
cOwnerSetNd_c* mpRoot; ///< The first element of the set.
};