PSCF v1.1
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
11namespace Util
12{
13
14 template <typename Data> class List;
15
21 template <typename Data>
22 class Node
23 {
24
25 public:
26
31 : prev_(0),
32 next_(0),
33 list_(0),
34 datum_()
35 {}
36
40 Node(Node<Data> const & other)
41 : prev_(other.prev_),
42 next_(other.next_),
43 list_(other.list_),
44 datum_(other.datum_)
45 {}
46
53 { return next_; }
54
61 { return prev_; }
62
68 Data const & data() const
69 { return datum_; }
70
76 Data& data()
77 { return datum_; }
78
85 { return *list_; }
86
93 { next_ = next; }
94
101 { prev_ = prev; }
102
109 { list_ = &list; }
110
117 { list_ = list; }
118
133 {
134 next_ = &other;
135 other.prev_ = this;
136 other.list_ = list_;
137 }
138
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
Linked list class template.
Definition: List.h:33
Linked List Node, class template.
Definition: Node.h:23
List< Data > & list() const
Get a reference to the List.
Definition: Node.h:84
Data const & data() const
Get a const reference to the associated Data.
Definition: Node.h:68
void setPrev(Node< Data > *prev)
Set pointer to the previous Node.
Definition: Node.h:100
void clear()
Nullify previous and next pointers, and nullify the list pointer.
Definition: Node.h:165
Node(Node< Data > const &other)
Copy constructor.
Definition: Node.h:40
Node()
Default constructor.
Definition: Node.h:30
Node< Data > * next() const
Get the next pointer.
Definition: Node.h:52
void setList(List< Data > *list)
Set the list.
Definition: Node.h:116
void attachPrev(Node< Data > &other)
Set pointers connecting the other node before this node.
Definition: Node.h:152
void setList(List< Data > &list)
Set the list.
Definition: Node.h:108
void attachNext(Node< Data > &other)
Set pointers connecting the other node after this node.
Definition: Node.h:132
void setNext(Node< Data > *next)
Set pointer to the next Node.
Definition: Node.h:92
Data & data()
Get a reference to the associated Data object.
Definition: Node.h:76
Node< Data > * prev() const
Get the previous pointer.
Definition: Node.h:60
Utility classes for scientific computation.
Definition: accumulators.mod:1