// EdIRDbg.cpp : implementation file
//

#include "stdafx.h"

#include "Defines.hpp"

#ifdef D_ED_IR_ACTIVE

#include "EdIRBkLs.hpp"

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

/////////////////////////////////////////////////////////////////////////////
// class CPA_EdIR_BreakPointList
/////////////////////////////////////////////////////////////////////////////

/****************************************************************************/
CPA_EdIR_BreakPointList::CPA_EdIR_BreakPointList()
{
}

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

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

	RemoveAll();
}

/****************************************************************************/
POSITION CPA_EdIR_BreakPointList::m_fn_posGetPositionBreakPoint(long lIndex,CString csBehaviourName)
{
	POSITION	pos=GetHeadPosition();
	BOOL			bFound=FALSE;
	while(pos!=NULL && !bFound)
	{
		CPA_EdIR_BreakPoint	*pclBreakPoint=GetAt(pos);

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

	return pos;
}

/****************************************************************************/
BOOL CPA_EdIR_BreakPointList::m_fn_bIsInList(long lIndex,CString csBehaviourName)
{
	return (m_fn_posGetPositionBreakPoint(lIndex,csBehaviourName)!=NULL);
}

/****************************************************************************/
void CPA_EdIR_BreakPointList::m_fn_vSetOneBreakPoint(long lIndex,CString csBehaviourName)
{
	AddTail(new CPA_EdIR_BreakPoint(lIndex,csBehaviourName));
}

/****************************************************************************/
void CPA_EdIR_BreakPointList::m_fn_vRemoveOneBreakPoint(long lIndex,CString csBehaviourName)
{
	POSITION	pos=m_fn_posGetPositionBreakPoint(lIndex,csBehaviourName);

	if(pos!=NULL)
	{
		CPA_EdIR_BreakPoint *pclBreakPoint=GetAt(pos);

		RemoveAt(pos);

		delete pclBreakPoint;
	}
}

/****************************************************************************/
BOOL CPA_EdIR_BreakPointList::m_fn_bExistMoreThanOnce(CPA_EdIR_BreakPoint *pclBreakPoint)
{
	POSITION	pos=GetHeadPosition();
	BOOL			bFound=FALSE;
	while(pos!=NULL && !bFound)
	{
		CPA_EdIR_BreakPoint *pclCurrentBreakPoint=GetNext(pos);

		if((pclCurrentBreakPoint!=pclBreakPoint) &&
			 (pclCurrentBreakPoint->m_fn_lGetIndex()==pclBreakPoint->m_fn_lGetIndex()) &&
			 (pclCurrentBreakPoint->m_fn_csGetBehaviourName()==pclBreakPoint->m_fn_csGetBehaviourName()))
			{
				bFound=TRUE;
			}
	}

	return bFound;
}

#endif //D_ED_IR_ACTIVE