#ifndef CSTLALLOCATOR_H_INCLUDED #define CSTLALLOCATOR_H_INCLUDED #include "cAudioDefines.h" #include "cAudioMemory.h" //#include "cAudioString.h" #include #include #include #include #include namespace cAudio { #ifdef CAUDIO_REROUTE_STL_ALLOCATIONS //! Reroutes allocations from STL containers into cAudio's memory system template class cSTLAllocator { public: typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; template struct rebind { typedef cSTLAllocator other; }; cSTLAllocator() { } ~cSTLAllocator() throw() { } cSTLAllocator( const cSTLAllocator& ) throw() { } template cSTLAllocator( const cSTLAllocator& ) throw() { } pointer address(reference x) const { return &x; } const_pointer address(const_reference x) const { return &x; } pointer allocate( size_type count, typename std::allocator::const_pointer ptr = 0 ) { (void)ptr; register size_type size = count*sizeof( T ); pointer p = static_cast(CAUDIO_MALLOC(size)); return p; } void deallocate( pointer p, size_type size ) { CAUDIO_FREE(p); } size_type max_size() const throw() { return cAudio::getMemoryProvider()->getMaxAllocationSize(); } void construct(pointer p, const T& val) { // call placement new new(static_cast(p)) T(val); } void destroy(pointer p) { p->~T(); } }; template<> class cSTLAllocator { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template struct rebind { typedef cSTLAllocator other; }; }; template inline bool operator==(const cSTLAllocator&, const cSTLAllocator&) { return true; } template inline bool operator!=(const cSTLAllocator&, const cSTLAllocator&) { return false; } #endif #ifdef CAUDIO_REROUTE_STL_ALLOCATIONS //typedef std::basic_string< cAudioChar, std::char_traits, cSTLAllocator > cAudioString; template struct cAudioMap { typedef std::map< T1, T2, std::less< T1 >, cSTLAllocator< std::pair< T1, T2 > > > Type; }; template struct cAudioSet { typedef std::set< T, std::less< T >, cSTLAllocator< T > > Type; }; template struct cAudioList { typedef std::list< T, cSTLAllocator< T > > Type; }; template struct cAudioVector { typedef std::vector< T, cSTLAllocator< T > > Type; }; #else //typedef std::string cAudioString; //typedef std::basic_string cAudioString; template struct cAudioMap { typedef std::map< T1, T2> Type; }; template struct cAudioSet { typedef std::set< T > Type; }; template struct cAudioList { typedef std::list< T > Type; }; template struct cAudioVector { typedef std::vector< T > Type; }; #endif }; #endif //! CSTLALLOCATOR_H_INCLUDED