Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkArenaAllocList.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkArenaAllocList_DEFINED
9#define SkArenaAllocList_DEFINED
10
12#include "src/base/SkArenaAlloc.h" // IWYU pragma: keep
13
14#include <utility>
15
16/**
17 * A singly linked list of Ts stored in a SkArenaAlloc. The arena rather than the list owns
18 * the elements. This supports forward iteration and range based for loops.
19 */
20template <typename T>
22private:
23 struct Node;
24
25public:
26 SkArenaAllocList() = default;
27
28 void reset() { fHead = fTail = nullptr; }
29
30 template <typename... Args>
31 inline T& append(SkArenaAlloc* arena, Args... args);
32
33 class Iter {
34 public:
35 Iter() = default;
36 inline Iter& operator++();
37 T& operator*() const { return fCurr->fT; }
38 T* operator->() const { return &fCurr->fT; }
39 bool operator==(const Iter& that) const { return fCurr == that.fCurr; }
40 bool operator!=(const Iter& that) const { return !(*this == that); }
41
42 private:
43 friend class SkArenaAllocList;
44 explicit Iter(Node* node) : fCurr(node) {}
45 Node* fCurr = nullptr;
46 };
47
48 Iter begin() { return Iter(fHead); }
49 Iter end() { return Iter(); }
50 Iter tail() { return Iter(fTail); }
51
52private:
53 struct Node {
54 template <typename... Args>
55 Node(Args... args) : fT(std::forward<Args>(args)...) {}
56 T fT;
57 Node* fNext = nullptr;
58 };
59 Node* fHead = nullptr;
60 Node* fTail = nullptr;
61};
62
63template <typename T>
64template <typename... Args>
66 SkASSERT(!fHead == !fTail);
67 auto* n = arena->make<Node>(std::forward<Args>(args)...);
68 if (!fTail) {
69 fHead = fTail = n;
70 } else {
71 fTail = fTail->fNext = n;
72 }
73 return fTail->fT;
74}
75
76template <typename T>
78 fCurr = fCurr->fNext;
79 return *this;
80}
81
82#endif
Instance * fNext
#define SkASSERT(cond)
Definition SkAssert.h:116
bool operator==(const Iter &that) const
bool operator!=(const Iter &that) const
SkArenaAllocList()=default
T & append(SkArenaAlloc *arena, Args... args)
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition dart.idl:29
Definition ref_ptr.h:256
#define T