1 //==-- llvm/ADT/ilist_node.h - Intrusive Linked List Helper ------*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ilist_node class template, which is a convenient
11 // base class for creating classes that can be used with ilists.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ADT_ILIST_NODE_H
16 #define LLVM_ADT_ILIST_NODE_H
20 template<typename NodeTy>
22 template <typename NodeTy> struct ilist_embedded_sentinel_traits;
23 template <typename NodeTy> struct ilist_half_embedded_sentinel_traits;
25 /// ilist_half_node - Base class that provides prev services for sentinels.
27 template<typename NodeTy>
28 class ilist_half_node {
29 friend struct ilist_traits<NodeTy>;
30 friend struct ilist_half_embedded_sentinel_traits<NodeTy>;
33 NodeTy *getPrev() { return Prev; }
34 const NodeTy *getPrev() const { return Prev; }
35 void setPrev(NodeTy *P) { Prev = P; }
36 ilist_half_node() : Prev(nullptr) {}
39 template<typename NodeTy>
40 struct ilist_nextprev_traits;
42 /// ilist_node - Base class that provides next/prev services for nodes
43 /// that use ilist_nextprev_traits or ilist_default_traits.
45 template<typename NodeTy>
46 class ilist_node : private ilist_half_node<NodeTy> {
47 friend struct ilist_nextprev_traits<NodeTy>;
48 friend struct ilist_traits<NodeTy>;
49 friend struct ilist_half_embedded_sentinel_traits<NodeTy>;
50 friend struct ilist_embedded_sentinel_traits<NodeTy>;
52 NodeTy *getNext() { return Next; }
53 const NodeTy *getNext() const { return Next; }
54 void setNext(NodeTy *N) { Next = N; }
56 ilist_node() : Next(nullptr) {}
59 /// @name Adjacent Node Accessors
62 /// \brief Get the previous node, or 0 for the list head.
63 NodeTy *getPrevNode() {
64 NodeTy *Prev = this->getPrev();
66 // Check for sentinel.
73 /// \brief Get the previous node, or 0 for the list head.
74 const NodeTy *getPrevNode() const {
75 const NodeTy *Prev = this->getPrev();
77 // Check for sentinel.
84 /// \brief Get the next node, or 0 for the list tail.
85 NodeTy *getNextNode() {
86 NodeTy *Next = getNext();
88 // Check for sentinel.
95 /// \brief Get the next node, or 0 for the list tail.
96 const NodeTy *getNextNode() const {
97 const NodeTy *Next = getNext();
99 // Check for sentinel.
100 if (!Next->getNext())
109 } // End llvm namespace