ilist_node.h revision fd7a918e5890a6c0611ab6b3fca7001d16593844
1//==-- llvm/ADT/ilist_node.h - Intrusive Linked List Helper ------*- C++ -*-==// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 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. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_ADT_ILIST_NODE_H 16#define LLVM_ADT_ILIST_NODE_H 17 18#include "llvm/Config/config.h" 19 20namespace llvm { 21 22template<typename NodeTy> 23struct ilist_traits; 24 25/// ilist_half_node - Base class that provides prev services for sentinels. 26/// 27template<typename NodeTy> 28class ilist_half_node { 29 friend struct ilist_traits<NodeTy>; 30 NodeTy *Prev; 31protected: 32 NodeTy *getPrev() { return Prev; } 33 const NodeTy *getPrev() const { return Prev; } 34 void setPrev(NodeTy *P) { Prev = P; } 35 ilist_half_node() : Prev(0) {} 36}; 37 38template<typename NodeTy> 39struct ilist_nextprev_traits; 40 41/// ilist_node - Base class that provides next/prev services for nodes 42/// that use ilist_nextprev_traits or ilist_default_traits. 43/// 44template<typename NodeTy> 45class ilist_node : ilist_half_node<NodeTy> { 46 friend struct ilist_nextprev_traits<NodeTy>; 47 friend struct ilist_traits<NodeTy>; 48 NodeTy *Next; 49 NodeTy *getNext() { return Next; } 50 const NodeTy *getNext() const { return Next; } 51 void setNext(NodeTy *N) { Next = N; } 52protected: 53 ilist_node() : Next(0) {} 54}; 55 56/// When assertions are off, the Next field of sentinels 57/// will not be accessed. So it is not necessary to allocate 58/// space for it. The following macro selects the most 59/// efficient traits class. The LLVM_COMPACT_SENTINELS 60/// configuration variable controls this. 61/// 62#if defined(LLVM_COMPACT_SENTINELS) && LLVM_COMPACT_SENTINELS 63# define ILIST_NODE ilist_half_node 64#else 65# define ILIST_NODE ilist_node 66#endif 67 68} // End llvm namespace 69 70#endif 71