/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. #ifndef CRYINCLUDE_CRYPOOL_STLWRAPPER_H #define CRYINCLUDE_CRYPOOL_STLWRAPPER_H #pragma once namespace NCryPoolAlloc { //namespace CSTLPoolAllocWrapperHelper //{ // inline void destruct(char *) {} // inline void destruct(wchar_t*) {} // template // inline void destruct(T *t) {t->~T();} //} //template //struct CSTLPoolAllocWrapperStatic //{ // static PoolAllocator * allocator; //}; //template //struct CSTLPoolAllocWrapperKungFu : public CSTLPoolAllocWrapperStatic //{ //}; template class CSTLPoolAllocWrapper { private: static TCont* m_pContainer; 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; static TCont* Container(){return m_pContainer; } static void Container(TCont* pContainer){m_pContainer = pContainer; } template struct rebind { typedef CSTLPoolAllocWrapper other; }; CSTLPoolAllocWrapper() throw() { } CSTLPoolAllocWrapper(const CSTLPoolAllocWrapper&) throw() { } template CSTLPoolAllocWrapper(const CSTLPoolAllocWrapper&) throw() { } ~CSTLPoolAllocWrapper() throw() { } pointer address(reference x) const { return &x; } const_pointer address(const_reference x) const { return &x; } pointer allocate(size_type n = 1, const_pointer hint = 0) { TCont* pContainer = Container(); uint8* pData = pContainer->TCont::template Allocate(n * sizeof(T), sizeof(T)); return pContainer->TCont::template Resolve(pData); // return Container()?Container()->Allocate(n*sizeof(T),sizeof(T)):0 } void deallocate(pointer p, size_type n = 1) { if (Container()) { Container()->Free(p); } } size_type max_size() const throw() { return Container() ? Container()->MemSize() : 0; } void construct(pointer p, const T& val) { new(static_cast(p))T(val); } void construct(pointer p) { new(static_cast(p))T(); } void destroy(pointer p) { p->~T(); } pointer new_pointer() { return new(allocate())T(); } pointer new_pointer(const T& val) { return new(allocate())T(val); } void delete_pointer(pointer p) { p->~T(); deallocate(p); } bool operator==(const CSTLPoolAllocWrapper&) {return true; } bool operator!=(const CSTLPoolAllocWrapper&) {return false; } }; } #endif // CRYINCLUDE_CRYPOOL_STLWRAPPER_H