resarray.h

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

H
134 行
字号
// ResArray.h
//

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

// Description:		Resource array which automatically resizes due to
//					its link-list nature.
//
//					A resource array object will always comprise of a
//					hidden dummy node. This node both simplifies node
//					generation/destruction and provides an end of array
//					indicator which will be used during iterations.
//

#pragma once

#include "IResource.h"
#include "ResListNode.h"
#include "ResArrayIt.h"
#include "ResArrayHandle.h"


namespace Resources
{


class ResourceArray
{
// Construction and destruction.
public:
	ResourceArray();
	virtual ~ResourceArray();

	void Destroy();
	void ReleaseUnusedResources();

// Resource handle.
	typedef ResArrayHandle ResHandle;

	static const ResHandle NullHandle;

// Iterations.
	typedef ResArrayIt iterator;

	inline iterator Begin()
	{
		return iterator(m_pBegin);
	}
	inline iterator End()
	{
		return iterator(m_pEnd);
	}
	inline iterator Last()
	{
		return iterator(m_pLast);
	}
	inline iterator At(size_t nIndex)
	{
		return Begin() + nIndex;
	}

	static const iterator NullIterator;

// Array manipulation.
	void Insert(iterator& itPos, LPRESOURCE pRes);
	void Append(LPRESOURCE pRes);

	ResHandle Aquire(ResHandle& handle);
	ResHandle AquireByIndex(size_t nIndex);

	inline ResHandle Aquire(DWORD dwUniqueResID)
	{
		return Aquire(Find(dwUniqueResID));
	}
	inline ResHandle Aquire(LPCSTR lpszFilePath)
	{
		return Aquire(Find(lpszFilePath));
	}

	inline ResHandle AquireNext(const ResHandle& prev, DWORD dwUniqueResID)
	{
		return Aquire(FindNext(iterator(prev.m_pItem), dwUniqueResID));
	}
	inline ResHandle AquireNext(const ResHandle& prev, LPCSTR lpszFilePath)
	{
		return Aquire(FindNext(iterator(prev.m_pItem), lpszFilePath));
	}

	void Release(iterator& itPos);
	void Release(size_t nIndex);
	void Release(LPRESOURCE pRes);

	iterator Find(LPRESOURCE pRes);
	iterator Find(DWORD dwUniqueResID);
	iterator Find(LPCSTR lpszFilePath);
	iterator FindNext(const iterator& prev, DWORD dwUniqueResID);
	iterator FindNext(const iterator& prev, LPCSTR lpszFilePath);

// Properties.
	inline size_t GetCount() const
	{
		return m_nSize;
	}
	inline bool IsAutoFreeUnused() const
	{
		return m_bAutoFree;
	}

	bool EnableAutoFreeUnused(bool bEnable = true);

// Link list nodes and helper functions.
protected:
	typedef ResListNode ListNode;
	typedef ListNode * LPLISTNODE;

	void CreateDummyNode();
	void QueryUpdate();
	void UpdateIndexes();

// Attributes.
private:
	LPLISTNODE m_pBegin, m_pEnd, m_pLast;
	size_t m_nSize;

	bool m_bAutoFree;
};

typedef ResourceArray * LPRESOURCEARRAY;


}; // namespace Resources

⌨️ 快捷键说明

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