windows-nt/Source/XPSP1/NT/sdktools/rasdiag/private/stlxmem.h
2020-09-26 16:20:57 +08:00

153 lines
3.3 KiB
C++

#pragma once
#ifndef _STLXMEM_H_
#define _STLXMEM_H_
//#include <cstdlib>
//#include <new>
//#include <utility>
#include <stdlib.h>
#include <stlnew.h>
#include <stlutil.h>
#ifdef _MSC_VER
#pragma pack(push,8)
#endif /* _MSC_VER */
#ifndef _FARQ /* specify standard memory model */
#define _FARQ
#define _PDFT ptrdiff_t
#define _SIZT size_t
#endif
#define _POINTER_X(T, A) T _FARQ *
#define _REFERENCE_X(T, A) T _FARQ &
_STD_BEGIN
// TEMPLATE FUNCTION _Allocate
template<class _Ty> inline
_Ty _FARQ *_Allocate(_PDFT _N, _Ty _FARQ *)
{
if (_N < 0)
_N = 0;
return ((_Ty _FARQ *)operator new((_SIZT)_N * sizeof (_Ty), raiseexception));
}
// TEMPLATE FUNCTION _Construct
template<class _T1, class _T2> inline
void _Construct(_T1 _FARQ *_P, const _T2& _V)
{
new ((void _FARQ *)_P) _T1(_V);
}
// TEMPLATE FUNCTION _Destroy
template<class _Ty> inline
void _Destroy(_Ty _FARQ *_P)
{
_DESTRUCTOR(_Ty, _P);
}
inline void _Destroy(char _FARQ *_P)
{
}
inline void _Destroy(wchar_t _FARQ *_P)
{
}
// TEMPLATE CLASS allocator
template<class _Ty>
class allocator
{
public:
typedef _SIZT size_type;
typedef _PDFT difference_type;
typedef _Ty _FARQ *pointer;
typedef const _Ty _FARQ *const_pointer;
typedef _Ty _FARQ& reference;
typedef const _Ty _FARQ& const_reference;
typedef _Ty value_type;
pointer address(reference _X) const
{
return (&_X);
}
const_pointer address(const_reference _X) const
{
return (&_X);
}
pointer allocate(size_type _N, const void *)
{
return (_Allocate((difference_type)_N, (pointer)0));
}
char _FARQ *_Charalloc(size_type _N)
{
return (_Allocate((difference_type)_N, (char _FARQ *)0));
}
void deallocate(void _FARQ *_P, size_type)
{
operator delete(_P);
}
void construct(pointer _P, const _Ty& _V)
{
_Construct(_P, _V);
}
void destroy(pointer _P)
{
_Destroy(_P);
}
_SIZT max_size() const
{
_SIZT _N = (_SIZT)(-1) / sizeof (_Ty);
return (0 < _N ? _N : 1);
}
};
template<class _Ty, class _U> inline
bool operator==(const allocator<_Ty>&, const allocator<_U>&)
{
return (true);
}
template<class _Ty, class _U> inline
bool operator!=(const allocator<_Ty>&, const allocator<_U>&)
{
return (false);
}
// CLASS allocator<void>
class /*_CRTIMP*/ allocator<void>
{
public:
typedef void _Ty;
typedef _Ty _FARQ *pointer;
typedef const _Ty _FARQ *const_pointer;
typedef _Ty value_type;
};
_STD_END
#ifdef _MSC_VER
#pragma pack(pop)
#endif /* _MSC_VER */
#endif /* _STLXMEM_H_ */
/*
* Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
*/
/*
* This file is derived from software bearing the following
* restrictions:
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this
* software and its documentation for any purpose is hereby
* granted without fee, provided that the above copyright notice
* appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation.
* Hewlett-Packard Company makes no representations about the
* suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
*/