|
| 1 | +// This file is part of the ACTS project. |
| 2 | +// |
| 3 | +// Copyright (C) 2016 CERN for the benefit of the ACTS project |
| 4 | +// |
| 5 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 8 | + |
| 9 | +#pragma once |
| 10 | + |
| 11 | +#include <memory> |
| 12 | +#include <vector> |
| 13 | + |
| 14 | +namespace Acts::Experimental { |
| 15 | + |
| 16 | +class SpacePointContainer2; |
| 17 | +template <typename T> |
| 18 | +class SpacePointColumnProxy; |
| 19 | + |
| 20 | +namespace detail::sp { |
| 21 | + |
| 22 | +// These classes should have gone into `SpacePointContainer2` but a compiler bug |
| 23 | +// prevents that |
| 24 | + |
| 25 | +class ColumnHolderBase { |
| 26 | + public: |
| 27 | + virtual ~ColumnHolderBase() = default; |
| 28 | + |
| 29 | + virtual std::unique_ptr<ColumnHolderBase> copy() const = 0; |
| 30 | + |
| 31 | + virtual std::size_t size() const = 0; |
| 32 | + virtual void reserve(std::size_t size) = 0; |
| 33 | + virtual void resize(std::size_t size) = 0; |
| 34 | + virtual void clear() = 0; |
| 35 | + virtual void emplace_back() = 0; |
| 36 | +}; |
| 37 | + |
| 38 | +template <typename T> |
| 39 | +class ColumnHolder final : public ColumnHolderBase { |
| 40 | + public: |
| 41 | + using Value = T; |
| 42 | + using Container = std::vector<Value>; |
| 43 | + using Proxy = SpacePointColumnProxy<Value>; |
| 44 | + |
| 45 | + ColumnHolder() = default; |
| 46 | + explicit ColumnHolder(Value defaultValue) |
| 47 | + : m_default(std::move(defaultValue)) {} |
| 48 | + |
| 49 | + Proxy proxy(const SpacePointContainer2 &container) const { |
| 50 | + return Proxy(container, m_data); |
| 51 | + } |
| 52 | + |
| 53 | + std::unique_ptr<ColumnHolderBase> copy() const override { |
| 54 | + return std::make_unique<detail::sp::ColumnHolder<T>>(*this); |
| 55 | + } |
| 56 | + |
| 57 | + std::size_t size() const override { return m_data.size(); } |
| 58 | + void reserve(std::size_t size) override { m_data.reserve(size); } |
| 59 | + void clear() override { m_data.clear(); } |
| 60 | + void resize(std::size_t size) override { m_data.resize(size, m_default); } |
| 61 | + void emplace_back() override { m_data.emplace_back(m_default); } |
| 62 | + |
| 63 | + private: |
| 64 | + Value m_default{}; |
| 65 | + Container m_data; |
| 66 | +}; |
| 67 | + |
| 68 | +} // namespace detail::sp |
| 69 | +} // namespace Acts::Experimental |
0 commit comments