File indexing completed on 2025-09-18 09:09:39
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <string_view>
0010 #include <nlohmann/json.hpp>
0011
0012
0013
0014
0015
0016
0017
0018 #define CELER_JSON_LOAD_REQUIRED(OBJ, STRUCT, NAME) \
0019 OBJ.at(#NAME).get_to(STRUCT.NAME)
0020
0021
0022
0023
0024
0025
0026 #define CELER_JSON_LOAD_OPTION(OBJ, STRUCT, NAME) \
0027 do \
0028 { \
0029 if (auto iter = OBJ.find(#NAME); \
0030 iter != OBJ.end() && !iter->is_null()) \
0031 { \
0032 iter->get_to(STRUCT.NAME); \
0033 } \
0034 } while (0)
0035
0036
0037
0038
0039
0040
0041 #define CELER_JSON_LOAD_DEPRECATED(OBJ, STRUCT, OLD, NEW) \
0042 do \
0043 { \
0044 if (auto iter = OBJ.find(#OLD); iter != OBJ.end()) \
0045 { \
0046 ::celeritas::warn_deprecated_json_option(#OLD, #NEW); \
0047 iter->get_to(STRUCT.NEW); \
0048 } \
0049 } while (0)
0050
0051
0052
0053
0054 #define CELER_JSON_SAVE(OBJ, STRUCT, NAME) OBJ[#NAME] = STRUCT.NAME
0055
0056
0057
0058
0059
0060
0061 #define CELER_JSON_SAVE_WHEN(OBJ, STRUCT, NAME, COND) \
0062 do \
0063 { \
0064 if ((COND)) \
0065 { \
0066 CELER_JSON_SAVE(OBJ, STRUCT, NAME); \
0067 } \
0068 else \
0069 { \
0070 OBJ[#NAME] = nullptr; \
0071 } \
0072 } while (0)
0073
0074
0075
0076
0077 #define CELER_JSON_PAIR(STRUCT, NAME) {#NAME, STRUCT.NAME}
0078
0079
0080
0081 namespace celeritas
0082 {
0083
0084
0085 void warn_deprecated_json_option(char const* old_name, char const* new_name);
0086
0087
0088 void save_format(nlohmann::json& j, std::string const& format);
0089
0090
0091 void save_units(nlohmann::json& j);
0092
0093
0094 void check_format(nlohmann::json const& j, std::string_view format);
0095
0096
0097 void check_units(nlohmann::json const& j, std::string_view format);
0098
0099
0100 }