| 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>()); |