13namespace CubicLibrary {
18 std::map<std::string, CubicsValues> fluid_map;
19 std::map<std::string, std::string> aliases_map;
21 std::map<std::string, std::string> JSONstring_map;
31 for (
const auto& el : listing) {
40 if (el.contains(
"rhomolarc") && el.at(
"rhomolarc").is_number()) {
43 if (el.contains(
"alpha") && el.at(
"alpha").is_object()) {
44 const nlohmann::json& alpha = el.at(
"alpha");
50 if (el.contains(
"alpha0") && el.at(
"alpha0").is_array()) {
53 std::pair<std::map<std::string, CubicsValues>::iterator,
bool> ret;
54 ret = fluid_map.emplace(
upper(val.
name), val);
56 fluid_map.erase(ret.first);
57 ret = fluid_map.emplace(
upper(val.
name), val);
59 std::cout <<
"added the cubic fluid: " + val.
name <<
'\n';
61 assert(ret.second ==
true);
63 for (
auto it = val.
aliases.begin(); it != val.
aliases.end(); ++it) {
64 if (aliases_map.find(*it) == aliases_map.end()) {
65 aliases_map.emplace(*it,
upper(val.
name));
68 std::pair<std::map<std::string, std::string>::iterator,
bool> addJson;
69 addJson = JSONstring_map.emplace(
upper(val.
name), el.dump());
71 JSONstring_map.erase(addJson.first);
72 addJson = JSONstring_map.emplace(
upper(val.
name), el.dump());
74 std::cout <<
"added the cubic fluid: " + val.
name <<
'\n';
76 assert(addJson.second ==
true);
84 std::string uppercase_identifier =
upper(key);
86 auto it = JSONstring_map.find(uppercase_identifier);
88 if (it == JSONstring_map.end()) {
89 auto italias = aliases_map.find(uppercase_identifier);
90 if (italias != aliases_map.end()) {
92 it = JSONstring_map.find(italias->second);
94 throw ValueError(
format(
"Fluid identifier [%s] was not found in CubicsLibrary", uppercase_identifier.c_str()));
99 nlohmann::json doc2 = nlohmann::json::array();
105 std::string uppercase_identifier =
upper(identifier);
107 auto it = fluid_map.find(uppercase_identifier);
109 if (it != fluid_map.end()) {
112 auto italias = aliases_map.find(uppercase_identifier);
113 if (italias != aliases_map.end()) {
115 return fluid_map.find(italias->second)->second;
117 throw ValueError(
format(
"Fluid identifier [%s] was not found in CubicsLibrary", uppercase_identifier.c_str()));
122 std::vector<std::string> out;
123 for (
auto it = fluid_map.begin(); it != fluid_map.end(); ++it) {
124 out.push_back(it->first);
133void add_fluids_from_JSON_string(CubicsLibraryClass& dest,
const std::string_view&
JSON) {
140 }
catch (std::exception& e) {
141 throw ValueError(
format(
"Unable to load cubics library with error: %s", e.what()));
144 throw ValueError(
format(
"Unable to validate cubics library against schema with error: %s", errstr.c_str()));
152 add_fluids_from_JSON_string(*
this, all_cubics_JSON);
166 add_fluids_from_JSON_string(get_library(),
JSON);
173 return get_library().
get(identifier);
176 return cubic_fluids_schema_JSON;