LLVM API Documentation

ilist_node.h
Go to the documentation of this file.
00001 //==-- llvm/ADT/ilist_node.h - Intrusive Linked List Helper ------*- C++ -*-==//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the ilist_node class template, which is a convenient
00011 // base class for creating classes that can be used with ilists.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_ADT_ILIST_NODE_H
00016 #define LLVM_ADT_ILIST_NODE_H
00017 
00018 namespace llvm {
00019 
00020 template<typename NodeTy>
00021 struct ilist_traits;
00022 
00023 /// ilist_half_node - Base class that provides prev services for sentinels.
00024 ///
00025 template<typename NodeTy>
00026 class ilist_half_node {
00027   friend struct ilist_traits<NodeTy>;
00028   NodeTy *Prev;
00029 protected:
00030   NodeTy *getPrev() { return Prev; }
00031   const NodeTy *getPrev() const { return Prev; }
00032   void setPrev(NodeTy *P) { Prev = P; }
00033   ilist_half_node() : Prev(nullptr) {}
00034 };
00035 
00036 template<typename NodeTy>
00037 struct ilist_nextprev_traits;
00038 
00039 /// ilist_node - Base class that provides next/prev services for nodes
00040 /// that use ilist_nextprev_traits or ilist_default_traits.
00041 ///
00042 template<typename NodeTy>
00043 class ilist_node : private ilist_half_node<NodeTy> {
00044   friend struct ilist_nextprev_traits<NodeTy>;
00045   friend struct ilist_traits<NodeTy>;
00046   NodeTy *Next;
00047   NodeTy *getNext() { return Next; }
00048   const NodeTy *getNext() const { return Next; }
00049   void setNext(NodeTy *N) { Next = N; }
00050 protected:
00051   ilist_node() : Next(nullptr) {}
00052 
00053 public:
00054   /// @name Adjacent Node Accessors
00055   /// @{
00056 
00057   /// \brief Get the previous node, or 0 for the list head.
00058   NodeTy *getPrevNode() {
00059     NodeTy *Prev = this->getPrev();
00060 
00061     // Check for sentinel.
00062     if (!Prev->getNext())
00063       return nullptr;
00064 
00065     return Prev;
00066   }
00067 
00068   /// \brief Get the previous node, or 0 for the list head.
00069   const NodeTy *getPrevNode() const {
00070     const NodeTy *Prev = this->getPrev();
00071 
00072     // Check for sentinel.
00073     if (!Prev->getNext())
00074       return nullptr;
00075 
00076     return Prev;
00077   }
00078 
00079   /// \brief Get the next node, or 0 for the list tail.
00080   NodeTy *getNextNode() {
00081     NodeTy *Next = getNext();
00082 
00083     // Check for sentinel.
00084     if (!Next->getNext())
00085       return nullptr;
00086 
00087     return Next;
00088   }
00089 
00090   /// \brief Get the next node, or 0 for the list tail.
00091   const NodeTy *getNextNode() const {
00092     const NodeTy *Next = getNext();
00093 
00094     // Check for sentinel.
00095     if (!Next->getNext())
00096       return nullptr;
00097 
00098     return Next;
00099   }
00100 
00101   /// @}
00102 };
00103 
00104 } // End llvm namespace
00105 
00106 #endif