ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/ccscs20/NullNode.hpp
Revision: 6
Committed: 2004-05-13T23:17:43-07:00 (21 years, 1 month ago) by Douglas Thrift
File size: 2502 byte(s)
Log Message:
Remove!

File Contents

# User Rev Content
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 4 template<typename Type>
11 Douglas Thrift 5 class NullNode
12 Douglas Thrift 1 {
13     private:
14 Douglas Thrift 5 Type value;
15     NullNode<Type>* next;
16     NullNode<Type>* previous;
17 Douglas Thrift 1 bool null;
18     public:
19 Douglas Thrift 5 NullNode() : next(NULL), previous(NULL), null(true) {}
20 Douglas Thrift 6 NullNode(const Type& value) : value(value), next(NULL), previous(NULL), null(false) {}
21 Douglas Thrift 1 ~NullNode() {}
22 Douglas Thrift 5 void setValue(const Type& value) { this->value = value; }
23     const Type& getValue(void) const { return value; }
24     void addNext(const Type& value);
25     void addPrevious(const Type& value);
26     void removeNext(void);
27     void removePrevious(void);
28     void setNext(NullNode<Type>* next) { this->next = next; }
29     void setPrevious(NullNode<Type>* previous) { this->previous = previous; }
30     NullNode<Type>* getNext(void) const { return next; }
31     NullNode<Type>* getPrevious(void) const { return next; }
32 Douglas Thrift 6 bool contains(const Type& value, NullNode<Type>* end, bool forward = true);
33     void remove(const Type& value, NullNode<Type>* end, bool forward = true);
34 Douglas Thrift 1 };
35    
36 Douglas Thrift 3 template<typename Type>
37 Douglas Thrift 5 void NullNode<Type>::addNext(const Type& value)
38     {
39     NullNode<Type>* behind = next;
40    
41     next = new NullNode<Type>(value);
42     next->previous = this;
43     next->next = behind;
44     behind->previous = next;
45     }
46    
47     template<typename Type>
48     void NullNode<Type>::addPrevious(const Type& value)
49     {
50     NullNode<Type>* ahead = previous;
51    
52     previous = new NullNode<Type>(value);
53     previous->next = this;
54     previous->previous = ahead;
55     ahead->next = previous;
56     }
57    
58     template<typename Type>
59     void NullNode<Type>::removeNext(void)
60     {
61     NullNode<Type>* behind = next->next;
62    
63     delete next;
64    
65     next = behind;
66     next->previous = this;
67     }
68    
69     template<typename Type>
70     void NullNode<Type>::removePrevious(void)
71     {
72     NullNode<Type>* ahead = previous->previous;
73    
74     delete previous;
75    
76     previous = ahead;
77     previous->next = this;
78     }
79    
80     template<typename Type>
81 Douglas Thrift 6 bool NullNode<Type>::contains(const Type& value, NullNode<Type>* end, bool forward)
82 Douglas Thrift 3 {
83 Douglas Thrift 6 NullNode<Type>* another = forward ? next : previous;
84 Douglas Thrift 3
85 Douglas Thrift 4 if (null && end == this)
86     {
87     return false;
88     }
89 Douglas Thrift 5 else if (!null && value == this->value)
90 Douglas Thrift 4 {
91     return true;
92     }
93     else return another->contains(value, end);
94 Douglas Thrift 3 }
95    
96 Douglas Thrift 6 template<typename Type>
97     void NullNode<Type>::remove(const Type& value, NullNode<Type>* end, bool forward)
98     {
99     NullNode<Type>* another = forward ? next : previous;
100    
101     if (!null && value == this->value)
102     {
103     next->previous = previous;
104     previous->next = next;
105    
106     delete this;
107     }
108     else if (end != this) another->remove(value, end, forward);
109     }
110    
111 Douglas Thrift 1 #endif // _NullNode_hpp_

Properties

Name Value
svn:eol-style native
svn:keywords Id