Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions include/container/seadStrTreeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ class StrTreeMap : public TreeMapImpl<SafeString>
char mKeyData[MaxKeyLength + 1];
};

template <typename T>
class ForEachConstContext
{
public:
ForEachConstContext(const T& callback) : context(callback) {}

void call(TreeMapNode<SafeString>* node)
{
Node* strNode = static_cast<Node*>(node);
context(strNode->key(), strNode->value());
}

private:
const T& context;
};

void allocBuffer(s32 node_max, Heap* heap, s32 alignment = sizeof(void*));
void setBuffer(s32 node_max, void* buffer);
void freeBuffer();
Expand Down Expand Up @@ -153,12 +169,14 @@ inline typename StrTreeMap<N, Value>::Node* StrTreeMap<N, Value>::find(const Saf

template <s32 N, typename Value>
template <typename Callable>
inline void StrTreeMap<N, Value>::forEach(const Callable& delegate) const
inline void StrTreeMap<N, Value>::forEach(const Callable& callback) const
{
MapImpl::forEach([&delegate](auto* base_node) {
auto* node = static_cast<Node*>(base_node);
delegate(node->key(), node->value());
});
ForEachConstContext<Callable> ctx(callback);

Delegate1<ForEachConstContext<Callable>, typename MapImpl::Node*> delegate(
&ctx, &ForEachConstContext<Callable>::call);

MapImpl::forEach(delegate);
}

template <s32 N, typename Value>
Expand Down
2 changes: 2 additions & 0 deletions include/container/seadTreeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class TreeMapNode
virtual ~TreeMapNode() = default;
virtual void erase_() = 0;

Key& key() { return mKey; }

const Key& key() const { return mKey; }

protected:
Expand Down