⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmrarray.h

📁 上传的是有关mfc的详细介绍
💻 H
字号:
// XMRArray.h: interface for the XMRArray class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_XMRARRAY_H__D7AEE90B_335B_4B46_ABD3_73B8B54ED4E7__INCLUDED_)
#define AFX_XMRARRAY_H__D7AEE90B_335B_4B46_ABD3_73B8B54ED4E7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <vector>

template<typename T>
class XMRArray :public std::vector<T> 
{
public:
	XMRArray() { }	

	int Add(const T& newElement)
	{
		push_back(newElement);
		return (int)this->size() - 1;
	}

	int GetSize() const
	{
		return (int)this->size();
	}

	T GetAt(int nIndex) const
	{
		return this->at(nIndex);
	}

	void RemoveAt(int nIndex, int nCount=1)
	{
		int nSize = this->size();
		if(nIndex >= nSize)
		{
			return;
		}

		// modified by zengzm 2005-9-12 增加判断,防止nCount<0
		int nEnd = nIndex + nCount;
		if (nEnd > nSize)
		{
			nEnd=nSize;
		}
		this->erase(this->begin() + nIndex, this->begin() + nEnd);
	}

	//! \brief 移除所有元素,同时清空所有空间。
	void RemoveAll()
	{
		this->clear(); 		
		FreeExtra();
	}

	//! \brief 释放数组中多余的内存空间。
	//! \remarks 删除数组中除有效元素占用外的空间。
	void FreeExtra()
	{
		if(this->capacity()>this->size()) {
			std::vector<T> vctTemp(this->begin(),this->end());
			swap(vctTemp);
		}
	}
};

#endif // !defined(AFX_XMRARRAY_H__D7AEE90B_335B_4B46_ABD3_73B8B54ED4E7__INCLUDED_)

⌨️ 快捷键说明

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