Teamcenter C++ API Reference
2312
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
base_utils
SmAllocator.hxx
Go to the documentation of this file.
1
// Copyright 2022 Siemens Digital Industries Software
2
// ==================================================
3
// Copyright 2013.
4
// Siemens Product Lifecycle Management Software Inc.
5
// All Rights Reserved.
6
// ==================================================
7
// Copyright 2022 Siemens Digital Industries Software
15
/* */
16
17
/* */
18
#ifndef SM_ALLOCATOR_HXX_INCLUDED
19
#define SM_ALLOCATOR_HXX_INCLUDED
20
21
#include <cstddef>
22
23
#include <base_utils/Mem.h>
24
25
#include <limits.h>
26
#ifdef SGI
27
#include <new.h>
28
#define SGISTATIC static
29
#else
30
#include <new>
31
#define SGISTATIC
32
#endif //SGI
33
34
// USE_REBIND_CLASS used to be conditional in ifdef blocks for each platform.
35
// However, since ALL platforms are now covered, removed all ifdef blocks to
36
// make it ONE SINGLE statement.
37
#define USE_REBIND_CLASS
38
39
#ifdef SOLARIS
40
#define OVERLOAD_MAX_SIZE
41
#endif
42
43
// Disable spurious warning C4100: 'p' unreferenced formal parameter
44
// from 'void destroy(pointer p)'
45
#if defined(WNT) || defined(WNT32)
46
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
47
#pragma warning(push)
48
#endif
/* _MSC_VER >= 1200 */
49
#pragma warning(disable:4100)
50
#endif
/* _MSC_VER */
51
74
template
<
class
T>
75
class
sm_allocator
76
{
77
public
:
78
#ifdef USE_REBIND_CLASS
79
template
<
class
U>
80
class
rebind
81
{
82
public
:
83
typedef
sm_allocator<U>
other
;
84
};
85
86
template
<
class
U>
sm_allocator
(
const
sm_allocator<U>
&)
87
{
88
}
89
#endif
90
91
typedef
std::size_t
size_type
;
92
typedef
std::ptrdiff_t
difference_type
;
93
typedef
T *
pointer
;
94
typedef
const
T *
const_pointer
;
95
typedef
T&
reference
;
96
typedef
const
T&
const_reference
;
97
typedef
T
value_type
;
98
pointer
address
(
reference
x)
const
99
{
100
return
&x;
101
}
102
const_pointer
address
(
const_reference
x)
const
103
{
104
return
&x;
105
}
106
sm_allocator
()
107
{
108
}
109
sm_allocator<T>
&
operator=
(
const
sm_allocator<T>
&)
110
{
111
return
*
this
;
112
}
113
SGISTATIC
pointer
allocate
(
size_type
n,
const
void
*
/*hint*/
= NULL)
114
{
115
size_type
alloc_size = n *
sizeof
(T);
116
117
/* On Solaris, the parameter "n" is the number of bytes and not the number of elements, */
118
/* so don't multiply it by the sizeof(T) -- someone else has already done that. */
119
/*
120
#if defined(SOLARIS)
121
alloc_size = n;
122
#endif
123
*/
124
return
(T *)MEM_alloc(alloc_size);
125
}
126
char
*
_Charalloc
(
size_type
n)
127
{
128
return
(
char
*)MEM_alloc(n);
129
}
130
SGISTATIC
void
deallocate
(
pointer
p,
size_type
/*n*/
= 0)
131
{
132
MEM_free(p);
133
}
134
void
construct
(
pointer
p,
const
T& val)
135
{
136
new
(p) T(val);
137
}
138
void
destroy
(
pointer
p)
139
{
140
p->~T();
141
}
142
size_type
max_size
()
const
143
{
144
return
UINT_MAX /
sizeof
(T);
145
}
146
#ifdef OVERLOAD_MAX_SIZE
147
size_type
max_size
(
size_type
size)
const
148
{
149
return
1 > UINT_MAX/size ?
size_type
(1) : size_type(UINT_MAX/size);
150
}
151
#endif
152
bool
operator ==
(
const
sm_allocator
&
/*other*/
)
const
153
{
154
return
true
;
155
}
156
bool
operator !=
(
const
sm_allocator
&
/*other*/
)
const
157
{
158
return
false
;
159
}
160
};
161
162
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
163
#pragma warning(pop)
164
#endif
/* _MSC_VER */
165
166
#endif