GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/io/vtk/precision.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 5 6 83.3%
Functions: 1 1 100.0%
Branches: 4 24 16.7%

Line Branch Exec Source
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 //
4 // SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 /*!
8 * \file
9 * \ingroup InputOutput
10 * \brief Vtk output precision options available in Dumux
11 */
12 #ifndef DUMUX_IO_VTK_PRECISION_HH
13 #define DUMUX_IO_VTK_PRECISION_HH
14
15 #include <array>
16 #include <string_view>
17 #include <dune/grid/io/file/vtk/common.hh>
18
19 namespace Dumux::Vtk {
20
21 using Dune::VTK::Precision;
22
23 /*!
24 * \ingroup InputOutput
25 * \brief Maps a string (e.g. from input) to a Dune precision type
26 */
27 1416 inline Precision stringToPrecision(std::string_view precisionName)
28 {
29 // this should really be constexpr but GCC <= 7.2 has a bug which
30 // doesn't allow string_view to be constexpr
31 1416 static const std::array<std::pair<std::string_view, Precision>, 5> nameToPrecision
32 {{
33 { "Float32", Precision::float32 },
34 { "Float64", Precision::float64 },
35 { "UInt32", Precision::uint32 },
36 { "UInt8", Precision::uint8 },
37 { "Int32", Precision::int32 },
38 }};
39
40
3/6
✓ Branch 0 taken 1421 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1421 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1421 times.
1421 for (const auto& [name, precision] : nameToPrecision)
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1421 times.
1426 if (name == precisionName)
42 1416 return precision;
43
44 DUNE_THROW(Dune::InvalidStateException, "Unknown precision type " << precisionName);
45 }
46
47 } // end namespace Dumux::Vtk
48
49 #endif
50