File indexing completed on 2026-01-07 10:02:04
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <string_view>
0010 #include <nlohmann/json.hpp>
0011
0012 #include "corecel/io/EnumStringMapper.hh"
0013 #include "corecel/io/Logger.hh"
0014
0015
0016
0017
0018
0019
0020
0021 #define CELER_JSON_LOAD_REQUIRED(OBJ, STRUCT, NAME) \
0022 OBJ.at(#NAME).get_to(STRUCT.NAME)
0023
0024
0025
0026
0027
0028
0029 #define CELER_JSON_LOAD_OPTION(OBJ, STRUCT, NAME) \
0030 do \
0031 { \
0032 if (auto iter = OBJ.find(#NAME); \
0033 iter != OBJ.end() && !iter->is_null()) \
0034 { \
0035 iter->get_to(STRUCT.NAME); \
0036 } \
0037 } while (0)
0038
0039
0040
0041
0042 #define CELER_JSON_LOAD_DEFAULT(OBJ, STRUCT, NAME, DEFAULT) \
0043 do \
0044 { \
0045 if (auto iter = OBJ.find(#NAME); \
0046 iter != OBJ.end() && !iter->is_null()) \
0047 { \
0048 iter->get_to(STRUCT.NAME); \
0049 } \
0050 else \
0051 { \
0052 STRUCT.NAME = DEFAULT; \
0053 CELER_LOG(debug) << "Set '" << #NAME << "' to " << STRUCT.NAME; \
0054 } \
0055 } while (0)
0056
0057
0058
0059
0060
0061
0062 #define CELER_JSON_LOAD_DEPRECATED(OBJ, STRUCT, OLD, NEW) \
0063 do \
0064 { \
0065 if (auto iter = OBJ.find(#OLD); iter != OBJ.end()) \
0066 { \
0067 ::celeritas::warn_deprecated_json_option(#OLD, #NEW); \
0068 iter->get_to(STRUCT.NEW); \
0069 } \
0070 } while (0)
0071
0072
0073
0074
0075 #define CELER_JSON_SAVE(OBJ, STRUCT, NAME) OBJ[#NAME] = STRUCT.NAME
0076
0077
0078
0079
0080
0081
0082 #define CELER_JSON_SAVE_WHEN(OBJ, STRUCT, NAME, COND) \
0083 do \
0084 { \
0085 if ((COND)) \
0086 { \
0087 CELER_JSON_SAVE(OBJ, STRUCT, NAME); \
0088 } \
0089 else \
0090 { \
0091 OBJ[#NAME] = nullptr; \
0092 } \
0093 } while (0)
0094
0095
0096
0097
0098 #define CELER_JSON_PAIR(STRUCT, NAME) {#NAME, STRUCT.NAME}
0099
0100
0101
0102 namespace celeritas
0103 {
0104
0105
0106 void warn_deprecated_json_option(char const* old_name, char const* new_name);
0107
0108
0109 void save_format(nlohmann::json& j, std::string const& format);
0110
0111
0112 void save_units(nlohmann::json& j);
0113
0114
0115 void check_format(nlohmann::json const& j, std::string_view format);
0116
0117
0118 void check_units(nlohmann::json const& j, std::string_view format);
0119
0120
0121 }