/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Microsoft Corporation // // SYNOPSIS // // Declares the class StdAllocator and the typedefs StdString and StdWString. // /////////////////////////////////////////////////////////////////////////////// #ifndef STDSTRING_H #define STDSTRING_H #pragma once #include #include // Implements a standard library conformant allocator that uses the run-time's // private heap for allocations. template class StdAllocator { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; typedef T value_type; template struct rebind { typedef StdAllocator other; }; StdAllocator() throw (); // Lint is not smart enough to recognize copy constructors for template //lint -esym(1931, StdAllocator<*>::StdAllocator*) StdAllocator(const StdAllocator&) throw () { } template StdAllocator(const StdAllocator&) throw () { } ~StdAllocator() throw (); pointer address(reference x) const throw (); const_pointer address(const_reference x) const throw (); pointer allocate(size_type n, const void* hint = 0); void deallocate(pointer p, size_type n) throw (); size_type max_size() const throw (); void construct(pointer p, const T& val); void destroy(pointer p) throw (); // Non-standard member required by Microsoft's implementation. bool operator==(const StdAllocator& rhs) const throw (); }; // Replacement for std::string. typedef std::basic_string< char, std::char_traits, StdAllocator > StdString; // Replacement for std::wstring. typedef std::basic_string< wchar_t, std::char_traits, StdAllocator > StdWString; template inline StdAllocator::StdAllocator() throw () { } template inline StdAllocator::~StdAllocator() throw () { } template inline __TYPENAME StdAllocator::pointer StdAllocator::address( reference x ) const throw () { return &x; } template inline __TYPENAME StdAllocator::const_pointer StdAllocator::address( const_reference x ) const throw () { return &x; } template inline __TYPENAME StdAllocator::pointer StdAllocator::allocate( size_type n, const void* ) { return static_cast(operator new (n * sizeof(T))); } template inline void StdAllocator::deallocate(pointer p, size_type) throw () { operator delete(p); } template inline __TYPENAME StdAllocator::size_type StdAllocator::max_size() const throw () { // Max size supported by the NT heap. return MAXINT_PTR; } template inline void StdAllocator::construct(pointer p, const T& val) { new (p) T(val); } template inline void StdAllocator::destroy(pointer p) throw () { p->~T(); } template inline bool StdAllocator::operator==(const StdAllocator&) const throw () { return true; } #endif // STDSTRING_H