ilist_node.h revision 2600ca8b3f3602d0904289eeed3d26f3d7aad2ae
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#undef LLVM_COMPACTIFY_SENTINELS
19/// @brief activate small sentinel structs
20/// Comment out if you want better debuggability
21/// of ilist<> end() iterators.
22/// See also llvm/ADT/ilist.h, where the
23/// same change must be made.
24///
25#define LLVM_COMPACTIFY_SENTINELS 1
26
27namespace llvm {
28
29template<typename NodeTy>
30struct ilist_traits;
31
32/// ilist_half_node - Base class that provides prev services for sentinels.
33///
34template<typename NodeTy>
35class ilist_half_node {
36  friend struct ilist_traits<NodeTy>;
37  NodeTy *Prev;
38protected:
39  NodeTy *getPrev() { return Prev; }
40  const NodeTy *getPrev() const { return Prev; }
41  void setPrev(NodeTy *P) { Prev = P; }
42  ilist_half_node() : Prev(0) {}
43};
44
45template<typename NodeTy>
46struct ilist_nextprev_traits;
47
48/// ilist_node - Base class that provides next/prev services for nodes
49/// that use ilist_nextprev_traits or ilist_default_traits.
50///
51template<typename NodeTy>
52class ilist_node : ilist_half_node<NodeTy> {
53  friend struct ilist_nextprev_traits<NodeTy>;
54  friend struct ilist_traits<NodeTy>;
55  NodeTy *Next;
56  NodeTy *getNext() { return Next; }
57  const NodeTy *getNext() const { return Next; }
58  void setNext(NodeTy *N) { Next = N; }
59protected:
60  ilist_node() : Next(0) {}
61};
62
63/// When assertions are off, the Next field of sentinels
64/// will not be accessed. So it is not necessary to allocate
65/// space for it. The following macro selects the most
66/// efficient traits class. The LLVM_COMPACTIFY_SENTINELS
67/// preprocessor symbol controls this.
68///
69#if defined(LLVM_COMPACTIFY_SENTINELS) && LLVM_COMPACTIFY_SENTINELS
70#   define ILIST_NODE ilist_half_node
71#else
72#   define ILIST_NODE ilist_node
73#endif
74
75} // End llvm namespace
76
77#endif
78