The Gaudi Framework  v33r1 (b1225454)
AnyDataWrapper.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_ANYDATAWRAPPER_H
12 #define GAUDIKERNEL_ANYDATAWRAPPER_H
13 
14 // Include files
15 #include "GaudiKernel/DataObject.h"
16 #include <cstddef>
17 #include <iterator>
18 #include <optional>
19 
20 namespace details {
21  using std::size;
22 
23  template <typename T, typename... Args>
24  constexpr auto size( const T&, Args&&... ) noexcept {
25  static_assert( sizeof...( Args ) == 0, "No extra args please" );
26  return std::nullopt;
27  }
28 } // namespace details
29 
30 // ugly hack to circumvent the usage of std::any
32  virtual std::optional<std::size_t> size() const = 0;
33 };
34 
35 template <class T>
37 public:
38  AnyDataWrapper( T&& data ) : m_data( std::move( data ) ){};
39 
41  : AnyDataWrapperBase( std::move( other ) ), m_data( std::move( other.m_data ) ){};
42 
43  const T& getData() const { return m_data; }
44  T& getData() { return m_data; }
45 
46  std::optional<std::size_t> size() const override {
47  using details::size;
48  return size( m_data );
49  }
50 
51 private:
52  T m_data;
53 };
54 
55 #endif
constexpr auto size(const T &, Args &&...) noexcept
virtual std::optional< std::size_t > size() const =0
STL namespace.
AnyDataWrapper(AnyDataWrapper &&other)
const T & getData() const
std::optional< std::size_t > size() const override
AnyDataWrapper(T &&data)
#define GAUDI_API
Definition: Kernel.h:81
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:40