b4f2770eb8
Migliorie varie nei costruttori.
160 lines
4.4 KiB
C++
160 lines
4.4 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2013
|
|
//----------------------------------------------------------------------------
|
|
// File : GdbNode.cpp Data : 28.11.13 Versione : 1.4a2
|
|
// Contenuto : Implementazione della classe GdbNode.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 28.11.13 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "GdbNode.h"
|
|
#include "GdbGroup.h"
|
|
|
|
//----------------------------------------------------------------------------
|
|
GdbNode::GdbNode( void)
|
|
: m_nId( GDB_ID_NULL), m_pNext( nullptr), m_pPrev( nullptr), m_pParent( nullptr)
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
GdbNode::GetParentId( void) const
|
|
{
|
|
if ( m_pParent != nullptr)
|
|
return m_pParent->m_nId ;
|
|
else
|
|
return 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbNode::AddTail( GdbGroup* pParent)
|
|
{
|
|
// se il padre non è definito, errore
|
|
if ( pParent == nullptr)
|
|
return false ;
|
|
|
|
// se non ci sono figli
|
|
if ( pParent->m_pLastNode == nullptr) {
|
|
pParent->m_pLastNode = this ;
|
|
pParent->m_pFirstNode = this ;
|
|
m_pParent = pParent ;
|
|
m_pNext = nullptr ;
|
|
m_pPrev = nullptr ;
|
|
m_pParent->NodeCountInc() ;
|
|
return true ;
|
|
}
|
|
|
|
// caso standard
|
|
return InsertAfter( pParent->m_pLastNode) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbNode::AddHead( GdbGroup* pParent)
|
|
{
|
|
// se il padre non è definito, errore
|
|
if ( pParent == nullptr)
|
|
return false ;
|
|
|
|
// se non ci sono figli
|
|
if ( pParent->m_pFirstNode == nullptr) {
|
|
pParent->m_pFirstNode = this ;
|
|
pParent->m_pLastNode = this ;
|
|
m_pParent = pParent ;
|
|
m_pNext = nullptr ;
|
|
m_pPrev = nullptr ;
|
|
m_pParent->NodeCountInc() ;
|
|
return true ;
|
|
}
|
|
|
|
// caso standard
|
|
return InsertBefore( pParent->m_pFirstNode) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbNode::InsertAfter( GdbNode* pRef)
|
|
{
|
|
// se riferimento non definito, errore
|
|
if ( pRef == nullptr)
|
|
return false ;
|
|
|
|
// sistemazione puntatori di elemento inserito
|
|
m_pNext = pRef->m_pNext ;
|
|
m_pPrev = pRef ;
|
|
m_pParent = pRef->m_pParent ;
|
|
// sistemazione puntatori di elemento di riferimento
|
|
pRef->m_pNext = this ;
|
|
// sistemazione puntatori di eventuale elemento successivo
|
|
if ( m_pNext != nullptr)
|
|
m_pNext->m_pPrev = this ;
|
|
// sistemazione dell'eventuale padre
|
|
if ( m_pParent != nullptr) {
|
|
// se nuovo ultimo nodo
|
|
if ( m_pParent->m_pLastNode == pRef)
|
|
m_pParent->m_pLastNode = this ;
|
|
m_pParent->NodeCountInc() ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GdbNode::InsertBefore( GdbNode* pRef)
|
|
{
|
|
// se riferimento non definito, errore
|
|
if ( pRef == nullptr)
|
|
return false ;
|
|
|
|
// sistemazione puntatori di elemento inserito
|
|
m_pNext = pRef ;
|
|
m_pPrev = pRef->m_pPrev ;
|
|
m_pParent = pRef->m_pParent ;
|
|
// sistemazione puntatori di elemento corrente
|
|
pRef->m_pPrev = this ;
|
|
// sistemazione puntatori di eventuale elemento precedente
|
|
if ( m_pPrev != nullptr)
|
|
m_pPrev->m_pNext = this ;
|
|
// sistemazione dell'eventuale padre
|
|
if ( m_pParent != nullptr) {
|
|
// se nuovo primo nodo
|
|
if ( m_pParent->m_pFirstNode == pRef)
|
|
m_pParent->m_pFirstNode = this ;
|
|
m_pParent->NodeCountInc() ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
bool
|
|
GdbNode::Remove( void)
|
|
{
|
|
// sistemazione dell'eventuale padre
|
|
if ( m_pParent != nullptr) {
|
|
if ( m_pParent->m_pFirstNode == this)
|
|
m_pParent->m_pFirstNode = m_pNext ;
|
|
if ( m_pParent->m_pLastNode == this)
|
|
m_pParent->m_pLastNode = m_pPrev ;
|
|
m_pParent->NodeCountDec() ;
|
|
}
|
|
// sistemazione di eventuale precedente
|
|
if ( m_pPrev != nullptr)
|
|
m_pPrev->m_pNext = m_pNext ;
|
|
// sistemazione di eventuale successivo
|
|
if ( m_pNext != nullptr)
|
|
m_pNext->m_pPrev = m_pPrev ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
|