// Null Node // // Douglas Thrift // // $Id$ #ifndef _NullNode_hpp_ #define _NullNode_hpp_ template class NullNode { private: Type value; NullNode* next; NullNode* previous; bool null; public: NullNode() : next(NULL), previous(NULL), null(true) {} NullNode(const Type& value) : value(value), next(NULL), previous(NULL), null(false) {} ~NullNode() {} void setValue(const Type& value) { this->value = value; } const Type& getValue(void) const { return value; } void addNext(const Type& value); void addPrevious(const Type& value); void removeNext(void); void removePrevious(void); void setNext(NullNode* next) { this->next = next; } void setPrevious(NullNode* previous) { this->previous = previous; } NullNode* getNext(void) const { return next; } NullNode* getPrevious(void) const { return next; } bool contains(const Type& value, NullNode* end); }; template void NullNode::addNext(const Type& value) { NullNode* behind = next; next = new NullNode(value); next->previous = this; next->next = behind; behind->previous = next; } template void NullNode::addPrevious(const Type& value) { NullNode* ahead = previous; previous = new NullNode(value); previous->next = this; previous->previous = ahead; ahead->next = previous; } template void NullNode::removeNext(void) { NullNode* behind = next->next; delete next; next = behind; next->previous = this; } template void NullNode::removePrevious(void) { NullNode* ahead = previous->previous; delete previous; previous = ahead; previous->next = this; } template bool NullNode::contains(const Type& value, NullNode* end) { NullNode* another = next != NULL ? next : previous; if (null && end == this) { return false; } else if (!null && value == this->value) { return true; } else return another->contains(value, end); } #endif // _NullNode_hpp_