-
Notifications
You must be signed in to change notification settings - Fork 31
/
AssertIO.json.cc
69 lines (64 loc) · 1.79 KB
/
AssertIO.json.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//----------------------------------*-C++-*----------------------------------//
// Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file corecel/AssertIO.json.cc
//---------------------------------------------------------------------------//
#include "AssertIO.json.hh"
#include "io/JsonPimpl.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Write details of a debug error to JSON output.
*/
void to_json(nlohmann::json& j, DebugErrorDetails const& d)
{
j["which"] = to_cstring(d.which);
if (d.condition)
{
j["condition"] = d.condition;
}
if (d.file && d.file[0] != '\0')
{
j["file"] = d.file;
}
if (d.line != 0)
{
j["line"] = d.line;
}
}
//---------------------------------------------------------------------------//
/*!
* Write details of a runtime error to JSON output.
*/
void to_json(nlohmann::json& j, RuntimeErrorDetails const& d)
{
j["what"] = d.what;
j["which"] = d.which;
if (!d.condition.empty())
{
j["condition"] = d.condition;
}
if (!d.file.empty())
{
j["file"] = d.file;
}
if (d.line != 0)
{
j["line"] = d.line;
}
}
//---------------------------------------------------------------------------//
/*!
* Write properties of a rich context exception.
*/
void to_json(nlohmann::json& j, RichContextException const& e)
{
JsonPimpl temp{std::move(j)};
e.output(&temp);
j = std::move(temp.obj);
}
//---------------------------------------------------------------------------//
} // namespace celeritas