MyGUI
3.2.1
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
mygui
MyGUIEngine
include
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__
Generated on Wed Aug 20 2014 00:03:31 for MyGUI by
1.8.3.1