|
Revision 13, 1.3 KB
(checked in by Douglas Thrift, 5 years ago)
|
|
Take that David!
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | // Null Node |
|---|
| 2 | // |
|---|
| 3 | // Douglas Thrift |
|---|
| 4 | // |
|---|
| 5 | // $Id$ |
|---|
| 6 | |
|---|
| 7 | #ifndef _NullNode_hpp_ |
|---|
| 8 | #define _NullNode_hpp_ |
|---|
| 9 | |
|---|
| 10 | #include "Node.hpp" |
|---|
| 11 | |
|---|
| 12 | template<typename Type> |
|---|
| 13 | class NullNode : public Node<Type> |
|---|
| 14 | { |
|---|
| 15 | public: |
|---|
| 16 | 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 | }; |
|---|
| 22 | |
|---|
| 23 | template<typename Type> |
|---|
| 24 | bool NullNode<Type>::contains(const Type& value, Node<Type>* end, bool forward) |
|---|
| 25 | { |
|---|
| 26 | Node<Type>* another = forward ? Node<Type>::next : Node<Type>::previous; |
|---|
| 27 | |
|---|
| 28 | if (end == this) return false; else return another->contains(value, end, forward); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | template<typename Type> |
|---|
| 32 | void NullNode<Type>::remove(const Type& value, Node<Type>* end, bool forward) |
|---|
| 33 | { |
|---|
| 34 | Node<Type>* another = forward ? Node<Type>::next : Node<Type>::previous; |
|---|
| 35 | |
|---|
| 36 | if (end != this) another->remove(value, end, forward); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | template<typename Type> |
|---|
| 40 | void NullNode<Type>::accept(Visitor<Type>* visitor, Node<Type>* end, bool forward) |
|---|
| 41 | { |
|---|
| 42 | Node<Type>* another = forward ? Node<Type>::next : Node<Type>::previous; |
|---|
| 43 | |
|---|
| 44 | if (end != this) another->accept(visitor, end, forward); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | #endif // _NullNode_hpp_ |
|---|