GenericListNode.cpp

From Giona

(Difference between revisions)
 
(2 intermediate revisions not shown)
Line 1: Line 1:
<pre>
<pre>
-
 
/****************************************************************************
/****************************************************************************
  *Generic List Node for a Linked List.
  *Generic List Node for a Linked List.
 +
* --------------------------------------------------------------------------
  *Author: Rosario Marino
  *Author: Rosario Marino
  ***************************************************************************/
  ***************************************************************************/
Line 13: 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 22: Line 24:
GenericListNode::~GenericListNode()
GenericListNode::~GenericListNode()
{
{
 +
Debug::debug("GenericListNode::~GenericListNode()");
     if(this->elem)
     if(this->elem)
-
        delete(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;
}
}
Line 31: 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 39: Line 58:
genericListElemT GenericListNode::getElem()
genericListElemT GenericListNode::getElem()
{
{
 +
Debug::debug("genericListElemT GenericListNode::getElem()");
return this->elem;
return this->elem;
}
}
Line 47: 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 55: Line 76:
GenericListNode* GenericListNode::getNext()
GenericListNode* GenericListNode::getNext()
{
{
 +
Debug::debug("GenericListNode* GenericListNode::getNext()");
return this->next;
return this->next;
}
}
 +
</pre>
</pre>

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;
}


BACK

Personal tools