ATLAS Offline Software
Loading...
Searching...
No Matches
DataProxy_cast.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 */
13
14
15#ifndef SGTOOLS_DATAPROXY_CAST_H
16#define SGTOOLS_DATAPROXY_CAST_H
17
18
20#include "SGTools/exceptions.h"
21#include <typeinfo>
22
23
24namespace SG {
25
26
27class DataProxy;
28
29
31
32 template<typename DATA>
33 DATA* DataProxy_cast(DataProxy* proxy);
34
36 template<typename DATA>
37 DATA DataProxy_cast(const DataProxy& proxy);
38
48 void* DataProxy_cast(DataProxy* proxy, CLID clid, const std::type_info* tinfo = nullptr);
50
51
52template <typename DATA>
54 typedef typename std::remove_const<DATA>::type DATA_nc;
56
57 return static_cast<DATA*>(DataProxy_cast (proxy, ClassID_traits<DATA>::ID(),
58 &typeid(DATA_nc)));
59}
60
61
63template<typename DATA>
64DATA DataProxy_cast(const SG::DataProxy& proxy)
65{
66 const DATA* result = SG::DataProxy_cast<DATA>(&proxy);
67 if (!result) SG::throwExcBadDataProxyCast(proxy, typeid(DATA));
68 return *result;
69}
70
71
72} // namespace SG
73
74
75#endif // not SGTOOLS_DATAPROXY_CAST_H
Exceptions that can be thrown by SGTools.
uint32_t CLID
The Class ID type.
convert to and from a SG storable
Forward declaration.
void throwExcBadDataProxyCast(const DataProxy &proxy, const std::type_info &tid)
Throw an ExcBadDataProxyCast exception.
DATA * DataProxy_cast(DataProxy *proxy)
cast the proxy into the concrete data object it proxies
static void init()
Initialization hook. A no-op by default.