/* ********************************************************************* * CBaseObj * ÆÄÀÏ : BaseObj.cpp * ±â´É : Base Object Ŭ·¡½º ±¸Çö * history : 2003.10.31 (yundi) ÀÛ¼º ********************************************************************** */ #include "BaseObj.h" namespace Caldron{ namespace Base{ int CBaseObj::ms_nTotalObjectCount = 0; CBaseObj::CBaseObj( CBaseObj* pParentObj ) { SetParent( NULL ); SetPrevSibling( NULL ); SetNextSibling( NULL ); SetFirstChild( NULL ); EstablishLinkageToParent( pParentObj ); ++ms_nTotalObjectCount; } CBaseObj::~CBaseObj() { // ÀÏ´Ü Àç±ÍÀûÀ¸·Î ±¸ÇöÇßÀ¸³ª ºñÀç±ÍÀûÀ¸·Î ¼öÁ¤ÇؾßÇÒµí. if( NULL != GetFirstChild() ) { CBaseObj* pObj = GetFirstChild()->GetLastSibling(); while( pObj ) { CBaseObj* pDeleteObj = pObj; pObj = pObj->GetPrevSibling(); SafeDelete( pDeleteObj ); } } Unlink(); --ms_nTotalObjectCount; } CBaseObj* CBaseObj::GetParent() { return m_rpParent; } CBaseObj* CBaseObj::GetFirstChild() { return m_rpFirstChild; } CBaseObj* CBaseObj::GetPrevSibling() { return m_rpPrevSibling; } CBaseObj* CBaseObj::GetNextSibling() { return m_rpNextSibling; } bool CBaseObj::LinkToParent( CBaseObj* pParentObj ) { if( pParentObj == GetParent() ) { return true; } CBaseObj* pObj = pParentObj; while( NULL != pObj ) { if( pObj == this ) { // ÀÚ½ÅÀÇ ÀÚ½Ä Áß Çϳª¸¦ ºÎ¸ð·Î linkÇÏ·Á°í ½ÃµµÇÑ °æ¿ì return false; } pObj = pObj->GetParent(); } if( !IsRoot() ) { Unlink(); } EstablishLinkageToParent( pParentObj ); return true; } CBaseObj* CBaseObj::GetLastSibling() { // ÀÏ´Ü ¾ÈÁ¤¼º Ãø¸é¿¡¼­ NULL Æ÷ÀÎÅÍ Ã³¸®¸¦ ÇØ Áá´Âµ¥ ÀÌ°É °è¼Ó ¿©±â¿¡ µÎ´Â°Ô ¹Ù¶÷Á÷ÇÑÁö´Â ¸ð¸£°Ú´Ù. if( NULL == this ) { return NULL; } CBaseObj* pObj = this; while( NULL != pObj->GetNextSibling() ) { pObj = pObj->GetNextSibling(); } return pObj; } void CBaseObj::AddSiblingObj( CBaseObj* pObj ) { CBaseObj* pLastSibling = GetLastSibling(); // establish mutual linkage pLastSibling->SetNextSibling( pObj ); pObj->SetPrevSibling( pLastSibling ); } void CBaseObj::Unlink() { // ºÎ¸ð¿Í siblingÀ¸·ÎÀÇ ¸µÅ©·ÎºÎÅÍ ºÐ¸®ÇØ ½º½º·Î°¡ root °¡ µÊ if( IsRoot() ) { return; } if( GetParent()->GetFirstChild() == this ) { GetParent()->SetFirstChild( GetNextSibling() ); } if( GetPrevSibling() != NULL ) { GetPrevSibling()->SetNextSibling( GetNextSibling() ); } if( GetNextSibling() != NULL ) { GetNextSibling()->SetPrevSibling( GetPrevSibling() ); } SetParent( NULL ); SetPrevSibling( NULL ); SetNextSibling( NULL ); } void CBaseObj::EstablishLinkageToParent( CBaseObj* pParent ) { // thisÀÇ parent¿Í siblingÀ¸·ÎÀÇ ¸µÅ©°¡ ¹«È¿ÇÑ »óÅ¿¡¼­ parentÀÇ child·Î¼­ // À¯È¿Çϵµ·Ï parent¿Í siblingÀ¸·ÎÀÇ ¸µÅ©¸¦ ¼³Á¤ if( NULL == pParent ) { return; } SetParent( pParent ); CBaseObj* pParentFirstChild = pParent->GetFirstChild(); if( NULL == pParentFirstChild ) { pParent->SetFirstChild( this ); } else { pParentFirstChild->AddSiblingObj( this ); } } bool CBaseObj::IsRoot() { if( NULL == GetParent() && NULL == GetPrevSibling() && NULL == GetNextSibling() ) { return true; } return false; } bool CBaseObj::IsLeaf() { if( NULL == GetFirstChild() ) { return true; } return false; } bool CBaseObj::IsFirst() { if( NULL == GetPrevSibling() ) { return true; } return false; } bool CBaseObj::IsLast() { if( NULL == GetNextSibling() ) { return true; } return false; } }}