https://mooseframework.inl.gov
JsonIO.h
Go to the documentation of this file.
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 {
55  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  if (v)
60  j = *v;
61  else
62  j = nullptr;
63  }
64  else
65  mooseAssert(false, "Should not get to this");
66  }
67 };
68 }
template class LIBMESH_EXPORT DenseVector< Real >
Base class for MOOSE-based applications.
Definition: MooseApp.h:85
void to_json(nlohmann::json &json, const Point &p)
Definition: JsonIO.C:50
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
static void to_json(json &j, const std::unique_ptr< T > &v)
Serializer that will output a unique ptr if it exists.
Definition: JsonIO.h:55
void to_json(nlohmann::json &json, const MooseApp &app)
Definition: JsonIO.C:22