// 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() : null(true) {} NullNode(const Type& value) : value(value), null(false) {} 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, bool forward = true); void remove(const Type& value, NullNode* end, bool forward = true); }; 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, bool forward) { NullNode* another = forward ? next : previous; if (null && end == this) { return false; } else if (!null && value == this->value) { return true; } else return another->contains(value, end); } template void NullNode::remove(const Type& value, NullNode* end, bool forward) { NullNode* another = forward ? next : previous; if (!null && value == this->value) { next->previous = previous; previous->next = next; delete this; } else if (end != this) another->remove(value, end, forward); } #endif // _NullNode_hpp_