GCC Code Coverage Report


Directory: gridformat/
File: gridformat/common/scalar_field.hpp
Date: 2024-11-20 14:41:59
Exec Total Coverage
Lines: 8 8 100.0%
Functions: 15 15 100.0%
Branches: 2 4 50.0%

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 58 explicit ScalarField(T value, const Precision<ValueType> = {})
28 58 : _value{std::move(value)}
29 58 {}
30
31 private:
32
1/2
✓ Branch 1 taken 101 times.
✗ Branch 2 not taken.
108 MDLayout _layout() const { return MDLayout{{1}}; }
33 154 DynamicPrecision _precision() const { return {Precision<ValueType>{}}; }
34
1/2
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
57 Serialization _serialized() const { return Serialization::from_scalar(_get_value()); }
35
36 51 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