MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / findFile

Method findFile

src/utilities/filetypes/WorkflowJSON.cpp:458–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

456 }
457
458 boost::optional<openstudio::path> WorkflowJSON_Impl::findFile(const openstudio::path& file) const {
459 // if absolute check if exists
460 if (file.is_absolute()) {
461 if (boost::filesystem::exists(file)) {
462 return file;
463 }
464
465 // absolute path does not exist
466 return boost::none;
467 }
468
469 for (const auto& path : absoluteFilePaths()) {
470 openstudio::path p = path / file;
471 if (boost::filesystem::exists(p) && boost::filesystem::is_regular_file(p)) {
472 return canonicalOrAbsolute(p);
473 }
474 }
475
476 // Extra check: if it starts with file://
477 std::string fileName = toString(file);
478 if (fileName.rfind("file://", 0) == 0) {
479 // We strip it, and try again
480 return findFile(toPath(fileName.substr(7)));
481
482 // if it starts with 'file:' (some test files - at least seb.osm - on OpenStudio-workflow-gem have that...)
483 // eg: 'file:files/USA_CO_Golden-NREL.724666_TMY3.epw'
484 } else if (fileName.rfind("file:", 0) == 0) {
485 // We strip it, and try again
486 return findFile(toPath(fileName.substr(5)));
487 }
488 return boost::none;
489 }
490
491 boost::optional<openstudio::path> WorkflowJSON_Impl::findFile(const std::string& fileName) const {
492 return findFile(toPath(fileName));

Callers 6

ExternalFileMethod · 0.80
TESTFunction · 0.80
getModelicaSetupFunction · 0.80
runInitializationMethod · 0.80

Calls 3

canonicalOrAbsoluteFunction · 0.85
toStringFunction · 0.50
toPathFunction · 0.50

Tested by 1

TESTFunction · 0.64