ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/ccscs20/NullNode.hpp
(Generate patch)

Comparing NullNode.hpp (file contents):
Revision 5 by Douglas Thrift, 2004-05-13T22:47:11-07:00 vs.
Revision 10 by Douglas Thrift, 2004-05-14T13:57:49-07:00

# Line 7 | Line 7
7   #ifndef _NullNode_hpp_
8   #define _NullNode_hpp_
9  
10 + #include "Visitor.hpp"
11 +
12   template<typename Type>
13   class NullNode
14   {
# Line 16 | Line 18 | private:
18          NullNode<Type>* previous;
19          bool null;
20   public:
21 <        NullNode() : next(NULL), previous(NULL), null(true) {}
22 <        NullNode(const Type& value) : value(value), next(NULL), previous(NULL),
21 <                null(false) {}
22 <        ~NullNode() {}
21 >        NullNode() : null(true) {}
22 >        NullNode(const Type& value) : value(value), null(false) {}
23          void setValue(const Type& value) { this->value = value; }
24          const Type& getValue(void) const { return value; }
25          void addNext(const Type& value);
# Line 30 | Line 30 | public:
30          void setPrevious(NullNode<Type>* previous) { this->previous = previous; }
31          NullNode<Type>* getNext(void) const { return next; }
32          NullNode<Type>* getPrevious(void) const { return next; }
33 <        bool contains(const Type& value, NullNode<Type>* end);
33 >        bool contains(const Type& value, NullNode<Type>* end, bool forward = true);
34 >        void remove(const Type& value, NullNode<Type>* end, bool forward = true);
35 >        void accept(Visitor<Type>* visitor, NullNode<Type>* end, bool forward = true);
36   };
37  
38   template<typename Type>
# Line 78 | Line 80 | void NullNode<Type>::removePrevious(void
80   }
81  
82   template<typename Type>
83 < bool NullNode<Type>::contains(const Type& value, NullNode<Type>* end)
83 > bool NullNode<Type>::contains(const Type& value, NullNode<Type>* end, bool forward)
84   {
85 <        NullNode<Type>* another = next != NULL ? next : previous;
85 >        NullNode<Type>* another = forward ? next : previous;
86  
87          if (null && end == this)
88          {
# Line 93 | Line 95 | bool NullNode<Type>::contains(const Type
95          else return another->contains(value, end);
96   }
97  
98 + template<typename Type>
99 + void NullNode<Type>::remove(const Type& value, NullNode<Type>* end, bool forward)
100 + {
101 +        NullNode<Type>* another = forward ? next : previous;
102 +
103 +        if (!null && value == this->value)
104 +        {
105 +                next->previous = previous;
106 +                previous->next = next;
107 +                
108 +                delete this;
109 +        }
110 +        else if (end != this) another->remove(value, end, forward);
111 + }
112 +
113 + template<typename Type>
114 + void NullNode<Type>::accept(Visitor<Type>* visitor, NullNode<Type>* end, bool forward)
115 + {
116 +        NullNode<Type>* another = forward ? next : previous;
117 +
118 +        if (!null) visitor->visit(value);
119 +        
120 +        if (end != this) another->accept(visitor, end, forward);
121 + }
122 +
123   #endif // _NullNode_hpp_

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines