resarrayit.cpp

来自「这个是我第一次完成的一个简单的3D ALIEN SHOOTING GAME的RE」· C++ 代码 · 共 130 行

CPP
130 行
字号
// ResArrayIt.cpp
//

// Author:			Lea Hayes
// Date Created:	10/03/2006
// Date Modified:	10/03/2006

#include "Common.h"
#include "ResArrayIt.h"

using namespace Resources;


// ResArrayIt - Construction and deconstruction

ResArrayIt::ResArrayIt(LPRESLISTNODE pItem)
: ResArrayHandle(pItem)
{
}

ResArrayIt::ResArrayIt(const ResArrayIt &it)
: ResArrayHandle(it.m_pItem)
{
}

ResArrayIt::~ResArrayIt()
{
}


// ResArrayIt - Properties.


// Function Name:	DistanceFrom
//
// Author:			Lea Hayes
// Date Created:	11/03/2006
// Date Modified:	11/03/2006
//
// Description:		Calculate distance between this iterator and the
//					iterator specified. When specified iterator occurs
//					before this iterator a negative value is returned.
//
size_t ResArrayIt::DistanceFrom(const ResArrayIt &it)
{
	// Simply return difference between iterator indexes.
	return (**this)->GetIndex() -
		(**const_cast<ResArrayIt*>(&it))->GetIndex();
}

// Function Name:	Increment
//
// Author:			Lea Hayes
// Date Created:	11/03/2006
// Date Modified:	11/03/2006
//
// Description:		Retrieve an iterator to the next resource(s).
//
void ResArrayIt::Increment(size_t nAmount /*=1*/)
{
	// Increment iterator as specified.
	for(size_t i = 0; i < nAmount; i++)
	{
		// Proceed to next item.
		m_pItem = m_pItem->m_pNext;
	}
}

// Function Name:	Decrement
//
// Author:			Lea Hayes
// Date Created:	11/03/2006
// Date Modified:	11/03/2006
//
// Description:		Retrieve an iterator to the previous resource(s).
//
void ResArrayIt::Decrement(size_t nAmount /*=1*/)
{
	// Increment iterator as specified.
	for(size_t i = 0; i < nAmount; i++)
	{
		// Proceed to previous item.
		m_pItem = m_pItem->m_pPrev;
	}
}


// ResArrayIt - Operator overloads.


// Function Name:	operator+
//
// Author:			Lea Hayes
// Date Created:	11/03/2006
// Date Modified:	11/03/2006
//
// Description:		Retrieve an iterator to the next resource.
//
ResArrayIt ResArrayIt::operator+ (size_t nAmount) const
{
	// Resulting iterator to return.
	ResArrayIt itResult = *this;

	// Increment resulting iterator.
	itResult.Increment(nAmount);

	// Finally return the resulting iterator.
	return itResult;
}

// Function Name:	operator-
//
// Author:			Lea Hayes
// Date Created:	11/03/2006
// Date Modified:	11/03/2006
//
// Description:		Retrieve an iterator to the previous resource.
//
ResArrayIt ResArrayIt::operator- (size_t nAmount) const
{
	// Resulting iterator to return.
	ResArrayIt itResult = *this;

	// Decrement resulting iterator.
	itResult.Decrement(nAmount);

	// Finally return the resulting iterator.
	return itResult;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?