blob: dfe4a7465ea9476191de48eae272472c191c2994 [file] [log] [blame]
kumarashishg826308d2023-06-23 13:21:22 +00001// Copyright 2020 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FXJS_GC_CONTAINER_TRACE_H_
6#define FXJS_GC_CONTAINER_TRACE_H_
7
8#include <list>
9#include <map>
10#include <set>
11#include <vector>
12
13#include "v8/include/cppgc/member.h"
14#include "v8/include/cppgc/visitor.h"
15
16namespace fxgc {
17
18template <typename T, typename V = cppgc::Visitor>
19void ContainerTrace(V* visitor, const std::list<cppgc::Member<T>>& container) {
20 for (const auto& item : container)
21 visitor->Trace(item);
22}
23
24template <typename T, typename U, typename V = cppgc::Visitor>
25void ContainerTrace(V* visitor,
26 const std::map<cppgc::Member<T>, U>& container) {
27 for (const auto& item : container) {
28 visitor->Trace(item.first);
29 }
30}
31
32template <typename T, typename U, typename V = cppgc::Visitor>
33void ContainerTrace(V* visitor,
34 const std::map<U, cppgc::Member<T>>& container) {
35 for (const auto& item : container)
36 visitor->Trace(item.second);
37}
38
39template <typename T, typename U, typename V = cppgc::Visitor>
40void ContainerTrace(
41 V* visitor,
42 const std::map<cppgc::Member<U>, cppgc::Member<T>>& container) {
43 for (const auto& item : container) {
44 visitor->Trace(item.first);
45 visitor->Trace(item.second);
46 }
47}
48
49template <typename T, typename V = cppgc::Visitor>
50void ContainerTrace(V* visitor, const std::set<cppgc::Member<T>>& container) {
51 for (const auto& item : container)
52 visitor->Trace(item);
53}
54
55template <typename T, typename V = cppgc::Visitor>
56void ContainerTrace(V* visitor,
57 const std::vector<cppgc::Member<T>>& container) {
58 for (const auto& item : container)
59 visitor->Trace(item);
60}
61
62} // namespace fxgc
63
64using fxgc::ContainerTrace;
65
66#endif // FXJS_GC_CONTAINER_TRACE_H_