epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrTLList_DEFINED |
| 12 | #define GrTLList_DEFINED |
| 13 | |
| 14 | #include "GrNoncopyable.h" |
| 15 | |
| 16 | template <typename T> class GrTLList : GrNoncopyable { |
| 17 | public: |
| 18 | class Entry { |
| 19 | Entry* fPrev; |
| 20 | Entry* fNext; |
| 21 | }; |
| 22 | |
| 23 | GrTLList() : fHead(NULL), fTail(NULL) {} |
| 24 | #if GR_DEBUG |
| 25 | ~GrTLList() { |
| 26 | GrAssert(NULL == fHead); |
| 27 | GrAssert(NULL == ftail); |
| 28 | } |
| 29 | #endif |
| 30 | |
| 31 | T* head() const { return fHead; } |
| 32 | T* tail() const { return fTail; } |
| 33 | |
| 34 | void addToHead(T*); |
| 35 | void addToTail(T*); |
| 36 | void removeFromList(T*); |
| 37 | |
| 38 | private: |
| 39 | Entry* fHead; |
| 40 | Entry* fTail; |
| 41 | |
| 42 | friend class Entry; |
| 43 | }; |
| 44 | |
| 45 | |
| 46 | class Parent { |
| 47 | GrTDLList<Child> fList; |
| 48 | }; |
| 49 | |
| 50 | class Child : public GrTLList::Entry<Child> { |
| 51 | }; |
| 52 | |
| 53 | #endif |
| 54 | |