storage.h

来自「The main idea of this work is to create 」· C头文件 代码 · 共 49 行

H
49
字号
#if !defined(AFX_STORAGE_H__E265A536_EDBA_4C6C_A3D8_3A9CDB81130A__INCLUDED_)
#define AFX_STORAGE_H__E265A536_EDBA_4C6C_A3D8_3A9CDB81130A__INCLUDED_

#include "common.h"
template <class _KeyType,class _ValType>
class storage
{
public:
	bool Add(const _KeyType &refKey,const _ValType &refVal)
	{
		_KeyArray::iterator it = mKeyArray.begin();
		
		while(mKeyArray.end() != it)
		{
			if(it->first == refKey)
				return false;
			++it;
		}
		
		mKeyArray.push_back(std::make_pair(refKey,refVal));

		return true;
	}
	_ValType Get(const _KeyType &refKey)
	{
		_KeyArray::iterator it = mKeyArray.begin();
		
		while(mKeyArray.end() != it)
		{
			if(it->first == refKey)
				return it->second;
			
			++it;
		} 
		
		return NULL;
	}
	void Clear()
	{
		mKeyArray.clear();
	}
private:
	typedef  std::vector< std::pair<_KeyType,_ValType> > _KeyArray;
	_KeyArray mKeyArray;
};


#endif // !defined(AFX_STORAGE_H__E265A536_EDBA_4C6C_A3D8_3A9CDB81130A__INCLUDED_)

⌨️ 快捷键说明

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