The Gaudi Framework  v30r1 (5d4f4ae2)
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 
9 namespace details
10 {
11  template <typename C>
12  constexpr auto size( const C& c ) noexcept( noexcept( c.size() ) ) -> decltype( c.size() )
13  {
14  return c.size();
15  }
16 
17  template <typename T, std::size_t N>
18  constexpr auto size( const T ( &array )[N] ) noexcept
19  {
20  return N;
21  }
22 
23  template <typename T, typename... Args>
24  constexpr auto size( const T&, Args&&... ) noexcept
25  {
26  static_assert( sizeof...( Args ) == 0, "No extra args please" );
27  return boost::none;
28  }
29 }
30 
31 // ugly hack to circumvent the usage of boost::any
33  // TODO: C++17: replace with 'std::optional<std::size_t>'
34  virtual boost::optional<std::size_t> size() const = 0;
35 };
36 
37 template <class T>
39 {
40 public:
41  AnyDataWrapper( T&& data ) : m_data( std::move( data ) ){};
42 
44  : AnyDataWrapperBase( std::move( other ) ), m_data( std::move( other.m_data ) ){};
45 
46  const T& getData() const { return m_data; }
47  T& getData() { return m_data; }
48 
49  boost::optional<std::size_t> size() const override
50  {
51  // TODO: C++17: add 'using std::size' and remove the first two implementations in details...
52  using details::size;
53  return size( m_data );
54  }
55 
56 private:
57  T m_data;
58 };
59 
60 #endif
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:110
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30