27 #include <itksys/SystemTools.hxx>
33 Impl() : m_FileReader(NULL), m_ConfidenceLevel(IFileReader::Unsupported), m_Id(-1) {}
35 IFileReader *m_FileReader;
43 Impl() : m_BestId(-1), m_SelectedId(m_BestId) {}
44 Impl(
const Impl &other) :
us::
SharedData(other), m_BestId(-1), m_SelectedId(m_BestId) {}
45 FileReaderRegistry m_ReaderRegistry;
46 std::map<long, FileReaderSelector::Item> m_Items;
47 std::vector<MimeType> m_MimeTypes;
55 if (!itksys::SystemTools::FileExists(path.c_str()))
65 if (m_Data->m_MimeTypes.empty())
68 for (std::vector<MimeType>::const_iterator mimeTypeIter = m_Data->m_MimeTypes.begin(),
69 mimeTypeIterEnd = m_Data->m_MimeTypes.end();
70 mimeTypeIter != mimeTypeIterEnd;
73 std::vector<FileReaderRegistry::ReaderReference> refs = m_Data->m_ReaderRegistry.GetReferences(*mimeTypeIter);
74 for (std::vector<FileReaderRegistry::ReaderReference>::const_iterator readerIter = refs.begin(),
76 readerIter != iterEnd;
79 IFileReader *reader = m_Data->m_ReaderRegistry.GetReader(*readerIter);
92 item.d->m_FileReaderRef = *readerIter;
93 item.d->m_FileReader = reader;
94 item.d->m_ConfidenceLevel = confidenceLevel;
95 item.d->m_MimeType = *mimeTypeIter;
97 m_Data->m_Items.insert(std::make_pair(item.d->m_Id, item));
104 catch (
const std::exception &e)
107 MITK_WARN <<
"IFileWriter::GetConfidenceLevel exception: " << e.what();
114 if (!m_Data->m_Items.empty())
116 std::set<Item> sortedItems;
117 for (std::map<long, Item>::const_iterator iter = m_Data->m_Items.begin(), iterEnd = m_Data->m_Items.end();
121 sortedItems.insert(iter->second);
123 m_Data->m_BestId = sortedItems.rbegin()->GetServiceId();
124 m_Data->m_SelectedId = m_Data->m_BestId;
131 m_Data = other.m_Data;
139 std::vector<Item> result;
140 for (std::map<long, Item>::const_iterator iter = m_Data->m_Items.begin(), iterEnd = m_Data->m_Items.end();
144 result.push_back(iter->second);
146 std::sort(result.begin(), result.end());
152 std::map<long, Item>::const_iterator iter = m_Data->m_Items.find(
id);
153 if (iter != m_Data->m_Items.end())
169 if (m_Data->m_Items.find(
id) == m_Data->m_Items.end())
173 m_Data->m_SelectedId = id;
193 return std::string();
204 if (d->m_ConfidenceLevel == other.d->m_ConfidenceLevel)
207 if (d->m_MimeType < other.d->m_MimeType)
211 else if (other.d->m_MimeType < d->m_MimeType)
218 return d->m_FileReaderRef < other.d->m_FileReaderRef;
221 return d->m_ConfidenceLevel < other.d->m_ConfidenceLevel;
224 FileReaderSelector::Item::Item() : d(new Impl()) {}
virtual ConfidenceLevel GetConfidenceLevel() const =0
The confidence level of the reader or writer implementation.
IFileReader::ConfidenceLevel GetConfidenceLevel() const
static IMimeTypeProvider * GetMimeTypeProvider(us::ModuleContext *context=us::GetModuleContext())
Get an IMimeTypeProvider instance.
std::vector< Item > Get() const
Get a sorted list of file reader items.
virtual const char * what() const override
bool Select(const Item &item)
static std::string PROP_DESCRIPTION()
Service property name for a description.
DataCollection - Class to facilitate loading/accessing structured data.
ValueType * any_cast(Any *operand)
IFileReader * GetReader() const
std::string GetDescription() const
Item & operator=(const Item &other)
bool operator<(const Item &other) const
FileReaderSelector(const FileReaderSelector &other)
long GetSelectedId() const
void Swap(ExplicitlySharedDataPointer &other)
std::vector< MimeType > GetMimeTypes() const
virtual void SetInput(const std::string &location)=0
Set the input location.
long GetServiceId() const
void swap(CustomMimeType &l, CustomMimeType &r)
std::string ToString() const
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
MimeType GetMimeType() const
void Swap(FileReaderSelector &fws)
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
A RAII helper class for core service objects.
The common interface for all MITK file readers.
US_Core_EXPORT const std::string & SERVICE_ID()
long GetDefaultId() const
FileReaderSelector & operator=(const FileReaderSelector &other)
us::ServiceReference< IFileReader > GetReference() const
virtual std::vector< MimeType > GetMimeTypesForFile(const std::string &filePath) const =0