GenericListNode.cpp
From Giona
(Difference between revisions)
(5 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
- | /* | + | /**************************************************************************** |
- | + | *Generic List Node for a Linked List. | |
- | + | * -------------------------------------------------------------------------- | |
- | + | *Author: Rosario Marino | |
- | * Generic List Node for a Linked List | + | ***************************************************************************/ |
- | */ | + | |
- | |||
- | |||
#include "GenericListNode.h" | #include "GenericListNode.h" | ||
Line 16: | Line 13: | ||
GenericListNode::GenericListNode() | GenericListNode::GenericListNode() | ||
{ | { | ||
+ | Debug::debug("GenericListNode::GenericListNode()"); | ||
this->next = NULL; | this->next = NULL; | ||
this->elem = NULL; | this->elem = NULL; | ||
+ | this->notAnObject=false; | ||
} | } | ||
Line 25: | Line 24: | ||
GenericListNode::~GenericListNode() | GenericListNode::~GenericListNode() | ||
{ | { | ||
- | if(this-> | + | Debug::debug("GenericListNode::~GenericListNode()"); |
- | + | if(this->elem) | |
- | if( | + | if(!notAnObject) |
- | + | { | |
+ | Debug::debug("GenericListNode::~GenericListNode() is deleting node element"); | ||
+ | delete(this->elem); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | * This method must be called if the element of the node | ||
+ | * is not an object created by a new() statement (so that | ||
+ | * the delete statement will ignore it) | ||
+ | */ | ||
+ | void GenericListNode::setNotAnObject() | ||
+ | { | ||
+ | Debug::debug("void GenericListNode::setNotAnObject()"); | ||
+ | this->notAnObject=true; | ||
} | } | ||
Line 36: | Line 49: | ||
void GenericListNode::setElem(genericListElemT elem) | void GenericListNode::setElem(genericListElemT elem) | ||
{ | { | ||
+ | Debug::debug("void GenericListNode::setElem(genericListElemT elem)"); | ||
this->elem = elem; | this->elem = elem; | ||
} | } | ||
Line 44: | Line 58: | ||
genericListElemT GenericListNode::getElem() | genericListElemT GenericListNode::getElem() | ||
{ | { | ||
+ | Debug::debug("genericListElemT GenericListNode::getElem()"); | ||
return this->elem; | return this->elem; | ||
} | } | ||
Line 52: | Line 67: | ||
void GenericListNode::setNext(GenericListNode *next) | void GenericListNode::setNext(GenericListNode *next) | ||
{ | { | ||
+ | Debug::debug("void GenericListNode::setNext(GenericListNode *next)"); | ||
this->next = next; | this->next = next; | ||
} | } | ||
Line 60: | Line 76: | ||
GenericListNode* GenericListNode::getNext() | GenericListNode* GenericListNode::getNext() | ||
{ | { | ||
+ | Debug::debug("GenericListNode* GenericListNode::getNext()"); | ||
return this->next; | return this->next; | ||
} | } | ||
+ | |||
</pre> | </pre> | ||
+ | |||
+ | [[Il database Object Oriented Generico|BACK]] | ||
[[Category:Codice Sorgente]] | [[Category:Codice Sorgente]] |
Current revision as of 17:37, 17 December 2007
/**************************************************************************** *Generic List Node for a Linked List. * -------------------------------------------------------------------------- *Author: Rosario Marino ***************************************************************************/ #include "GenericListNode.h" /* * Constructor */ GenericListNode::GenericListNode() { Debug::debug("GenericListNode::GenericListNode()"); this->next = NULL; this->elem = NULL; this->notAnObject=false; } /* * Destructor */ GenericListNode::~GenericListNode() { Debug::debug("GenericListNode::~GenericListNode()"); if(this->elem) if(!notAnObject) { Debug::debug("GenericListNode::~GenericListNode() is deleting node element"); delete(this->elem); } } /* * This method must be called if the element of the node * is not an object created by a new() statement (so that * the delete statement will ignore it) */ void GenericListNode::setNotAnObject() { Debug::debug("void GenericListNode::setNotAnObject()"); this->notAnObject=true; } /* * Sets the element of the node */ void GenericListNode::setElem(genericListElemT elem) { Debug::debug("void GenericListNode::setElem(genericListElemT elem)"); this->elem = elem; } /* * Returns the element of the node */ genericListElemT GenericListNode::getElem() { Debug::debug("genericListElemT GenericListNode::getElem()"); return this->elem; } /* * Sets next node in the list */ void GenericListNode::setNext(GenericListNode *next) { Debug::debug("void GenericListNode::setNext(GenericListNode *next)"); this->next = next; } /* * Returns next node in the list */ GenericListNode* GenericListNode::getNext() { Debug::debug("GenericListNode* GenericListNode::getNext()"); return this->next; }