gusucode.com > 通用协议编解码模块C#源码程序 > 通用协议编解码模块/codec_src/Codec_src/BasicObject/BaseCollection.cpp

    // BaseCollection.cpp: implementation of the CBaseCollection class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include <afxtempl.h>

#include <BasicObject/BasicObjects.h>
#include "BaseCollection.h"

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


DEFINE_EXPORT_OBJECT_INDICATOR(BaseCollection)
IMPLEMENT_OBJECT(CBaseCollection)

BOOL CBaseCollection::ConvertInterface(IBase* pBase, void** ppIntf, INN nInN) const
{

	BOOL bResult = FALSE;
	if (pBase)
	{
		bResult = TRUE;
		if (ppIntf)
		{
			if (nInN == IN_IBase)
				*ppIntf = pBase;
			else
				bResult = pBase->GetInterface(nInN, ppIntf);
		}
	}

	return bResult;
}

LONG CBaseCollection::GetCount() const
{
	return m_List.GetCount();
}

COLPOS CBaseCollection::GetPosAt(LONG nIndex) const
{
	return (COLPOS)m_List.FindIndex(nIndex);
}

COLPOS CBaseCollection::GetHeadPos() const
{
	return (COLPOS)m_List.GetHeadPosition();
}

COLPOS CBaseCollection::GetTailPos() const
{
	return (COLPOS)m_List.GetTailPosition();
}

BOOL CBaseCollection::GetNext(COLPOS &nPos, void** ppIntf, INN nInN/*=IN_IBase*/) const
{
	IBase *pBase = m_List.GetNext((POSITION&)nPos);
	return ConvertInterface(pBase, ppIntf, nInN);
}

BOOL CBaseCollection::GetPrev(COLPOS &nPos, void** ppIntf, INN nInN/*=IN_IBase*/) const
{
	IBase *pBase = m_List.GetPrev((POSITION&)nPos);
	return ConvertInterface(pBase, ppIntf, nInN);
}

BOOL CBaseCollection::GetAtPos(COLPOS nPos, void** ppIntf, INN nInN/*=IN_IBase*/) const
{
	IBase *pBase = m_List.GetAt((POSITION)nPos);
	return ConvertInterface(pBase, ppIntf, nInN);
}

BOOL CBaseCollection::SetAtPos(COLPOS nPos, IBase *pIntf)
{
	m_List.SetAt((POSITION)nPos, pIntf);
	return TRUE;
}

BOOL CBaseCollection::InsertBeforePos(COLPOS &nPos, IBase *pIntf)
{
	if (m_List.IsEmpty())
	{
		m_List.AddHead(pIntf);
		nPos = (COLPOS)m_List.GetHeadPosition();
	}
	else
	{
		nPos = (COLPOS)m_List.InsertBefore((POSITION)nPos, pIntf);
	}
	return (nPos != NULL);
}

BOOL CBaseCollection::InsertAfterPos(COLPOS &nPos, IBase *pIntf)
{
	if (m_List.IsEmpty())
	{
		m_List.AddTail(pIntf);
		nPos = (COLPOS)m_List.GetTailPosition();
	}
	else
	{
		nPos = (COLPOS)m_List.InsertAfter((POSITION)nPos, pIntf);
	}
	return (nPos != NULL);
}

BOOL CBaseCollection::RemoveAtPos(COLPOS nPos)
{
	m_List.RemoveAt((POSITION)nPos);
	return TRUE;
}