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

Method getExternalFile

src/model/ExternalFile.cpp:188–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186 } // namespace detail
187
188 boost::optional<ExternalFile> ExternalFile::getExternalFile(const Model& model, const std::string& filename, bool copyFile) {
189 path p = toPath(filename);
190 if (!p.has_filename()) {
191 return boost::none;
192 }
193 std::string s;
194 if (copyFile) {
195 s = toString(p.filename());
196 } else {
197 s = filename;
198 }
199
200 // this factory method will give us better control if we start doing things like copying files
201 for (const auto& externalFile : model.getConcreteModelObjects<ExternalFile>()) {
202
203 // handle Windows filename case insensitivity?
204 if (externalFile.fileName() == s) {
205 return externalFile;
206 }
207 }
208
209 try {
210 return ExternalFile(model, filename, copyFile);
211 } catch (std::exception&) {
212 }
213 return boost::none;
214 }
215
216 ExternalFile::ExternalFile(const Model& model, const std::string& filename, bool copyFile) : ResourceObject(ExternalFile::iddObjectType(), model) {
217 OS_ASSERT(getImpl<detail::ExternalFile_Impl>());

Callers 2

runMethod · 0.80
runMethod · 0.80

Calls 5

filenameMethod · 0.80
ExternalFileFunction · 0.70
toPathFunction · 0.50
toStringFunction · 0.50
fileNameMethod · 0.45

Tested by

no test coverage detected