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).
| 131 | /// File-private so the constructor can populate `*this` without going through |
| 132 | /// the get_library() singleton (which would recurse into its own constructor). |
| 133 | void 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 | |
| 149 | CubicsLibraryClass::CubicsLibraryClass() : empty(true) { |
no test coverage detected