Files
Client/GameTools/CaldronBase/BaseObj.cpp
LGram16 dd97ddec92 Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code:
- Client: Game client source (moved to Client/Client/)
- Server: Game server source
- GameTools: Development tools
- CryptoSource: Encryption utilities
- database: Database scripts
- Script: Game scripts
- rylCoder_16.02.2008_src: Legacy coder tools
- GMFont, Game: Additional resources

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 20:17:20 +09:00

235 lines
3.4 KiB
C++

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