// EdIRDbg.cpp : implementation file
//

#include "stdafx.h"

#include "Defines.hpp"

#ifdef D_ED_IR_ACTIVE

#include "EdIRDbLs.hpp"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// class CPA_EdIR_DebugInfoList
/////////////////////////////////////////////////////////////////////////////

/****************************************************************************/
CPA_EdIR_DebugInfoList::CPA_EdIR_DebugInfoList()
{
}

/****************************************************************************/
CPA_EdIR_DebugInfoList::~CPA_EdIR_DebugInfoList()
{
	m_fn_vDestroyAndRemoveAllEntries();
}

/****************************************************************************/
void CPA_EdIR_DebugInfoList::m_fn_vDestroyAndRemoveAllEntries()
{
	POSITION	pos=GetHeadPosition();
	while(pos!=NULL)
		delete GetNext(pos);

	RemoveAll();
}

/****************************************************************************/
CPA_EdIR_DebugInfo *CPA_EdIR_DebugInfoList::m_fn_pclGetDebugInfo(struct tdstNodeInterpret_ *pstNode)
{
	POSITION	pos=GetHeadPosition();
	BOOL			bFound=FALSE;
	while(pos!=NULL && !bFound)
	{
		CPA_EdIR_DebugInfo	*pclDebugInfo=GetAt(pos);

		if(pclDebugInfo->m_fn_pstGetNode()==pstNode)
			bFound=TRUE;
		else
			GetNext(pos);
	}

	if(pos!=NULL)
		return GetAt(pos);
	else
		return NULL;
}

/****************************************************************************/
long CPA_EdIR_DebugInfoList::m_fn_lGetLineNumber(struct tdstNodeInterpret_ *pstNode)
{
	CPA_EdIR_DebugInfo *pclDebugInfo=m_fn_pclGetDebugInfo(pstNode);

	if(pclDebugInfo!=NULL)
		return pclDebugInfo->m_fn_lGetLineNumber();
	else
		return -1;
}

/****************************************************************************/
long CPA_EdIR_DebugInfoList::m_fn_lGetColumnNumber(struct tdstNodeInterpret_ *pstNode)
{
	CPA_EdIR_DebugInfo *pclDebugInfo=m_fn_pclGetDebugInfo(pstNode);

	if(pclDebugInfo!=NULL)
		return pclDebugInfo->m_fn_lGetColumnNumber();
	else
		return -1;
}

/****************************************************************************/
long CPA_EdIR_DebugInfoList::m_fn_lGetIndex(struct tdstNodeInterpret_ *pstNode)
{
	CPA_EdIR_DebugInfo *pclDebugInfo=m_fn_pclGetDebugInfo(pstNode);

	if(pclDebugInfo!=NULL)
		return pclDebugInfo->m_fn_lGetIndex();
	else
		return -1;
}

/****************************************************************************/
CString CPA_EdIR_DebugInfoList::m_fn_csGetBehaviourName(struct tdstNodeInterpret_ *pstNode)
{
	CPA_EdIR_DebugInfo *pclDebugInfo=m_fn_pclGetDebugInfo(pstNode);

	if(pclDebugInfo!=NULL)
		return pclDebugInfo->m_fn_csGetBehaviourName();
	else
		return "";
}

/****************************************************************************/
struct tdstNodeInterpret_ *CPA_EdIR_DebugInfoList::m_fn_pstGetNode(long lIndex,CString csBehaviourName)
{
	POSITION	pos=GetHeadPosition();
	BOOL			bFound=FALSE;
	while(pos!=NULL && !bFound)
	{
		CPA_EdIR_DebugInfo	*pclDebugInfo=GetAt(pos);

		if((pclDebugInfo->m_fn_csGetBehaviourName()==csBehaviourName) &&
			 (pclDebugInfo->m_fn_lGetIndex()>lIndex))
			bFound=TRUE;
		else
			GetNext(pos);
	}

	if(pos!=NULL)
		return GetAt(pos)->m_fn_pstGetNode();
	else
		return NULL;
}

//BEGIN ROMTEAM Cristi Petrescu 98-05-
/****************************************************************************/
BOOL CPA_EdIR_DebugInfoList::m_fn_bExecuted (long lIndex)
{
	POSITION pos = GetHeadPosition ();
	BOOL bExecuted = FALSE;

	while (pos)
	{
		CPA_EdIR_DebugInfo *pclDebugInfo = GetNext (pos);

		if (pclDebugInfo -> m_fn_lGetIndex () > lIndex)
		{
			break;
		}

		if (pclDebugInfo -> m_fn_lGetIndex () == lIndex)
		{
			bExecuted = TRUE;
			break;
		}
	}

	return bExecuted;
}
//END ROMTEAM Cristi Petrescu 98-05-

#endif //D_ED_IR_ACTIVE