| The Gaudi Framework v32r1 (f65d50dc)

AnyDataWrapper.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_ANYDATAWRAPPER_H
2 #define GAUDIKERNEL_ANYDATAWRAPPER_H
3
4 // Include files
5 #include "GaudiKernel/DataObject.h"
6 #include <cstddef>
7 #include <iterator>
8 #include <optional>
9
10 namespace details {
11 using std::size;
12
13 template <typename T, typename... Args>
14 constexpr auto size( const T&, Args&&... ) noexcept {
15 static_assert( sizeof...( Args ) == 0, "No extra args please" );
16 return std::nullopt;
17 }
18 } // namespace details
19
20 // ugly hack to circumvent the usage of std::any
21 struct GAUDI_API AnyDataWrapperBase : DataObject {
22 virtual std::optional<std::size_t> size() const = 0;
23 };
24
25 template <class T>
26 class GAUDI_API AnyDataWrapper final : public AnyDataWrapperBase {
27 public:
28 AnyDataWrapper( T&& data ) : m_data( std::move( data ) ){};
29
30 AnyDataWrapper( AnyDataWrapper&& other )
31 : AnyDataWrapperBase( std::move( other ) ), m_data( std::move( other.m_data ) ){};
32
33 const T& getData() const { return m_data; }
34 T& getData() { return m_data; }
35
36 std::optional<std::size_t> size() const override {
37 using details::size;
38 return size( m_data );
39 }
40
41 private:
42 T m_data;
43 };
44
45 #endif
AnyDataWrapperBase
Definition: AnyDataWrapper.h:21
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:14
AnyDataWrapperBase::size
virtual std::optional< std::size_t > size() const =0
std
STL namespace.
AnyDataWrapper::AnyDataWrapper
AnyDataWrapper(AnyDataWrapper &&other)
Definition: AnyDataWrapper.h:30
AnyDataWrapper::getData
const T & getData() const
Definition: AnyDataWrapper.h:33
AnyDataWrapper
Definition: AnyDataWrapper.h:26
details
Definition: AnyDataWrapper.h:10
AnyDataWrapper::size
std::optional< std::size_t > size() const override
Definition: AnyDataWrapper.h:36
AnyDataWrapper::m_data
T m_data
Definition: AnyDataWrapper.h:42
AnyDataWrapper::AnyDataWrapper
AnyDataWrapper(T &&data)
Definition: AnyDataWrapper.h:28
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
AnyDataWrapper::getData
T & getData()
Definition: AnyDataWrapper.h:34
DataObject.h