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