MCPcopy Create free account
hub / github.com/CoolProp/CoolProp / add_fluids_from_JSON_string

Function add_fluids_from_JSON_string

src/Backends/Cubics/CubicsLibrary.cpp:133–146  ·  view source on GitHub ↗

Schema-validate a JSON blob and merge it into the given library instance. File-private so the constructor can populate `*this` without going through the get_library() singleton (which would recurse into its own constructor).

Source from the content-addressed store, hash-verified

131/// File-private so the constructor can populate `*this` without going through
132/// the get_library() singleton (which would recurse into its own constructor).
133void add_fluids_from_JSON_string(CubicsLibraryClass& dest, const std::string_view& JSON) {
134 std::string errstr;
135 cpjson::schema_validation_code val_code = cpjson::validate_schema(cubic_fluids_schema_JSON, JSON, errstr);
136 if (val_code == cpjson::SCHEMA_VALIDATION_OK) {
137 nlohmann::json dd = cpjson::parse(JSON);
138 try {
139 dest.add_many(dd);
140 } catch (std::exception& e) {
141 throw ValueError(format("Unable to load cubics library with error: %s", e.what()));
142 }
143 } else {
144 throw ValueError(format("Unable to validate cubics library against schema with error: %s", errstr.c_str()));
145 }
146}
147} // anonymous namespace
148
149CubicsLibraryClass::CubicsLibraryClass() : empty(true) {

Callers 2

CubicsLibraryClassMethod · 0.70
add_fluids_as_JSONFunction · 0.70

Calls 5

validate_schemaFunction · 0.85
parseFunction · 0.85
whatMethod · 0.80
formatFunction · 0.50
add_manyMethod · 0.45

Tested by

no test coverage detected