File indexing completed on 2025-01-18 09:57:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #pragma once
0012 #include "GaudiKernel/DataObject.h"
0013 #include <cstddef>
0014 #include <iterator>
0015 #include <optional>
0016 #include <utility>
0017
0018 namespace details {
0019 using std::size;
0020
0021 template <typename T, typename... Args>
0022 constexpr auto size( const T&, Args&&... ) noexcept {
0023 static_assert( sizeof...( Args ) == 0, "No extra args please" );
0024 return std::nullopt;
0025 }
0026 }
0027
0028
0029 struct GAUDI_API AnyDataWrapperBase : DataObject {
0030 virtual std::optional<std::size_t> size() const = 0;
0031 };
0032
0033 template <typename T>
0034 class GAUDI_API AnyDataWrapper : public AnyDataWrapperBase {
0035 protected:
0036 T m_data;
0037
0038 public:
0039 AnyDataWrapper( T&& data ) : m_data{ std::move( data ) } {};
0040 AnyDataWrapper( AnyDataWrapper&& ) = delete;
0041 AnyDataWrapper( AnyDataWrapper const& ) = delete;
0042 AnyDataWrapper& operator=( AnyDataWrapper&& ) = delete;
0043 AnyDataWrapper& operator=( AnyDataWrapper const& ) = delete;
0044
0045 const T& getData() const { return m_data; }
0046 T& getData() { return m_data; }
0047
0048 std::optional<std::size_t> size() const override {
0049 using ::details::size;
0050 return size( getData() );
0051 }
0052 };
0053
0054 template <typename ViewType, typename OwnedType>
0055 class GAUDI_API AnyDataWithViewWrapper : public AnyDataWrapper<ViewType> {
0056 OwnedType m_owned;
0057
0058 public:
0059 AnyDataWithViewWrapper( OwnedType&& data ) : AnyDataWrapper<ViewType>{ {} }, m_owned{ std::move( data ) } {
0060 AnyDataWrapper<ViewType>::m_data = ViewType{ std::as_const( m_owned ) };
0061 }
0062 AnyDataWithViewWrapper( AnyDataWithViewWrapper&& ) = delete;
0063 AnyDataWithViewWrapper( AnyDataWithViewWrapper const& ) = delete;
0064 AnyDataWithViewWrapper& operator=( AnyDataWithViewWrapper&& ) = delete;
0065 AnyDataWithViewWrapper& operator=( AnyDataWithViewWrapper const& ) = delete;
0066 };