GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/io/json.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 12 13 92.3%
Functions: 2 2 100.0%
Branches: 9 66 13.6%

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-FileCopyrightText: 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 Collection of json classes from JSON for Modern C++ library
11 */
12
13 #include <dune/common/fvector.hh>
14 #include <dune/common/exceptions.hh>
15
16 #include <dumux/io/json/json.hpp>
17
18 namespace Dumux::Json {
19 using JsonTree = nlohmann::json;
20 } // end namespace Dumux::Json
21
22 namespace nlohmann {
23
24 template <typename ctype, int k>
25 struct adl_serializer<Dune::FieldVector<ctype, k>>
26 {
27 1 static void to_json(json& j, const Dune::FieldVector<ctype, k>& fv)
28 {
29 1 j = json::array();
30
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < k; ++i) {
31
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
9 j.push_back(fv[i]);
32 }
33 1 }
34
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 static void from_json(const json& j, Dune::FieldVector<ctype, k>& fv)
36 {
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!j.is_array())
38
1/22
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
1 DUNE_THROW(Dune::IOError, "json: Cannot convert to FieldVector, not an array");
39
40
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (j.size() != k)
41 DUNE_THROW(Dune::IOError, "json: Cannot convert to FieldVector of size " << k << " from array of size " << j.size());
42
43
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < k; ++i)
44 3 fv[i] = j[i].template get<ctype>();
45 1 }
46 };
47
48 } // end namespace nlohmann
49