cAudio 2.3.0
3d Audio Engine
Loading...
Searching...
No Matches
cSTLAllocator.h
1// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2// This file is part of the "cAudio Engine"
3// For conditions of distribution and use, see copyright notice in cAudio.h
4
5#pragma once
6
7#include "cAudioDefines.h"
8#include "cAudioMemory.h"
9//#include "cAudioString.h"
10
11#include <set>
12#include <map>
13#include <list>
14#include <vector>
15#include <string>
16#include <cstddef>
17
18namespace cAudio
19{
20#if CAUDIO_REROUTE_STL_ALLOCATIONS == 1
22 template <typename T> class cSTLAllocator
23 {
24 public:
25 typedef T value_type;
26 typedef value_type* pointer;
27 typedef const value_type* const_pointer;
28 typedef value_type& reference;
29 typedef const value_type& const_reference;
30 typedef std::size_t size_type;
31 typedef std::ptrdiff_t difference_type;
32
33 template<typename U>
34 struct rebind
35 {
36 typedef cSTLAllocator<U> other;
37 };
38
39 cSTLAllocator()
40 { }
41
42 ~cSTLAllocator() throw()
43 { }
44
45 cSTLAllocator( const cSTLAllocator& ) throw()
46 { }
47
48 template <typename U>
49 cSTLAllocator( const cSTLAllocator<U>& ) throw()
50 { }
51
52 pointer address(reference x) const
53 {
54 return &x;
55 }
56
57 const_pointer address(const_reference x) const
58 {
59 return &x;
60 }
61
62 pointer allocate( size_type count, typename std::allocator<void>::const_pointer ptr = 0 )
63 {
64 (void)ptr;
65 size_type size = count*sizeof( T );
66 pointer p = static_cast<pointer>(CAUDIO_MALLOC(size));
67 return p;
68 }
69
70 void deallocate( pointer p, size_type size )
71 {
72 CAUDIO_FREE(p);
73 }
74
75 size_type max_size() const throw()
76 {
78 }
79
80 void construct(pointer p, const T& val)
81 {
82 // call placement new
83 new(static_cast<void*>(p)) T(val);
84 }
85
86 void destroy(pointer p)
87 {
88 p->~T();
89 }
90 };
91
92 template<> class cSTLAllocator<void>
93 {
94 public:
95 typedef size_t size_type;
96 typedef ptrdiff_t difference_type;
97 typedef void* pointer;
98 typedef const void* const_pointer;
99 typedef void value_type;
100
101 template<typename U>
102 struct rebind
103 {
104 typedef cSTLAllocator<U> other;
105 };
106 };
107
108 template <typename T>
109 inline bool operator==(const cSTLAllocator<T>&, const cSTLAllocator<T>&)
110 {
111 return true;
112 }
113
114 template <typename T>
115 inline bool operator!=(const cSTLAllocator<T>&, const cSTLAllocator<T>&)
116 {
117 return false;
118 }
119#endif
120
121#if CAUDIO_REROUTE_STL_ALLOCATIONS == 1
122 //typedef std::basic_string< cAudioChar, std::char_traits<cAudioChar>, cSTLAllocator<cAudioChar> > cAudioString;
123 template<typename T1, typename T2> struct cAudioMap { typedef std::map< T1, T2, std::less< T1 >, cSTLAllocator< std::pair< T1, T2 > > > Type; };
124 template<typename T> struct cAudioSet { typedef std::set< T, std::less< T >, cSTLAllocator< T > > Type; };
125 template<typename T> struct cAudioList { typedef std::list< T, cSTLAllocator< T > > Type; };
126 template<typename T> struct cAudioVector { typedef std::vector< T, cSTLAllocator< T > > Type; };
127#else
128 //typedef std::string cAudioString;
129 //typedef std::basic_string<cAudioChar> cAudioString;
130 template<typename T1, typename T2> struct cAudioMap { typedef std::map< T1, T2> Type; };
131 template<typename T> struct cAudioSet { typedef std::set< T > Type; };
132 template<typename T> struct cAudioList { typedef std::list< T > Type; };
133 template<typename T> struct cAudioVector { typedef std::vector< T > Type; };
134#endif
135
136};
virtual size_t getMaxAllocationSize()=0
Returns the largest possible single allocation that can be made.
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:16
CAUDIO_API IMemoryProvider * getMemoryProvider()
Returns a pointer to the memory provider of cAudio.