| 99 | } |
| 100 | |
| 101 | int PCSAFTLibraryClass::add_many(const nlohmann::json& listing) { |
| 102 | int counter = 0; |
| 103 | std::string fluid_name; |
| 104 | for (const auto& fluid_json : listing) { |
| 105 | try { |
| 106 | PCSAFTFluid fluid = cpjson::make_pcsaft_fluid(fluid_json); |
| 107 | fluid_name = fluid.getName(); |
| 108 | |
| 109 | // If the fluid is ok... |
| 110 | |
| 111 | // First check that none of the identifiers are already present |
| 112 | bool already_present = false; |
| 113 | |
| 114 | if (string_to_index_map.find(fluid.getCAS()) != string_to_index_map.end() |
| 115 | || string_to_index_map.find(fluid_name) != string_to_index_map.end() |
| 116 | || string_to_index_map.find(upper(fluid_name)) != string_to_index_map.end()) { |
| 117 | already_present = true; |
| 118 | } else { |
| 119 | // Check the aliases |
| 120 | for (std::size_t i = 0; i < fluid.getAliases().size(); ++i) { |
| 121 | if (string_to_index_map.find(fluid.getAliases()[i]) != string_to_index_map.end()) { |
| 122 | already_present = true; |
| 123 | break; |
| 124 | } |
| 125 | if (string_to_index_map.find(upper(fluid.getAliases()[i])) != string_to_index_map.end()) { |
| 126 | already_present = true; |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | if (already_present) { |
| 133 | if (!get_config_bool(OVERWRITE_FLUIDS)) { |
| 134 | throw ValueError(format( |
| 135 | "Cannot load fluid [%s:%s] because it is already in library; consider enabling the config boolean variable OVERWRITE_FLUIDS", |
| 136 | fluid.getName().c_str(), fluid.getCAS().c_str())); |
| 137 | } else { |
| 138 | // Remove the one(s) that are already there |
| 139 | |
| 140 | // Remove the actual fluid instance |
| 141 | std::size_t index = string_to_index_map.find(fluid_name)->second; |
| 142 | |
| 143 | if (fluid_map.find(index) != fluid_map.end()) { |
| 144 | fluid_map.erase(fluid_map.find(index)); |
| 145 | } |
| 146 | |
| 147 | if (string_to_index_map.find(fluid_name) != string_to_index_map.end()) { |
| 148 | fluid_map.erase(fluid_map.find(index)); |
| 149 | } |
| 150 | |
| 151 | // Remove the identifiers pointing to that instance |
| 152 | if (string_to_index_map.find(fluid.getCAS()) != string_to_index_map.end()) { |
| 153 | string_to_index_map.erase(string_to_index_map.find(fluid.getCAS())); |
| 154 | } |
| 155 | if (string_to_index_map.find(fluid_name) != string_to_index_map.end()) { |
| 156 | string_to_index_map.erase(string_to_index_map.find(fluid_name)); |
| 157 | } |
| 158 | // Check the aliases |
no test coverage detected