ATLAS Offline Software
UIntConv.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-2023 CERN for the benefit of the ATLAS collaboration.
4  */
20 #ifndef CXXUTILS_UINTCONV_H
21 #define CXXUTILS_UINTCONV_H
22 
23 
24 #include "CxxUtils/SizedUInt.h"
25 #include <cstdint>
26 
27 
28 namespace CxxUtils {
29 namespace detail {
30 
31 
35 template <class T>
36 union UIntConv
37 {
38  // Unsigned type of the same size as T.
39  using uint_t = typename SizedUInt<sizeof(T)>::type;
40 
41  // Union members to convert between uint_t and T.
43  T x;
44 
45 
49  static uintptr_t valToUInt (T x) {
50  UIntConv u;
51  u.x = x;
52  return static_cast<uintptr_t> (u.ui);
53  };
54 
55 
59  static T uintToVal (uintptr_t ui) {
60  UIntConv u;
61  u.ui = static_cast<uint_t>(ui);
62  return u.x;
63  };
64 };
65 
66 
67 // Specialization for the case where no conversion is required.
68 template <>
69 union UIntConv<uintptr_t>
70 {
74  static uintptr_t valToUInt (uintptr_t x) {
75  return x;
76  };
77 
78 
82  static uintptr_t uintToVal (uintptr_t ui) {
83  return ui;
84  };
85 };
86 
87 
88 } // namespace detail
89 } // namespace CxxUtils
90 
91 
92 #endif // not CXXUTILS_UINTCONV_H
CxxUtils::detail::UIntConv::x
T x
Definition: UIntConv.h:43
CxxUtils::detail::UIntConv< uintptr_t >::uintToVal
static uintptr_t uintToVal(uintptr_t ui)
Convert a uintptr_t to a T.
Definition: UIntConv.h:82
SizedUInt.h
Generate an unsigned integer type of a specified size.
CxxUtils::detail::SizedUInt
Definition: SizedUInt.h:28
detail
Definition: extract_histogram_tag.cxx:14
CxxUtils::detail::UIntConv::uint_t
typename SizedUInt< sizeof(T)>::type uint_t
Definition: UIntConv.h:39
CxxUtils::detail::UIntConv::ui
uint_t ui
Definition: UIntConv.h:42
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
CxxUtils::detail::UIntConv::valToUInt
static uintptr_t valToUInt(T x)
Convert a T to a uintptr_t.
Definition: UIntConv.h:49
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::detail::UIntConv::uintToVal
static T uintToVal(uintptr_t ui)
Convert a uintptr_t to a T.
Definition: UIntConv.h:59
CxxUtils::detail::UIntConv
Helpers for converting between uintptr_t and a pointer or integer.
Definition: UIntConv.h:37
CxxUtils::detail::UIntConv< uintptr_t >::valToUInt
static uintptr_t valToUInt(uintptr_t x)
Convert a T to a uintptr_t.
Definition: UIntConv.h:74
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78