LCOV - code coverage report
Current view: top level - include/outputs - JsonIO.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 5 5 100.0 %
Date: 2025-07-17 01:28:37 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include "MooseError.h"
      13             : 
      14             : #include "nlohmann/json.h"
      15             : 
      16             : #include "libmesh/libmesh_common.h"
      17             : 
      18             : #include <memory>
      19             : 
      20             : class MooseApp;
      21             : 
      22             : namespace libMesh
      23             : {
      24             : class Point;
      25             : template <typename T>
      26             : class DenseVector;
      27             : template <typename T>
      28             : class DenseMatrix;
      29             : template <typename T>
      30             : class NumericVector;
      31             : }
      32             : 
      33             : // Overloads for to_json, which _must_ be overloaded in the namespace
      34             : // in which the object is found in order to enable argument-dependent lookup.
      35             : // See https://en.cppreference.com/w/cpp/language/adl for more information
      36             : void to_json(nlohmann::json & json, const MooseApp & app); // MooseDocs:to_json
      37             : 
      38             : namespace libMesh
      39             : {
      40             : void to_json(nlohmann::json & json, const Point & p);
      41             : void to_json(nlohmann::json & json, const DenseVector<Real> & vector);
      42             : void to_json(nlohmann::json & json, const DenseMatrix<Real> & matrix);
      43             : void to_json(nlohmann::json & json, const std::unique_ptr<NumericVector<Number>> & vector);
      44             : }
      45             : 
      46             : namespace nlohmann
      47             : {
      48             : template <typename T>
      49             : struct adl_serializer<std::unique_ptr<T>>
      50             : {
      51             :   /// Serializer that will output a unique ptr if it exists. We wrap this
      52             :   /// with is_constructible_v so that we don't specialize types that
      53             :   /// don't already have a specialization. This is required for some earlier
      54             :   /// compilers, even though we're not using it at the moment
      55           2 :   static void to_json(json & j, const std::unique_ptr<T> & v)
      56             :   {
      57             :     if constexpr (std::is_constructible_v<nlohmann::json, T>)
      58             :     {
      59           2 :       if (v)
      60           1 :         j = *v;
      61             :       else
      62           1 :         j = nullptr;
      63             :     }
      64             :     else
      65             :       mooseAssert(false, "Should not get to this");
      66           2 :   }
      67             : };
      68             : }

Generated by: LCOV version 1.14