The Gaudi Framework  v30r3 (a5ef0a68)
AnyDataWrapper.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_ANYDATAWRAPPER_H
2 #define GAUDIKERNEL_ANYDATAWRAPPER_H
3 
4 // Include files
6 #include "boost/optional.hpp"
7 #include <cstddef>
8 #include <iterator>
9 
10 namespace details
11 {
12 #if __cplusplus < 201703L
13  template <typename C>
14  constexpr auto size( const C& c ) noexcept( noexcept( c.size() ) ) -> decltype( c.size() )
15  {
16  return c.size();
17  }
18 
19  template <typename T, std::size_t N>
20  constexpr auto size( const T ( &array )[N] ) noexcept
21  {
22  return N;
23  }
24 #else
25  using std::size;
26 #endif
27 
28  template <typename T, typename... Args>
29  constexpr auto size( const T&, Args&&... ) noexcept
30  {
31  static_assert( sizeof...( Args ) == 0, "No extra args please" );
32  return boost::none;
33  }
34 }
35 
36 // ugly hack to circumvent the usage of boost::any
38  // TODO: C++17: replace with 'std::optional<std::size_t>'
39  virtual boost::optional<std::size_t> size() const = 0;
40 };
41 
42 template <class T>
44 {
45 public:
46  AnyDataWrapper( T&& data ) : m_data( std::move( data ) ){};
47 
49  : AnyDataWrapperBase( std::move( other ) ), m_data( std::move( other.m_data ) ){};
50 
51  const T& getData() const { return m_data; }
52  T& getData() { return m_data; }
53 
54  boost::optional<std::size_t> size() const override
55  {
56  // TODO: C++17: add 'using std::size' and remove the first two implementations in details...
57  using details::size;
58  return size( m_data );
59  }
60 
61 private:
62  T m_data;
63 };
64 
65 #endif
constexpr auto size(const T &, Args &&...) noexcept
boost::optional< std::size_t > size() const override
STL namespace.
const T & getData() const
AnyDataWrapper(AnyDataWrapper &&other)
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
int N
Definition: IOTest.py:101
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
AnyDataWrapper(T &&data)
#define GAUDI_API
Definition: Kernel.h:104
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30