Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r7 (7f57a304)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 #pragma once
12 #include "GaudiKernel/DataObject.h"
13 #include <cstddef>
14 #include <iterator>
15 #include <optional>
16 #include <utility>
17 
18 namespace details {
19  using std::size;
20 
21  template <typename T, typename... Args>
22  constexpr auto size( const T&, Args&&... ) noexcept {
23  static_assert( sizeof...( Args ) == 0, "No extra args please" );
24  return std::nullopt;
25  }
26 } // namespace details
27 
28 // ugly hack to circumvent the usage of std::any
30  virtual std::optional<std::size_t> size() const = 0;
31 };
32 
33 template <typename T>
35 protected:
36  T m_data;
37 
38 public:
39  AnyDataWrapper( T&& data ) : m_data{ std::move( data ) } {};
41  AnyDataWrapper( AnyDataWrapper const& ) = delete;
44 
45  const T& getData() const { return m_data; }
46  T& getData() { return m_data; }
47 
48  std::optional<std::size_t> size() const override {
49  using details::size;
50  return size( getData() );
51  }
52 };
53 
54 template <typename ViewType, typename OwnedType>
56  OwnedType m_owned;
57 
58 public:
59  AnyDataWithViewWrapper( OwnedType&& data ) : AnyDataWrapper<ViewType>{ {} }, m_owned{ std::move( data ) } {
60  AnyDataWrapper<ViewType>::m_data = ViewType{ std::as_const( m_owned ) };
61  }
66 };
AnyDataWithViewWrapper::m_owned
OwnedType m_owned
Definition: AnyDataWrapper.h:56
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:22
std::move
T move(T... args)
AnyDataWrapper::operator=
AnyDataWrapper & operator=(AnyDataWrapper &&)=delete
AnyDataWrapper::getData
const T & getData() const
Definition: AnyDataWrapper.h:45
AnyDataWithViewWrapper::AnyDataWithViewWrapper
AnyDataWithViewWrapper(AnyDataWithViewWrapper &&)=delete
AnyDataWrapperBase
Definition: AnyDataWrapper.h:29
AnyDataWithViewWrapper::operator=
AnyDataWithViewWrapper & operator=(AnyDataWithViewWrapper &&)=delete
AnyDataWrapper::AnyDataWrapper
AnyDataWrapper(AnyDataWrapper &&)=delete
AnyDataWrapper::m_data
T m_data
Definition: AnyDataWrapper.h:36
details
Definition: AnyDataWrapper.h:18
AnyDataWrapper::size
std::optional< std::size_t > size() const override
Definition: AnyDataWrapper.h:48
AnyDataWrapper
Definition: AnyDataWrapper.h:34
AnyDataWrapper::operator=
AnyDataWrapper & operator=(AnyDataWrapper const &)=delete
AnyDataWithViewWrapper
Definition: AnyDataWrapper.h:55
AnyDataWrapper::AnyDataWrapper
AnyDataWrapper(AnyDataWrapper const &)=delete
DataObject.h
AnyDataWithViewWrapper::AnyDataWithViewWrapper
AnyDataWithViewWrapper(AnyDataWithViewWrapper const &)=delete
AnyDataWrapper::getData
T & getData()
Definition: AnyDataWrapper.h:46
DataObject
Definition: DataObject.h:40
AnyDataWithViewWrapper::operator=
AnyDataWithViewWrapper & operator=(AnyDataWithViewWrapper const &)=delete
AnyDataWithViewWrapper::AnyDataWithViewWrapper
AnyDataWithViewWrapper(OwnedType &&data)
Definition: AnyDataWrapper.h:59
AnyDataWrapper::AnyDataWrapper
AnyDataWrapper(T &&data)
Definition: AnyDataWrapper.h:39
AnyDataWrapperBase::size
virtual std::optional< std::size_t > size() const =0
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81