ATLAS Offline Software
Loading...
Searching...
No Matches
DVLInfo.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*/
11
12
13#ifndef ATHCONTAINERS_TOOLS_DVLINFO_H
14#define ATHCONTAINERS_TOOLS_DVLINFO_H
15
16
19#include <typeinfo>
20#include <cstddef>
21#include <type_traits>
22
23
24
25namespace DataModel_detail {
26
27
32{
33public:
35 virtual ~DVLIteratorBase() {}
36
37
46 virtual const void* next() = 0;
47};
48
49
50/*
51 * @brief Holder to implement conversion copies for @c DataVector/@c DataList.
52 *
53 * In some cases, we want to convert @c DataVector<A> to @c DataVector<B>,
54 * where the two @c DataVector classes are not related by inheritance,
55 * but where @c A and @c B are. In such a case, we can make a new view
56 * container for @c DataVector<B> and fill it with the pointers
57 * from @c DataVector<A> (suitably converted). In order for this
58 * to work with the conversion machinery in SGTools, we must be able
59 * to do this given only the @c type_info for @c DataVector<B>.
60 * Thus, we build a registry of @c DVLInfo objects, indexed
61 * by the @c type_info; the @c DVLInfo objects have virtual methods
62 * to build the new container and to fill it. (Everything said here
63 * for @c DataVector also applies to @c DataList.)
64 *
65 * Note: these objects should only be allocated statically.
66 */
68{
69public:
78 DVLInfoBase (const std::type_info& tinfo,
79 const std::type_info& elt_tinfo);
80
81
83 virtual ~DVLInfoBase() {}
84
85
89 const std::type_info& tinfo() const;
90
91
95 CLID clid() const;
96
97
102 const std::type_info& elt_tinfo() const;
103
104
110 virtual void* make (size_t nreserve) const = 0;
111
112
119 virtual void push (void* cont_p, void* elt_p) const = 0;
120
121
126 virtual size_t size (void* cont_p) const = 0;
127
128
133 virtual void clear (void* cont_p) const = 0;
134
135
140 virtual void del (void* cont_p) const = 0;
141
142
147 virtual void* clone (void* cont_p) const = 0;
148
149
154 virtual DVLIteratorBase* iterator (const void* cont_p) const = 0;
155
156
161 virtual SG::AuxVectorBase* base (void* cont_p) const = 0;
162
163
169 static DVLInfoBase* find (const std::type_info& tinfo);
170
171
177 static DVLInfoBase* find (CLID clid);
178
179
180private:
182 const std::type_info& m_tinfo;
183
185 const std::type_info& m_elt_tinfo;
186};
187
188
195template <class T>
197 : public DVLIteratorBase
198{
199public:
200 typedef typename T::const_iterator base_iterator;
201
202
208 DVLIterator (const base_iterator& beg, const base_iterator& end);
209
210
219 virtual const void* next() override;
220
221
222private:
223 typename T::const_iterator m_it;
224 typename T::const_iterator m_end;
225};
226
227
228/*
229 * @brief Per-container @c DVLInfo.
230 *
231 * One instance of this class is instantiated for each
232 * @c DataVector/@c DataList class.
233 */
234template <class T>
236 : public DVLInfoBase
237{
238public:
240 typedef T Container;
241
243 typedef typename std::remove_const<typename Container::base_value_type>::type Elt;
244
245
252
253
259 virtual void* make (size_t nreserve) const override;
260
261
268 virtual void push (void* cont_p, void* elt_p) const override;
269
270
275 virtual size_t size (void* cont_p) const override;
276
277
282 virtual void clear (void* cont_p) const override;
283
284
289 virtual void del (void* cont_p) const override;
290
291
296 virtual void* clone (void* cont_p) const override;
297
298
303 virtual DVLIteratorBase* iterator (const void* cont_p) const override;
304
305
310 virtual SG::AuxVectorBase* base (void* cont_p) const override;
311
312
320 static const std::type_info* initHelper();
321};
322
323
334template <class T>
335void* dvl_convert (const T& src,
336 const DVLInfoBase& targ_info);
337
338
350template <class T>
351void* dvl_convert (const T& src,
352 const std::type_info& targ_tinfo,
353 DVLInfoBase*& targ_info);
354
355
367template <class T>
368void* dvl_convert (const T& src,
369 CLID clid,
370 DVLInfoBase*& targ_info);
371
372
382template <class T>
383void dvl_update (const T& src,
384 void* target,
385 const DVLInfoBase* targ_info);
386
387
388
389} // namespace DataModel_detail
390
391
393
394
395#endif // not ATHCONTAINERS_TOOLS_DVLINFO_H
Manage index tracking and synchronization of auxiliary data.
Standalone helpers.
uint32_t CLID
The Class ID type.
static DVLInfoBase * find(const std::type_info &tinfo)
Find the DVLInfo for the container tinfo.
Definition DVLInfo.cxx:76
virtual void * make(size_t nreserve) const =0
Construct a new container.
virtual void clear(void *cont_p) const =0
Erase the elements in the container.
virtual void * clone(void *cont_p) const =0
Copy a container.
virtual void push(void *cont_p, void *elt_p) const =0
Push a new pointer into the container.
virtual void del(void *cont_p) const =0
Delete a container.
const std::type_info & elt_tinfo() const
Return the type_info for the container's element.
virtual SG::AuxVectorBase * base(void *cont_p) const =0
Return a pointer to the container base.
CLID clid() const
Return the CLID for the container.
Definition DVLInfo.cxx:117
const std::type_info & m_elt_tinfo
The type_info of the container's element.
Definition DVLInfo.h:185
const std::type_info & tinfo() const
Return the type_info for the container.
virtual ~DVLInfoBase()
Destructor.
Definition DVLInfo.h:83
virtual DVLIteratorBase * iterator(const void *cont_p) const =0
Return a new iterator object.
const std::type_info & m_tinfo
The type_info of the container.
Definition DVLInfo.h:182
virtual size_t size(void *cont_p) const =0
Return the size of the container.
DVLInfoBase(const std::type_info &tinfo, const std::type_info &elt_tinfo)
Constructor.
Definition DVLInfo.cxx:59
static const std::type_info * initHelper()
Helper to create the DVLInfo static instance.
virtual DVLIteratorBase * iterator(const void *cont_p) const override
Return a new iterator object.
virtual void del(void *cont_p) const override
Delete a container.
virtual SG::AuxVectorBase * base(void *cont_p) const override
Return a pointer to the container base.
virtual void * make(size_t nreserve) const override
Construct a new container.
virtual void push(void *cont_p, void *elt_p) const override
Push a new pointer into the container.
virtual void * clone(void *cont_p) const override
Copy a container.
T Container
Container type.
Definition DVLInfo.h:240
std::remove_const< typenameContainer::base_value_type >::type Elt
The container's element type (with pointer and any const removed).
Definition DVLInfo.h:243
virtual void clear(void *cont_p) const override
Erase the elements in the container.
virtual size_t size(void *cont_p) const override
Return the size of the container.
Helper to iterate over a DV container.
Definition DVLInfo.h:32
virtual ~DVLIteratorBase()
Destructor.
Definition DVLInfo.h:35
virtual const void * next()=0
Return the next element from the container.
DVLIterator(const base_iterator &beg, const base_iterator &end)
Constructor.
T::const_iterator m_end
Definition DVLInfo.h:224
T::const_iterator m_it
Definition DVLInfo.h:223
T::const_iterator base_iterator
Definition DVLInfo.h:200
virtual const void * next() override
Return the next element from the container.
Manage index tracking and synchronization of auxiliary data.
void * dvl_convert(const T &src, const DVLInfoBase &targ_info)
Perform DataVector/DataList conversion copying.
void dvl_update(const T &src, void *target, const DVLInfoBase *targ_info)
Update the elements in the target container from the source.