1 // 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
16 namespace fxgc {
17
18 template <typename T, typename V = cppgc::Visitor>
ContainerTrace(V * visitor,const std::list<cppgc::Member<T>> & container)19 void ContainerTrace(V* visitor, const std::list<cppgc::Member<T>>& container) {
20 for (const auto& item : container)
21 visitor->Trace(item);
22 }
23
24 template <typename T, typename U, typename V = cppgc::Visitor>
ContainerTrace(V * visitor,const std::map<cppgc::Member<T>,U> & container)25 void 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
32 template <typename T, typename U, typename V = cppgc::Visitor>
ContainerTrace(V * visitor,const std::map<U,cppgc::Member<T>> & container)33 void 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
39 template <typename T, typename U, typename V = cppgc::Visitor>
ContainerTrace(V * visitor,const std::map<cppgc::Member<U>,cppgc::Member<T>> & container)40 void 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
49 template <typename T, typename V = cppgc::Visitor>
ContainerTrace(V * visitor,const std::set<cppgc::Member<T>> & container)50 void ContainerTrace(V* visitor, const std::set<cppgc::Member<T>>& container) {
51 for (const auto& item : container)
52 visitor->Trace(item);
53 }
54
55 template <typename T, typename V = cppgc::Visitor>
ContainerTrace(V * visitor,const std::vector<cppgc::Member<T>> & container)56 void 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
64 using fxgc::ContainerTrace;
65
66 #endif // FXJS_GC_CONTAINER_TRACE_H_
67