Gets the autosized component value from the sql file **/
| 288 | |
| 289 | /** Gets the autosized component value from the sql file **/ |
| 290 | boost::optional<double> ModelObject_Impl::getAutosizedValue(const std::string& valueName, const std::string& units, |
| 291 | std::string overrideCompType) const { |
| 292 | |
| 293 | // Get the object name |
| 294 | if (!name()) { |
| 295 | LOG(Warn, "This object does not have a name, cannot retrieve the autosized value '" + valueName + "'."); |
| 296 | return boost::none; |
| 297 | } |
| 298 | |
| 299 | // Check that the model has a sql file |
| 300 | if (!model().sqlFile()) { |
| 301 | LOG(Warn, "This model has no sql file, cannot retrieve the autosized value '" + valueName + "'."); |
| 302 | return boost::none; |
| 303 | } |
| 304 | |
| 305 | // Get the object name and transform to the way it is recorded |
| 306 | // in the sql file |
| 307 | std::string sqlName = name().get(); |
| 308 | boost::to_upper(sqlName); |
| 309 | |
| 310 | // Get the object type and transform to the way it is recorded in the sql file |
| 311 | if (overrideCompType.empty()) { |
| 312 | overrideCompType = iddObject().type().valueDescription(); |
| 313 | boost::replace_all(overrideCompType, "OS:", ""); |
| 314 | } |
| 315 | |
| 316 | const std::string directQuery = R"sql( |
| 317 | SELECT Value FROM ComponentSizes |
| 318 | WHERE CompType = ? |
| 319 | AND CompName = ? |
| 320 | AND Description = ? |
| 321 | AND Units = ?; |
| 322 | )sql"; |
| 323 | boost::optional<double> val = model().sqlFile().get().execAndReturnFirstDouble(directQuery, |
| 324 | // bindArgs |
| 325 | overrideCompType, sqlName, valueName, units); |
| 326 | if (!val) { |
| 327 | LOG(Debug, fmt::format(R"sql(The direct query failed: |
| 328 | SELECT Value FROM ComponentSizes |
| 329 | WHERE CompType = '{}' |
| 330 | AND CompName = '{}' |
| 331 | AND Description = '{}' |
| 332 | AND Units = '{}';)sql", |
| 333 | overrideCompType, sqlName, valueName, units)); |
| 334 | } |
| 335 | |
| 336 | return val; |
| 337 | } |
| 338 | |
| 339 | //void ModelObject_Impl::connect(unsigned outletPort, ModelObject target, unsigned inletPort) |
| 340 | //{ |
no test coverage detected