ATLAS Offline Software
Loading...
Searching...
No Matches
DataBucket.h
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef ATHENAKERNEL_DATABUCKET_H
8#define ATHENAKERNEL_DATABUCKET_H
9
11
12//FIXME CLID is a tdef and can't be forward declared
13#include "GaudiKernel/ClassID.h"
14#include <memory>
15#include <type_traits>
16
23
24namespace SG {
25 class IRegisterTransient;
26 class CopyConversionBase;
27
28 template <class T>
29 class DataBucket : public DataBucketBase {
30
31 public:
32
33 // CONSTRUCTORS:
34
35 DataBucket(): m_ptr(0) {} //needed by the generic converters
37 template <class U>
38 DataBucket(std::unique_ptr<U> data);
39
40 // DESTRUCTOR:
41
42 virtual ~DataBucket();
43
44 // DATAOBJECT METHODS
45 virtual const CLID& clID() const override;
46 static const CLID& classID();
47
48 // return the pointer as a void*
49 virtual void* object() override
50 {
51 typedef typename std::remove_const<T>::type T_nc;
52 return const_cast<T_nc*>(m_ptr);
53 }
54
58 virtual const std::type_info& tinfo() const override
59 {
60 return typeid(T);
61 }
62
63 // Serialize the object for reading
64 // StreamBuffer& serialize(StreamBuffer& s);
65 // Serialize the object for writing
66 // StreamBuffer& serialize(StreamBuffer& s) const;
67
68
69
70 // AUTOMATIC CONVERSION OF TYPES
71 operator T*() { return ptr(); } //FIXME can we do without?
72 operator const T*() const { return cptr(); }
73
82 virtual void* cast (CLID clid,
83 IRegisterTransient* irt = 0,
84 bool isConst = true) override;
85
86
95 virtual void* cast (const std::type_info& tinfo,
96 IRegisterTransient* irt = 0,
97 bool isConst = true) override;
98
111 virtual void* cast (CLID clid,
112 const std::type_info& tinfo,
113 SG::IRegisterTransient* irt = 0,
114 bool isConst = true) override;
115
116
121 virtual void relinquish() override{ m_ptr=0;} //LEAKS m_ptr
122
126 virtual void lock() override;
127
128
129 protected:
130 T* ptr() { return m_ptr; }
131 const T* cptr() const { return m_ptr; }
132
133
142
143
151 void* tryStaticConversion (const std::type_info& tinfo);
152
153
154private:
155 T* m_ptr; //we own the thing now!
156
158 typedef std::pair<const CopyConversionBase*, void*> ent_t;
159 typedef std::vector<ent_t> vec_t;
161
164 };
165} //end namespace SG
167
168#endif // ATHENAKERNEL_DATABUCKET_H
uint32_t CLID
The Class ID type.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static const CLID & classID()
DataBucket(std::unique_ptr< U > data)
virtual void * cast(const std::type_info &tinfo, IRegisterTransient *irt=0, bool isConst=true) override
Return the contents of the DataBucket, converted to type given by std::type_info.
virtual const std::type_info & tinfo() const override
Return the type_info for the stored object.
Definition DataBucket.h:58
virtual void * cast(CLID clid, const std::type_info &tinfo, SG::IRegisterTransient *irt=0, bool isConst=true) override
Return the contents of the DataBucket, converted to type given by clid.
virtual void lock() override
If the held object derives from ILockable, call lock() on it.
virtual void * object() override
Definition DataBucket.h:49
void * tryStaticConversion(CLID clid)
Try a conversion using static SG_BASES information.
const T * cptr() const
Definition DataBucket.h:131
virtual const CLID & clID() const override
DataBucket(T *data)
void * tryStaticConversion(const std::type_info &tinfo)
Try a conversion using static SG_BASES information.
DataBucket & operator=(const DataBucket &)
std::vector< ent_t > vec_t
Definition DataBucket.h:159
virtual void * cast(CLID clid, IRegisterTransient *irt=0, bool isConst=true) override
Return the contents of the DataBucket, converted to type given by clid.
virtual void relinquish() override
Give up ownership of the DataBucket contents.
Definition DataBucket.h:121
DataBucket(const DataBucket &)
std::pair< const CopyConversionBase *, void * > ent_t
Objects made by copy conversion.
Definition DataBucket.h:158
virtual ~DataBucket()
Interface for registering a transient object in t2p map.
Forward declaration.