Line data Source code
1 : // SPDX-License-Identifier: BSD-3-Clause 2 : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 3 : /// @file 4 : /// @author Simon Heybrock 5 : #pragma once 6 : 7 : #include "scipp-variable_export.h" 8 : #include "scipp/common/index.h" 9 : #include "scipp/core/dimensions.h" 10 : #include "scipp/core/dtype.h" 11 : #include "scipp/units/unit.h" 12 : 13 : #include <memory> 14 : 15 : namespace scipp::variable { 16 : 17 : class Variable; 18 : class VariableConcept; 19 : 20 : using VariableConceptHandle = std::shared_ptr<VariableConcept>; 21 : 22 : /// Abstract base class for any data that can be held by Variable. This is using 23 : /// so-called concept-based polymorphism, see talks by Sean Parent. 24 : /// 25 : /// This is the most generic representation for a multi-dimensional array of 26 : /// data. There are currently the implementations of this interface: 27 : /// - ElementArrayModel for simple arrays of elements. 28 : /// - StructureArrayModel for arrays of structured elements, providing access to 29 : /// components of the structures as Variable. Currently used for 30 : /// Eigen::Vector3d and Eigen::Matrix3d. Could be used, e.g., also for 31 : /// supporting complex<double>. 32 : /// - BinArrayModel for "arrays" of bins, i.e., event data. 33 : class SCIPP_VARIABLE_EXPORT VariableConcept { 34 : public: 35 : VariableConcept(const units::Unit &unit); 36 2973931 : virtual ~VariableConcept() = default; 37 : 38 : virtual VariableConceptHandle clone() const = 0; 39 : virtual VariableConceptHandle 40 : makeDefaultFromParent(const scipp::index size) const = 0; 41 : virtual VariableConceptHandle 42 : makeDefaultFromParent(const Variable &shape) const = 0; 43 : 44 : virtual DType dtype() const noexcept = 0; 45 6318315 : virtual const units::Unit &unit() const { return m_unit; } 46 : virtual scipp::index size() const = 0; 47 : 48 855867 : virtual void setUnit(const units::Unit &unit) { m_unit = unit; } 49 : 50 : virtual bool has_variances() const noexcept = 0; 51 : virtual void setVariances(const Variable &variances) = 0; 52 : 53 : virtual bool equals(const Variable &a, const Variable &b) const = 0; 54 : virtual bool equals_nan(const Variable &a, const Variable &b) const = 0; 55 : virtual void copy(const Variable &src, Variable &dest) const = 0; 56 : virtual void copy(const Variable &src, Variable &&dest) const = 0; 57 : virtual void assign(const VariableConcept &other) = 0; 58 : virtual scipp::index dtype_size() const = 0; 59 : virtual scipp::index object_size() const = 0; 60 : 61 : virtual const VariableConceptHandle &bin_indices() const = 0; 62 : 63 : friend class Variable; 64 : 65 : private: 66 : units::Unit m_unit; 67 : }; 68 : 69 : } // namespace scipp::variable