ae4a5905f83cd6f26d5e6fe9e5cfa56d5fe4d419
[oota-llvm.git] / include / llvm / ADT / ilist_node.h
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
27 namespace llvm {
28
29 template<typename NodeTy>
30 struct ilist_traits;
31
32 /// ilist_half_node - Base class that provides prev services for sentinels.
33 ///
34 template<typename NodeTy>
35 class ilist_half_node {
36   friend struct ilist_traits<NodeTy>;
37   NodeTy *Prev;
38 protected:
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
45 template<typename NodeTy>
46 struct 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 ///
51 template<typename NodeTy>
52 class 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; }
59 protected:
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