ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthContainers
AthContainers
tools
DVLCast.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-, 20262026 CERN for the benefit of the ATLAS collaboration
4
*/
11
12
13
#ifndef ATHCONTAINERS_TOOLS_DVLCAST_H
14
#define ATHCONTAINERS_TOOLS_DVLCAST_H
15
16
17
#include <limits>
18
#include <limits.h>
19
#include <typeinfo>
20
#include <cstdlib>
21
#include <cstddef>
22
#include <print>
23
24
25
namespace
DataModel_detail
{
26
27
47
template
<
class
DVL,
bool
has_virtual=DVL::has_virtual>
struct
DVLCast
{};
48
49
53
template
<
class
DVL>
54
struct
DVLCast
<DVL, false>
55
{
56
typedef
typename
DVL::base_value_type
T
;
57
58
63
template
<
class
U>
64
static
T
*
cast
(U* b)
65
{
66
return
static_cast<
T
*
>
(b);
67
}
68
};
69
70
74
template
<
class
DVL>
75
struct
DVLCast
<DVL, true>
76
{
77
typedef
typename
DVL::base_value_type
T
;
78
79
83
template
<
class
U>
84
static
int
find_offset
(U* b)
85
{
86
T
* ret =
dynamic_cast<
T
*
>
(b);
87
int
offs =
reinterpret_cast<
char
*
>
(ret) -
reinterpret_cast<
char
*
>
(b);
88
return
offs;
89
}
90
91
96
template
<
class
U>
97
static
T
*
cast
(U* b)
98
{
99
// The common case will be for the dynamic type of b to be T.
100
// So test to avoid a dynamic_cast in that case.
101
// The extra test shouldn't add significant overhead
102
// to the case where we really need to run dynamic_cast.
103
if
(!b)
104
return
0;
105
if
(
typeid
(*b) ==
typeid
(
T
)) {
106
static
const
ptrdiff_t offs =
find_offset
(b);
107
return
reinterpret_cast<
T
*
>
(
reinterpret_cast<
char
*
>
(b) + offs);
108
}
109
else
110
return
dynamic_cast<
T
*
>
(b);
111
}
112
};
113
114
115
}
// namespace DataModel_detail
116
117
118
#endif
// not ATHCONTAINERS_TOOLS_DVLCAST_H
DataModel_detail
Definition
CompareAndPrint.h:15
DataModel_detail::DVLCast< DVL, false >::cast
static T * cast(U *b)
Cast b to a T*.
Definition
DVLCast.h:64
DataModel_detail::DVLCast< DVL, false >::T
DVL::base_value_type T
Definition
DVLCast.h:56
DataModel_detail::DVLCast< DVL, true >::cast
static T * cast(U *b)
Cast b to a T*.
Definition
DVLCast.h:97
DataModel_detail::DVLCast< DVL, true >::T
DVL::base_value_type T
Definition
DVLCast.h:77
DataModel_detail::DVLCast< DVL, true >::find_offset
static int find_offset(U *b)
Find the offset of T within U.
Definition
DVLCast.h:84
DataModel_detail::DVLCast
casting operations for DataVector/DataList.
Definition
DVLCast.h:47
Generated on
for ATLAS Offline Software by
1.17.0