28 #include "itksys/SystemTools.hxx"
36 for (
auto &elem : m_ServiceObjects)
38 elem.second.UngetService(elem.first);
46 mitkThrow() <<
"FileReaderRegistry::GetMimeTypeForFile was called with empty path. Returning empty MimeType, "
47 "please report this error to the developers.";
52 if (mimeTypes.empty())
58 return mimeTypes.front();
63 const MimeType &mimeType, us::ModuleContext *context)
70 return context->GetServiceReferences<
IFileReader>(filter);
74 us::ModuleContext *context)
81 m_ServiceObjects.insert(std::make_pair(reader, serviceObjects));
86 us::ModuleContext *context)
91 std::vector<mitk::IFileReader *> result;
96 std::vector<us::ServiceReference<IFileReader>> refs = GetReferences(mimeType, context);
97 std::sort(refs.begin(), refs.end());
99 result.reserve(refs.size());
108 m_ServiceObjects.insert(std::make_pair(reader, serviceObjects));
109 result.push_back(reader);
117 std::map<mitk::IFileReader *, us::ServiceObjects<mitk::IFileReader>>::iterator readerIter =
118 m_ServiceObjects.find(reader);
119 if (readerIter != m_ServiceObjects.end())
121 readerIter->second.UngetService(reader);
122 m_ServiceObjects.erase(readerIter);
128 for (
const auto &reader : readers)
130 this->UngetReader(reader);
static IMimeTypeProvider * GetMimeTypeProvider(us::ModuleContext *context=us::GetModuleContext())
Get an IMimeTypeProvider instance.
mitk::IFileReader * GetReader(const ReaderReference &ref, us::ModuleContext *context=us::GetModuleContext())
std::vector< mitk::IFileReader * > GetReaders(const MimeType &mimeType, us::ModuleContext *context=us::GetModuleContext())
static MimeType GetMimeTypeForFile(const std::string &path, us::ModuleContext *context=us::GetModuleContext())
Get the highest ranked mime-type for the given file name.
static std::string PROP_MIMETYPE()
Service property name for the mime-type associated with this file writer.
std::string GetName() const
US_Core_EXPORT const std::string & OBJECTCLASS()
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
void UngetReaders(const std::vector< mitk::IFileReader * > &readers)
A RAII helper class for core service objects.
static std::vector< ReaderReference > GetReferences(const MimeType &mimeType, us::ModuleContext *context=us::GetModuleContext())
The common interface for all MITK file readers.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
virtual std::vector< MimeType > GetMimeTypesForFile(const std::string &filePath) const =0
void UngetReader(mitk::IFileReader *reader)