| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de> | ||
| 2 | // SPDX-License-Identifier: MIT | ||
| 3 | /*! | ||
| 4 | * \file | ||
| 5 | * \ingroup Common | ||
| 6 | * \copydoc GridFormat::ScalarField | ||
| 7 | */ | ||
| 8 | #ifndef GRIDFORMAT_COMMON_SCALAR_FIELD_HPP_ | ||
| 9 | #define GRIDFORMAT_COMMON_SCALAR_FIELD_HPP_ | ||
| 10 | |||
| 11 | #include <utility> | ||
| 12 | #include <type_traits> | ||
| 13 | |||
| 14 | #include <gridformat/common/field.hpp> | ||
| 15 | #include <gridformat/common/md_layout.hpp> | ||
| 16 | #include <gridformat/common/precision.hpp> | ||
| 17 | #include <gridformat/common/serialization.hpp> | ||
| 18 | #include <gridformat/common/concepts.hpp> | ||
| 19 | |||
| 20 | namespace GridFormat { | ||
| 21 | |||
| 22 | template<Concepts::Scalar T, Concepts::Scalar ValueType = T> | ||
| 23 | class ScalarField : public Field { | ||
| 24 | static constexpr bool do_cast = !std::is_same_v<T, ValueType>; | ||
| 25 | |||
| 26 | public: | ||
| 27 | 62 | explicit ScalarField(T value, const Precision<ValueType> = {}) | |
| 28 | 62 | : _value{std::move(value)} | |
| 29 | 62 | {} | |
| 30 | |||
| 31 | private: | ||
| 32 |
1/2✓ Branch 1 taken 106 times.
✗ Branch 2 not taken.
|
118 | MDLayout _layout() const { return MDLayout{{1}}; } |
| 33 | 164 | DynamicPrecision _precision() const { return {Precision<ValueType>{}}; } | |
| 34 |
1/2✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
|
63 | Serialization _serialized() const { return Serialization::from_scalar(_get_value()); } |
| 35 | |||
| 36 | 61 | ValueType _get_value() const requires(!do_cast) { return _value; } | |
| 37 | 1 | ValueType _get_value() const requires(do_cast) { return static_cast<ValueType>(_value); } | |
| 38 | |||
| 39 | T _value; | ||
| 40 | }; | ||
| 41 | |||
| 42 | } // namespace GridFormat | ||
| 43 | |||
| 44 | #endif // GRIDFORMAT_COMMON_SCALAR_FIELD_HPP_ | ||
| 45 |