Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/pdf/SkSinglyLinkedList.h

Issue 1839633003: SkPDF: PDFDevice::ContentEntry now implemented with SinglyLinkedList (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-03-28 (Monday) 13:12:45 EDT Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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 #ifndef SkSinglyLinkedList_DEFINED
8 #define SkSinglyLinkedList_DEFINED
9
10 #include <utility>
11
12 #include "SkTypes.h"
13
14 template <typename T> class SkSinglyLinkedList {
15 struct Node;
16 public:
17 SkSinglyLinkedList() : fHead(nullptr), fTail(nullptr) {}
18 ~SkSinglyLinkedList() { this->reset(); }
19 void reset() {
20 SkASSERT(fHead != nullptr || nullptr == fTail);
21 Node* node = fHead;
22 while (node) {
23 Node* next = node->fNext;
24 SkASSERT(next != nullptr || node == fTail);
25 delete node;
26 node = next;
27 }
28 fHead = nullptr;
29 fTail = nullptr;
30 }
31 T* back() { return fTail ? &fTail->fData : nullptr; }
32 T* front() { return fHead ? &fHead->fData : nullptr; }
33 #ifdef SK_DEBUG
34 int count() { // O(n), debug only.
35 int count = 0;
36 for (Node* node = fHead; node; node = node->fNext) {
37 ++count;
38 }
39 return count;
40 }
41 #endif
42 void pop_front() {
43 if (Node* node = fHead) {
44 fHead = node->fNext;
45 delete node;
46 if (fHead == nullptr) {
47 fTail = nullptr;
48 }
49 }
50 }
51 template <class... Args> T* emplace_front(Args&&... args) {
52 Node* n = new Node(std::forward<Args>(args)...);
53 n->fNext = fHead;
54 if (!fTail) {
55 fTail = n;
56 SkASSERT(!fHead);
57 }
58 fHead = n;
59 return &n->fData;
60 }
61 template <class... Args> T* emplace_back(Args&&... args) {
62 Node* n = new Node(std::forward<Args>(args)...);
63 if (fTail) {
64 fTail->fNext = n;
65 } else {
66 fHead = n;
67 }
68 fTail = n;
69 return &n->fData;
70 }
71 class ConstIter {
72 public:
73 void operator++() { fNode = fNode->fNext; }
74 const T& operator*() const { return fNode->fData; }
75 bool operator!=(const ConstIter& rhs) const { return fNode != rhs.fNode; }
76 ConstIter(const Node* n) : fNode(n) {}
77 private:
78 const Node* fNode;
79 };
80 ConstIter begin() const { return ConstIter(fHead); }
81 ConstIter end() const { return ConstIter(nullptr); }
82
83 private:
84 struct Node {
85 T fData;
86 Node* fNext;
87 template <class... Args>
88 Node(Args&&... args) : fData(std::forward<Args>(args)...), fNext(nullptr ) {}
89 };
90 Node* fHead;
91 Node* fTail;
92 SkSinglyLinkedList(const SkSinglyLinkedList<T>&) = delete;
93 SkSinglyLinkedList& operator=(const SkSinglyLinkedList<T>&) = delete;
94 };
95 #endif // SkSinglyLinkedList_DEFINED
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698