version 3.8
precision.hh
Go to the documentation of this file.
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//
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
19namespace Dumux::Vtk {
20
21using Dune::VTK::Precision;
22
27inline 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 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 for (const auto& [name, precision] : nameToPrecision)
41 if (name == precisionName)
42 return precision;
43
44 DUNE_THROW(Dune::InvalidStateException, "Unknown precision type " << precisionName);
45}
46
47} // end namespace Dumux::Vtk
48
49#endif
Precision stringToPrecision(std::string_view precisionName)
Maps a string (e.g. from input) to a Dune precision type.
Definition: precision.hh:27
Definition: fieldtype.hh:15