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

📄 rpgstdmemory.h

📁 五行MMORPG引擎系统V1.0
💻 H
字号:
// xmemory internal header (from <memory>)
#pragma once
#ifndef _RPG__STDMEMORY_H_
#define _RPG__STDMEMORY_H_
//#include <cstdlib>
//#include <new>
#include <xutility>

#pragma pack(push,8)
#pragma warning(push,3)

 #pragma warning(disable: 4100)

#ifndef _FARQ	/* specify standard memory model */
 #define _FARQ
 #define _PDFT	ptrdiff_t
 #define _SIZT	size_t
#endif

#define _RPG_DESTRUCTOR(ty, ptr)		(ptr)->~ty()

 //#define _CPOINTER_X(T, A)		\
	//typename A::template rebind<T>::other::const_pointer
 //#define _CREFERENCE_X(T, A)	\
	//typename A::template rebind<T>::other::const_reference
 //#define _POINTER_X(T, A)	\
	//typename A::template rebind<T>::other::pointer
 //#define _REFERENCE_X(T, A)	\
	//typename A::template rebind<T>::other::reference

namespace RPG
{
//_STD_BEGIN
		// TEMPLATE FUNCTION _Allocate
//template<class _Ty> inline
//	_Ty _FARQ *_Allocate(_SIZT _Count, _Ty _FARQ *)
//	{	// allocate storage for _Count elements of type _Ty
//	return (_Ty _FARQ *)dMalloc(_Count * sizeof (_Ty));//operator new(_Count * sizeof (_Ty)));
//	}

		// TEMPLATE FUNCTION _Construct
//template<class _T1,
//	class _T2> inline
//	void _Construct(_T1 _FARQ *_Ptr, const _T2& _Val)
//	{	// construct object at _Ptr with value _Val
//	new ((void _FARQ *)_Ptr) _T1(_Val);
//	}

		// TEMPLATE FUNCTION _Destroy
//template<class _Ty> inline
//	void _Destroy(_Ty _FARQ *_Ptr)
//	{	// destroy object at _Ptr
//	_RPG_DESTRUCTOR(_Ty, _Ptr);
//	}

//template<> inline
//	void _Destroy(char _FARQ *)
//	{	// destroy a char (do nothing)
//	}
//
//template<> inline
//	void _Destroy(wchar_t _FARQ *)
//	{	// destroy a wchar_t (do nothing)
//	}


		// TEMPLATE CLASS _Allocator_base
template<class _Ty>
struct _Allocator_base
{	// base class for generic allocators
	typedef _Ty value_type;
};

		// TEMPLATE CLASS _Allocator_base<const _Ty>
template<class _Ty>
struct _Allocator_base<const _Ty>
{	// base class for generic allocators for const _Ty
	typedef _Ty value_type;
};

		// TEMPLATE CLASS allocator
template<class _Ty>
class allocator	: public _Allocator_base<_Ty>
{	// generic allocator for objects of class _Ty
public:
	typedef _Allocator_base<_Ty> _Mybase;
	typedef typename _Mybase::value_type value_type;


	typedef value_type _FARQ *pointer;
	typedef value_type _FARQ& reference;
	typedef const value_type _FARQ *const_pointer;
	typedef const value_type _FARQ& const_reference;

	typedef _SIZT size_type;
	typedef _PDFT difference_type;

	template<class _Other>
		struct rebind
		{	// convert an allocator<_Ty> to an allocator <_Other>
			typedef allocator<_Other> other;
		};

	pointer address(reference _Val) const
	{	// return address of mutable _Val
		return (&_Val);
	}

	const_pointer address(const_reference _Val) const
	{	// return address of nonmutable _Val
		return (&_Val);
	}

	allocator()
	{	// construct default allocator (do nothing)
	}

	allocator(const allocator<_Ty>&)
	{	// construct by copying (do nothing)
	}

	template<class _Other>
	allocator(const allocator<_Other>&)
	{	// construct from a related allocator (do nothing)
	}

	template<class _Other>
	allocator<_Ty>& operator=(const allocator<_Other>&)
	{	// assign from a related allocator (do nothing)
		return (*this);
	}

	void deallocate(pointer _Ptr, size_type)
	{	// deallocate object at _Ptr, ignore size
		//operator delete(_Ptr);
		dFree(_Ptr);
	}

	pointer allocate(size_type _Count)
	{	// allocate array of _Count elements
		//return (_Allocate(_Count, (pointer)0));
			return (_Ty _FARQ *)dMalloc(_Count * sizeof (_Ty));//operator new(_Count * sizeof (_Ty)));
	}

	pointer allocate(size_type _Count, const void _FARQ *)
	{	// allocate array of _Count elements, ignore hint
		return (allocate(_Count));
	}

	void construct(pointer _Ptr, const _Ty& _Val)
	{	// construct object at _Ptr with value _Val
		//_Construct(_Ptr, _Val);
			//new ((void _FARQ *)_Ptr) _Ty(_Val);
			constructInPlace(_Ptr);
	}

	void destroy(pointer _Ptr)
	{	// destroy object at _Ptr
		//_Destroy(_Ptr);
			destructInPlace(_Ptr);
	}

	_SIZT max_size() const
	{	// estimate maximum array size
		_SIZT _Count = (_SIZT)(-1) / sizeof (_Ty);
		return (0 < _Count ? _Count : 1);
	}
};

		// allocator TEMPLATE OPERATORS
template<class _Ty,	class _Other>
inline	bool operator==(const allocator<_Ty>&, const allocator<_Other>&)
{	// test for allocator equality (always true)
	return (true);
}

template<class _Ty,	class _Other> 
inline bool operator!=(const allocator<_Ty>&, const allocator<_Other>&)
{	// test for allocator inequality (always false)
	return (false);
}

		// CLASS allocator<void>
template<> class _CRTIMP2 allocator<void>
{	// generic allocator for type void
public:
	typedef void _Ty;
	typedef _Ty _FARQ *pointer;
	typedef const _Ty _FARQ *const_pointer;
	typedef _Ty value_type;

	template<class _Other>
	struct rebind
	{	// convert an allocator<void> to an allocator <_Other>
		typedef allocator<_Other> other;
	};

	allocator()
	{	// construct default allocator (do nothing)
	}

	allocator(const allocator<_Ty>&)
	{	// construct by copying (do nothing)
	}

	template<class _Other>
	allocator(const allocator<_Other>&)
	{	// construct from related allocator (do nothing)
	}

	template<class _Other>
	allocator<_Ty>& operator=(const allocator<_Other>&)
	{	// assign from a related allocator (do nothing)
		return (*this);
	}
};

		// TEMPLATE FUNCTION _Destroy_range
template<class _Ty,
	class _Alloc> inline
	void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al)
	{	// destroy [_First, _Last)
	_Destroy_range(_First, _Last, _Al, _Ptr_cat(_First, _Last));
	}

template<class _Ty,
	class _Alloc> inline
	void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al,
	std::_Nonscalar_ptr_iterator_tag)
	{	// destroy [_First, _Last), arbitrary type
	for (; _First != _Last; ++_First)
		_Al.destroy(_First);
	}

template<class _Ty,
	class _Alloc> inline
	void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al,
		std::_Scalar_ptr_iterator_tag)
	{	// destroy [_First, _Last), scalar type (do nothing)
	}
//_STD_END
};//namespace RPG

 #pragma warning(default: 4100)

#pragma warning(pop)
#pragma pack(pop)

#endif /* _RPG__STDMEMORY_H_ */


⌨️ 快捷键说明

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