ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/ccscs20/NullNode.hpp
Revision: 5
Committed: 2004-05-13T22:47:11-07:00 (21 years, 1 month ago) by Douglas Thrift
File size: 2058 byte(s)
Log Message:
Die!

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     NullNode(const Type& value) : value(value), next(NULL), previous(NULL),
21     null(false) {}
22 Douglas Thrift 1 ~NullNode() {}
23 Douglas Thrift 5 void setValue(const Type& value) { this->value = value; }
24     const Type& getValue(void) const { return value; }
25     void addNext(const Type& value);
26     void addPrevious(const Type& value);
27     void removeNext(void);
28     void removePrevious(void);
29     void setNext(NullNode<Type>* next) { this->next = next; }
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 Douglas Thrift 4 bool contains(const Type& value, NullNode<Type>* end);
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 4 bool NullNode<Type>::contains(const Type& value, NullNode<Type>* end)
82 Douglas Thrift 3 {
83 Douglas Thrift 5 NullNode<Type>* another = next != NULL ? 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 1 #endif // _NullNode_hpp_

Properties

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