ATLAS Offline Software
Public Types | Static Public Member Functions | List of all members
DataModel_detail::DVLCast< DVL, true > Struct Template Reference

casting operations for DataVector/List, dynamic_cast version. More...

#include <DVLCast.h>

Collaboration diagram for DataModel_detail::DVLCast< DVL, true >:

Public Types

typedef DVL::base_value_type T
 

Static Public Member Functions

template<class U >
static int find_offset (U *b)
 Find the offset of T within U. More...
 
template<class U >
static Tcast (U *b)
 Cast b to a T*. More...
 
template<class U >
static const Tcast (const U *b)
 Cast b to a const T*. More...
 

Detailed Description

template<class DVL>
struct DataModel_detail::DVLCast< DVL, true >

casting operations for DataVector/List, dynamic_cast version.

Definition at line 88 of file DVLCast.h.

Member Typedef Documentation

◆ T

template<class DVL >
typedef DVL::base_value_type DataModel_detail::DVLCast< DVL, true >::T

Definition at line 90 of file DVLCast.h.

Member Function Documentation

◆ cast() [1/2]

template<class DVL >
template<class U >
static const T* DataModel_detail::DVLCast< DVL, true >::cast ( const U *  b)
inlinestatic

Cast b to a const T*.

Parameters
bPointer to cast.

Definition at line 132 of file DVLCast.h.

133  {
134  // See above.
135  if (!b)
136  return 0;
137  if (typeid(*b) == typeid(T)) {
138  static ptrdiff_t offs = LONG_MAX;
139  if (offs == LONG_MAX) {
140  T* ret = dynamic_cast<const T*> (b);
141  offs = reinterpret_cast<char*>(ret) - reinterpret_cast<char*>(b);
142  return ret;
143  }
144  return reinterpret_cast<const T*> (reinterpret_cast<char*>(b) + offs);
145  }
146  else
147  return dynamic_cast<const T*> (b);
148  }

◆ cast() [2/2]

template<class DVL >
template<class U >
static T* DataModel_detail::DVLCast< DVL, true >::cast ( U *  b)
inlinestatic

Cast b to a T*.

Parameters
bPointer to cast.

Definition at line 110 of file DVLCast.h.

111  {
112  // The common case will be for the dynamic type of b to be T.
113  // So test to avoid a dynamic_cast in that case.
114  // The extra test shouldn't add significant overhead
115  // to the case where we really need to run dynamic_cast.
116  if (!b)
117  return 0;
118  if (typeid(*b) == typeid(T)) {
119  static const ptrdiff_t offs = find_offset (b);
120  return reinterpret_cast<T*> (reinterpret_cast<char*>(b) + offs);
121  }
122  else
123  return dynamic_cast<T*> (b);
124  }

◆ find_offset()

template<class DVL >
template<class U >
static int DataModel_detail::DVLCast< DVL, true >::find_offset ( U *  b)
inlinestatic

Find the offset of T within U.

Definition at line 97 of file DVLCast.h.

98  {
99  T* ret = dynamic_cast<T*> (b);
100  int offs = reinterpret_cast<char*>(ret) - reinterpret_cast<char*>(b);
101  return offs;
102  }

The documentation for this struct was generated from the following file:
DataModel_detail::DVLCast< DVL, true >::find_offset
static int find_offset(U *b)
Find the offset of T within U.
Definition: DVLCast.h:97
ret
T ret(T t)
Definition: rootspy.cxx:260
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
DataModel_detail::DVLCast< DVL, true >::T
DVL::base_value_type T
Definition: DVLCast.h:90