//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pError - 
//-----------------------------------------------------------------------------
static void FixEmptyEntity(MapError *pError)
{
	CMapClass *pKillMe = pError->pObjects[0];

	if (pKillMe->GetParent() != NULL)
	{
		GetHistory()->KeepForDestruction(pKillMe);
		pKillMe->GetParent()->RemoveChild(pKillMe);
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pDependent - 
//-----------------------------------------------------------------------------
void CMapClass::AddDependent(CMapClass *pDependent)
{
	//
	// Never add ourselves to our dependents. It creates a circular dependency
	// which is bad.
	//
	if (pDependent != this)
	{
		//
		// Also, never add one of our ancestors as a dependent. This too creates a
		// nasty circular dependency.
		//
		bool bIsOurAncestor = false;
		CMapClass *pTestParent = GetParent();
		while (pTestParent != NULL)
		{
			if (pTestParent == pDependent)
			{
				bIsOurAncestor = true;
				break;
			}

			pTestParent = pTestParent->GetParent();
		}

		if (!bIsOurAncestor)
		{
			m_Dependents.AddTail(pDependent);
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pDependent - 
//-----------------------------------------------------------------------------
void CMapClass::AddDependent(CMapClass *pDependent)
{
	//
	// Never add ourselves to our dependents. It creates a circular dependency
	// which is bad.
	//
	if (pDependent == this)
		return;

	//
	// Don't add the same dependent twice.
	//
	int nIndex = m_Dependents.Find(pDependent);
	if (nIndex != -1)
		return;

	//
	// Also, never add one of our ancestors as a dependent. This too creates a
	// nasty circular dependency.
	//
	bool bIsOurAncestor = false;
	CMapClass *pTestParent = GetParent();
	while (pTestParent != NULL)
	{
		if (pTestParent == pDependent)
		{
			bIsOurAncestor = true;
			break;
		}

		pTestParent = pTestParent->GetParent();
	}

	if (!bIsOurAncestor)
	{
		m_Dependents.AddToTail(pDependent);
		Assert(m_Dependents.Count() < 1000);
	}
}