Simpatico  v1.10
Node.h
1 #ifndef UTIL_NODE_H
2 #define UTIL_NODE_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 namespace Util
12 {
13 
14  template <typename Data> class List;
15 
21  template <typename Data>
22  class Node
23  {
24 
25  public:
26 
30  Node()
31  : prev_(0),
32  next_(0),
33  list_(0),
34  datum_()
35  {}
36 
40  Node(const Node<Data>& other)
41  : prev_(other.prev_),
42  next_(other.next_),
43  list_(other.list_),
44  datum_(other.datum_)
45  {}
46 
52  Node<Data>* next() const
53  { return next_; }
54 
60  Node<Data>* prev() const
61  { return prev_; }
62 
68  const Data& data() const
69  { return datum_; }
70 
76  Data& data()
77  { return datum_; }
78 
84  List<Data>& list() const
85  { return *list_; }
86 
93  { next_ = next; }
94 
101  { prev_ = prev; }
102 
109  { list_ = &list; }
110 
117  { list_ = list; }
118 
132  void attachNext(Node<Data>& other)
133  {
134  next_ = &other;
135  other.prev_ = this;
136  other.list_ = list_;
137  }
138 
152  void attachPrev(Node<Data>& other)
153  {
154  prev_ = &other;
155  other.next_ = this;
156  other.list_ = list_;
157  }
158 
165  void clear()
166  {
167  prev_ = 0;
168  next_ = 0;
169  list_ = 0;
170  }
171 
172  private:
173 
179  Node<Data>* prev_;
180 
186  Node<Data>* next_;
187 
193  List<Data>* list_;
194 
201  Data datum_;
202 
203  };
204 
205 }
206 #endif
Node< Data > * next() const
Get the next pointer.
Definition: Node.h:52
Data & data()
Get a reference to the associated Data object.
Definition: Node.h:76
void setPrev(Node< Data > *prev)
Set pointer to the previous Node.
Definition: Node.h:100
Node()
Default constructor.
Definition: Node.h:30
void attachNext(Node< Data > &other)
Set pointers connecting the other node after this node.
Definition: Node.h:132
List< Data > & list() const
Get a reference to the List.
Definition: Node.h:84
Node(const Node< Data > &other)
Copy constructor.
Definition: Node.h:40
Node< Data > * prev() const
Get the previous pointer.
Definition: Node.h:60
Utility classes for scientific computation.
Definition: accumulators.mod:1
void setList(List< Data > *list)
Set the list.
Definition: Node.h:116
void clear()
Nullify previous and next pointers, and nullify the list pointer.
Definition: Node.h:165
void attachPrev(Node< Data > &other)
Set pointers connecting the other node before this node.
Definition: Node.h:152
Linked list class template.
Definition: List.h:32
Linked List Node, class template.
Definition: Node.h:22
void setNext(Node< Data > *next)
Set pointer to the next Node.
Definition: Node.h:92
void setList(List< Data > &list)
Set the list.
Definition: Node.h:108
const Data & data() const
Get a const reference to the associated Data.
Definition: Node.h:68