24 #include <itksys/SystemTools.hxx> 34 Impl() : m_FileWriter(nullptr), m_ConfidenceLevel(IFileWriter::Unsupported), m_BaseDataIndex(0), m_Id(-1) {}
36 IFileWriter *m_FileWriter;
38 std::size_t m_BaseDataIndex;
45 Impl() : m_BestId(-1), m_SelectedId(m_BestId) {}
46 Impl(
const Impl &other) :
us::SharedData(other), m_BestId(-1), m_SelectedId(m_BestId) {}
47 FileWriterRegistry m_WriterRegistry;
48 std::map<long, FileWriterSelector::Item> m_Items;
49 std::set<MimeType> m_MimeTypes;
60 std::vector<FileWriterRegistry::WriterReference> refs;
62 std::string destMimeType = mimeType;
63 if (destMimeType.empty() && !path.empty())
67 if (!mimeTypes.empty())
69 for (
unsigned int index = 0; index < mimeTypes.size(); index++)
71 std::vector<FileWriterRegistry::WriterReference> tempRefs =
72 m_Data->m_WriterRegistry.GetReferences(baseData, mimeTypes.at(index).GetName());
73 for (
unsigned int innerIndex = 0; innerIndex < tempRefs.size(); innerIndex++)
75 refs.push_back(tempRefs.at(innerIndex));
79 else if (!itksys::SystemTools::GetFilenameExtension(path).empty())
87 refs = m_Data->m_WriterRegistry.GetReferences(baseData, destMimeType);
92 refs = m_Data->m_WriterRegistry.GetReferences(baseData, destMimeType);
99 for (std::vector<FileWriterRegistry::WriterReference>::const_iterator iter = refs.begin(), iterEnd = refs.end();
104 if (!mimeTypeName.empty())
112 IFileWriter *writer = m_Data->m_WriterRegistry.GetWriter(*iter);
113 if (writer ==
nullptr)
126 std::find(classHierarchy.begin(), classHierarchy.end(), baseDataType);
128 if (idxIter != classHierarchy.end())
130 baseDataIndex = std::distance(classHierarchy.begin(), idxIter);
134 item.d->m_FileWriterRef = *iter;
135 item.d->m_FileWriter = writer;
136 item.d->m_ConfidenceLevel = confidenceLevel;
137 item.d->m_BaseDataIndex = baseDataIndex;
138 item.d->m_MimeType = mimeType;
140 m_Data->m_Items.insert(std::make_pair(item.d->m_Id, item));
141 m_Data->m_MimeTypes.insert(mimeType);
151 catch (
const std::exception &e)
154 MITK_WARN <<
"IFileWriter::GetConfidenceLevel exception: " << e.what();
163 m_Data->m_SelectedId = m_Data->m_BestId;
170 m_Data = other.m_Data;
177 std::vector<Item> result;
178 for (std::map<long, Item>::const_iterator iter = m_Data->m_Items.begin(), iterEnd = m_Data->m_Items.end();
182 if (mimeType.empty() || iter->second.GetMimeType().GetName() == mimeType)
184 result.push_back(iter->second);
187 std::sort(result.begin(), result.end());
198 std::map<long, Item>::const_iterator iter = m_Data->m_Items.find(
id);
199 if (iter != m_Data->m_Items.end())
212 std::vector<Item> items =
Get(mimeType);
215 return Select(items.back());
223 if (m_Data->m_Items.find(
id) == m_Data->m_Items.end())
227 m_Data->m_SelectedId = id;
235 std::vector<MimeType> result;
236 result.reserve(m_Data->m_MimeTypes.size());
237 result.assign(m_Data->m_MimeTypes.begin(), m_Data->m_MimeTypes.end());
255 return std::string();
265 return std::string();
274 if (d->m_ConfidenceLevel == other.d->m_ConfidenceLevel)
278 if (d->m_BaseDataIndex == other.d->m_BaseDataIndex)
281 return d->m_FileWriterRef < other.d->m_FileWriterRef;
283 return other.d->m_BaseDataIndex < d->m_BaseDataIndex;
285 return d->m_ConfidenceLevel < other.d->m_ConfidenceLevel;
288 FileWriterSelector::Item::Item() : d(
new Impl()) {}
virtual ConfidenceLevel GetConfidenceLevel() const =0
The confidence level of the reader or writer implementation.
std::vector< Item > Get() const
Get a sorted list of file writer info objects.
static IMimeTypeProvider * GetMimeTypeProvider(us::ModuleContext *context=us::GetModuleContext())
Get an IMimeTypeProvider instance.
Base of all data objects.
long GetSelectedId() const
Item & operator=(const Item &other)
virtual MimeType GetMimeTypeForName(const std::string &name) const =0
long GetServiceId() const
static std::string PROP_DESCRIPTION()
Service property name for a description.
bool Select(const std::string &mimeType)
DataCollection - Class to facilitate loading/accessing structured data.
ValueType * any_cast(Any *operand)
static std::string PROP_MIMETYPE()
Service property name for the mime-type associated with this file writer.
virtual std::vector< std::string > GetClassHierarchy() const
std::string ToString() const
IFileWriter::ConfidenceLevel GetConfidenceLevel() const
std::vector< MimeType > GetMimeTypes() const
const char * what() const override
void Swap(ExplicitlySharedDataPointer &other)
bool operator<(const Item &other) const
std::string GetBaseDataType() const
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
MimeType GetMimeType() const
void swap(CustomMimeType &l, CustomMimeType &r)
virtual void SetInput(const BaseData *data)=0
Set the input data for writing.
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
FileWriterSelector & operator=(const FileWriterSelector &other)
std::string GetDescription() const
static std::string PROP_BASEDATA_TYPE()
Service property name for the supported mitk::BaseData sub-class.
FileWriterSelector(const FileWriterSelector &other)
A RAII helper class for core service objects.
long GetDefaultId() const
US_Core_EXPORT const std::string & SERVICE_ID()
The common interface of all MITK file writers.
IFileWriter * GetWriter() const
us::ServiceReference< IFileWriter > GetReference() const
void Swap(FileWriterSelector &fws)
virtual std::vector< MimeType > GetMimeTypesForFile(const std::string &filePath) const =0