1 |
Douglas Thrift |
1 |
// Null Node |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#ifndef _NullNode_hpp_ |
8 |
|
|
#define _NullNode_hpp_ |
9 |
|
|
|
10 |
Douglas Thrift |
13 |
#include "Node.hpp" |
11 |
Douglas Thrift |
10 |
|
12 |
Douglas Thrift |
4 |
template<typename Type> |
13 |
Douglas Thrift |
13 |
class NullNode : public Node<Type> |
14 |
Douglas Thrift |
1 |
{ |
15 |
|
|
public: |
16 |
Douglas Thrift |
13 |
void setNext(NullNode<Type>* next) { this->next = dynamic_cast<Node<Type>*>(next); } |
17 |
|
|
void setPrevious(NullNode<Type>* previous) { this->previous = dynamic_cast<Node<Type>*>(previous); } |
18 |
|
|
bool contains(const Type& value, Node<Type>* end, bool forward); |
19 |
|
|
void remove(const Type& value, Node<Type>* end, bool forward); |
20 |
|
|
void accept(Visitor<Type>* visitor, Node<Type>* end, bool forward); |
21 |
Douglas Thrift |
1 |
}; |
22 |
|
|
|
23 |
Douglas Thrift |
3 |
template<typename Type> |
24 |
Douglas Thrift |
13 |
bool NullNode<Type>::contains(const Type& value, Node<Type>* end, bool forward) |
25 |
Douglas Thrift |
5 |
{ |
26 |
Douglas Thrift |
13 |
Node<Type>* another = forward ? Node<Type>::next : Node<Type>::previous; |
27 |
Douglas Thrift |
5 |
|
28 |
Douglas Thrift |
13 |
if (end == this) return false; else return another->contains(value, end, forward); |
29 |
Douglas Thrift |
5 |
} |
30 |
|
|
|
31 |
|
|
template<typename Type> |
32 |
Douglas Thrift |
13 |
void NullNode<Type>::remove(const Type& value, Node<Type>* end, bool forward) |
33 |
Douglas Thrift |
5 |
{ |
34 |
Douglas Thrift |
13 |
Node<Type>* another = forward ? Node<Type>::next : Node<Type>::previous; |
35 |
Douglas Thrift |
5 |
|
36 |
Douglas Thrift |
13 |
if (end != this) another->remove(value, end, forward); |
37 |
Douglas Thrift |
5 |
} |
38 |
|
|
|
39 |
|
|
template<typename Type> |
40 |
Douglas Thrift |
13 |
void NullNode<Type>::accept(Visitor<Type>* visitor, Node<Type>* end, bool forward) |
41 |
Douglas Thrift |
5 |
{ |
42 |
Douglas Thrift |
13 |
Node<Type>* another = forward ? Node<Type>::next : Node<Type>::previous; |
43 |
Douglas Thrift |
5 |
|
44 |
Douglas Thrift |
10 |
if (end != this) another->accept(visitor, end, forward); |
45 |
|
|
} |
46 |
|
|
|
47 |
Douglas Thrift |
1 |
#endif // _NullNode_hpp_ |