ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
AtlasTest
TestTools
TestTools
TestAlloc.h
Go to the documentation of this file.
1
// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
/*
3
* Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
4
*/
11
12
13
#ifndef TESTTOOLS_TESTALLOC_H
14
#define TESTTOOLS_TESTALLOC_H
15
16
17
namespace
Athena_test
{
18
19
27
template
<
class
T>
28
class
TestAlloc
29
{
30
public
:
32
typedef
T*
pointer
;
33
typedef
const
T*
const_pointer
;
34
typedef
T&
reference
;
35
typedef
const
T&
const_reference
;
36
typedef
T
value_type
;
37
typedef
size_t
size_type
;
38
typedef
ptrdiff_t
difference_type
;
39
40
constexpr
static
size_t
MAGIC
= 0xdeadbeeffeedabba;
41
42
struct
Head
{
43
size_t
i
[2];
44
};
45
pointer
allocate
(
size_type
n,
const
void
* = 0)
46
{
47
void
* p = malloc (
sizeof
(
Head
) + n*
sizeof
(T));
48
if
(!p) std::abort();
49
Head
*
h
= (
Head
*)p;
50
h
->i[0] = n;
51
h
->i[1] =
MAGIC
;
52
return
reinterpret_cast<
pointer
>
(
h
+1);
53
}
54
55
void
deallocate
(
pointer
p,
size_type
n)
56
{
57
Head
*
h
=
reinterpret_cast<
Head
*
>
(p);
58
--
h
;
59
if
(
h
->i[0] != n ||
60
h
->i[1] !=
MAGIC
) {
61
std::abort();
62
}
63
free (
h
);
64
}
65
66
size_type
max_size
()
const
throw()
67
{
68
return
99999;
69
}
70
71
template
<
class
...
Args
>
72
void
construct
(
pointer
p,
Args
&&... args)
73
{
74
// Suppress bogus warning seen with gcc 14.1.
75
#if __GNUC__ >= 14
76
# pragma GCC diagnostic push
77
# pragma GCC diagnostic ignored "-Wstringop-overflow"
78
#endif
79
new
(p) T(std::forward<Args>(args)...);
80
#if __GNUC__ >= 14
81
# pragma GCC diagnostic pop
82
#endif
83
}
84
85
void
destroy
(
pointer
p)
86
{
87
p->~T();
88
}
89
90
pointer
address
(
reference
x
)
const
91
{
92
return
&
x
;
93
}
94
95
const_pointer
address
(
const_reference
x
)
const
96
{
97
return
&
x
;
98
}
99
100
// We have no state, so consider all instances equal.
101
bool
operator==
(
const
TestAlloc
&
/*other*/
)
const
102
{
return
true
; }
103
};
104
105
106
}
// namespace Athena_test
107
108
109
#endif
// not TESTTOOLS_TESTALLOC_H
x
#define x
h
Header file for AthHistogramAlgorithm.
Athena_test::TestAlloc
To test handling of non-standard memory allocators.
Definition
TestAlloc.h:29
Athena_test::TestAlloc::const_reference
const T & const_reference
Definition
TestAlloc.h:35
Athena_test::TestAlloc::value_type
T value_type
Definition
TestAlloc.h:36
Athena_test::TestAlloc::address
const_pointer address(const_reference x) const
Definition
TestAlloc.h:95
Athena_test::TestAlloc::const_pointer
const T * const_pointer
Definition
TestAlloc.h:33
Athena_test::TestAlloc::reference
T & reference
Definition
TestAlloc.h:34
Athena_test::TestAlloc::address
pointer address(reference x) const
Definition
TestAlloc.h:90
Athena_test::TestAlloc::difference_type
ptrdiff_t difference_type
Definition
TestAlloc.h:38
Athena_test::TestAlloc::size_type
size_t size_type
Definition
TestAlloc.h:37
Athena_test::TestAlloc::max_size
size_type max_size() const
Definition
TestAlloc.h:66
Athena_test::TestAlloc::pointer
T * pointer
Standard STL allocator typedefs.
Definition
TestAlloc.h:32
Athena_test::TestAlloc::allocate
pointer allocate(size_type n, const void *=0)
Definition
TestAlloc.h:45
Athena_test::TestAlloc::deallocate
void deallocate(pointer p, size_type n)
Definition
TestAlloc.h:55
Athena_test::TestAlloc::operator==
bool operator==(const TestAlloc &) const
Definition
TestAlloc.h:101
Athena_test::TestAlloc::construct
void construct(pointer p, Args &&... args)
Definition
TestAlloc.h:72
Athena_test::TestAlloc::MAGIC
static constexpr size_t MAGIC
Definition
TestAlloc.h:40
Athena_test::TestAlloc::destroy
void destroy(pointer p)
Definition
TestAlloc.h:85
Athena_test
functions & macros to test the difference between floats
Definition
InitGaudiGoogleTest.h:30
Args
Definition
test_lwtnn_fastgraph.cxx:12
Athena_test::TestAlloc::Head
Definition
TestAlloc.h:42
Athena_test::TestAlloc::Head::i
size_t i[2]
Definition
TestAlloc.h:43
Generated on
for ATLAS Offline Software by
1.17.0