MyGUI 3.2.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_Allocator.h
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #ifndef MYGUI_ALLOCATOR_H_
8 #define MYGUI_ALLOCATOR_H_
9
10 #include <memory>
11 #include <limits>
12
13 namespace MyGUI
14 {
15
16 template<typename T>
17 class Allocator
18 {
19 public:
20 // typedefs
21 typedef T value_type;
22 typedef value_type* pointer;
23 typedef const value_type* const_pointer;
24 typedef value_type& reference;
25 typedef const value_type& const_reference;
26 typedef std::size_t size_type;
27 typedef std::ptrdiff_t difference_type;
28
29 public:
30 // convert an allocator<T> to allocator<U>
31 template<typename U>
32 struct rebind
33 {
34 typedef Allocator<U> other;
35 };
36
37 public:
38 inline explicit Allocator() { }
39 inline ~Allocator() { }
40 template<typename U>
41 inline explicit Allocator(Allocator<U> const&) { }
42
43 // address
44 inline pointer address(reference r)
45 {
46 return &r;
47 }
48 inline const_pointer address(const_reference r)
49 {
50 return &r;
51 }
52
53 // memory allocation
54 inline pointer allocate(size_type cnt, typename std::allocator<void>::const_pointer = 0)
55 {
56 return reinterpret_cast<pointer>(::operator new (cnt * sizeof (T)));
57 }
58 inline void deallocate(pointer p, size_type)
59 {
60 ::operator delete (p);
61 }
62
63 // size
64 inline size_type max_size() const
65 {
66 return (std::numeric_limits<size_type>::max)() / sizeof(T);
67 }
68
69 // construction/destruction
70 inline void construct(pointer p, const T& t)
71 {
72 new (p) T(t);
73 }
74 inline void destroy(pointer p)
75 {
76 p->~T();
77 }
78
79 inline bool operator==(Allocator const&)
80 {
81 return true;
82 }
83 inline bool operator!=(Allocator const& a)
84 {
85 return !operator==(a);
86 }
87 };
88
89 } // namespace MyGUI
90
91 #endif // MYGUI_ALLOCATOR_H_
MyGUI::Allocator::Allocator
Allocator()
Definition: MyGUI_Allocator.h:38
MyGUI::Allocator::operator==
bool operator==(Allocator const &)
Definition: MyGUI_Allocator.h:79
MyGUI::Allocator::const_reference
const value_type & const_reference
Definition: MyGUI_Allocator.h:25
MyGUI::Allocator::difference_type
std::ptrdiff_t difference_type
Definition: MyGUI_Allocator.h:27
MyGUI::Allocator::operator!=
bool operator!=(Allocator const &a)
Definition: MyGUI_Allocator.h:83
MyGUI::Allocator
Definition: MyGUI_Allocator.h:17
MyGUI::Allocator::rebind::other
Allocator< U > other
Definition: MyGUI_Allocator.h:34
MyGUI::Allocator::Allocator
Allocator(Allocator< U > const &)
Definition: MyGUI_Allocator.h:41
MyGUI::Allocator::max_size
size_type max_size() const
Definition: MyGUI_Allocator.h:64
MyGUI::Allocator::value_type
T value_type
Definition: MyGUI_Allocator.h:21
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::Allocator::deallocate
void deallocate(pointer p, size_type)
Definition: MyGUI_Allocator.h:58
MyGUI::Allocator::address
const_pointer address(const_reference r)
Definition: MyGUI_Allocator.h:48
MyGUI::Allocator::const_pointer
const value_type * const_pointer
Definition: MyGUI_Allocator.h:23
MyGUI::Allocator::rebind
Definition: MyGUI_Allocator.h:32
MyGUI::Allocator::destroy
void destroy(pointer p)
Definition: MyGUI_Allocator.h:74
MyGUI::Allocator::reference
value_type & reference
Definition: MyGUI_Allocator.h:24
MyGUI::Allocator::size_type
std::size_t size_type
Definition: MyGUI_Allocator.h:26
MyGUI::Allocator::address
pointer address(reference r)
Definition: MyGUI_Allocator.h:44
MyGUI::Allocator::pointer
value_type * pointer
Definition: MyGUI_Allocator.h:22
MyGUI::Allocator::allocate
pointer allocate(size_type cnt, typename std::allocator< void >::const_pointer=0)
Definition: MyGUI_Allocator.h:54
MyGUI::Allocator::~Allocator
~Allocator()
Definition: MyGUI_Allocator.h:39
MyGUI::Allocator::construct
void construct(pointer p, const T &t)
Definition: MyGUI_Allocator.h:70