ATLAS Offline Software
Loading...
Searching...
No Matches
StorableConversions.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/*
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef ATHENAKERNEL_STORABLECONVERSIONS_H
8# define ATHENAKERNEL_STORABLECONVERSIONS_H
13
17#include "GaudiKernel/DataObject.h"
18
19#include <memory>
20#include <type_traits>
21#include <typeinfo>
22
23
24namespace SG {
25
26 // put a dobj pointer in a bucket as appropriate
27 template <typename T>
28 DataObject* asStorable(T* pObject);
29
30 // get a dobj pointer from a bucket as appropriate
31 template <typename T>
32 bool fromStorable(DataObject* pDObj, T*& pTrans, bool quiet=false,
33 IRegisterTransient* irt = 0,
34 bool isConst = true);
35
36 template <typename T>
37 T* Storable_cast(DataObject* pDObj, bool quiet=true,
38 IRegisterTransient* irt = 0,
39 bool isConst = true) {
40 T* result;
41 return fromStorable(pDObj, result, quiet, irt, isConst) ? result : 0;
42 }
43
44
58 void* fromStorable(DataObject* pDObj, CLID clid,
59 const std::type_info* tinfo = nullptr,
60 bool quiet = false,
61 IRegisterTransient* irt = 0,
62 bool isConst = true);
63
64
78 void* Storable_cast(DataObject* pDObj, CLID clid,
79 const std::type_info* tinfo = nullptr,
80 bool quiet = false,
81 IRegisterTransient* irt = 0,
82 bool isConst = true);
83}
84
86// implementation details
87
88
89namespace SG {
90
91
128 template <class T, class U /* = T*/>
130 {
131 // The first base of @c T (or @c SG::NoBase).
133
134 // Test to see if it's valid.
135 static constexpr bool has_base = std::is_same_v<base1, SG::NoBase>;
136
137 // This is what we'll return in the default (no base) case.
138 using deflt = std::type_identity<SG::DataBucket<U> >;
139
140 // This is what we use to recursively check the base
142
143 // Calculate the output.
144 using type = typename std::conditional_t<has_base, deflt, recurse>::type;
145
147 static void init() {}
148 };
149
150
151 // put a dobj pointer in a bucket as appropriate
152 template <typename T>
153 DataObject* asStorable(T* pObject) {
154 typedef typename DataBucketTrait<T>::type bucket_t;
155 return new bucket_t (pObject);
156 }
157
158 template <typename T>
159 DataObject* asStorable(std::unique_ptr<T> pObject) {
160 typedef typename std::remove_const<T>::type T_nc;
161 typedef typename DataBucketTrait<T_nc>::type bucket_t;
162 return new bucket_t (std::move(pObject));
163 }
164
165 // get a dobj pointer from a bucket as appropriate
166 //the DataObject must be a DataBucket<DATA>*.
167
168 template <typename T>
169 bool fromStorable(DataObject* pDObj, T*& pTrans,
170 bool quiet,
172 bool isConst /*= true*/)
173 {
174 typedef typename std::remove_const<T>::type T_nc;
176
177 pTrans = static_cast<T*> (fromStorable (pDObj, ClassID_traits<T_nc>::ID(),
178 &typeid(T_nc),
179 quiet, irt, isConst));
180 return pTrans != nullptr;
181}
182
183}
184
185#endif // ATHENAKERNEL_STORABLECONVERSIONS_H
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
uint32_t CLID
The Class ID type.
Interface for registering a transient object in t2p map.
Forward declaration.
T * Storable_cast(DataObject *pDObj, bool quiet=true, IRegisterTransient *irt=0, bool isConst=true)
typename SG::BaseType< T >::type BaseType_t
Definition Bases.h:62
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
unsigned long long T
Metafunction to find the proper DataBucket class for T.
static void init()
Initialization hook. A no-op by default.
SG::BaseType_t< typename SG::Bases< T >::bases::Base1 > base1
typename std::conditional_t< has_base, deflt, recurse >::type type
std::type_identity< SG::DataBucket< U > > deflt
DataBucketTrait< base1, U > recurse