Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::AbstractFileWriter Class Referenceabstract

Base class for writing mitk::BaseData objects to files or streams. More...

#include <mitkAbstractFileWriter.h>

Inheritance diagram for mitk::AbstractFileWriter:
Collaboration diagram for mitk::AbstractFileWriter:

Classes

class  LocalFile
 A local file representation for writers that cannot use streams. More...
 
class  OutputStream
 An output stream wrapper for writer implementations. More...
 

Public Member Functions

void SetInput (const BaseData *data) override
 Set the input data for writing. More...
 
const BaseData * GetInput () const override
 Get the input data. More...
 
void SetOutputLocation (const std::string &location) override
 Set the output file-system path, clearing any output stream. More...
 
std::string GetOutputLocation () const override
 Get the current output location. More...
 
void SetOutputStream (const std::string &location, std::ostream *os) override
 Set an output stream and associated location label. More...
 
std::ostream * GetOutputStream () const override
 Get the current output stream. More...
 
void Write () override=0
 Write the base data to the specified location or output stream. More...
 
ConfidenceLevel GetConfidenceLevel () const override
 Determine confidence for writing the current input data. More...
 
MimeType GetRegisteredMimeType () const
 Get the MIME type that was registered for this writer. More...
 
Options GetOptions () const override
 Get the current option values. More...
 
us::Any GetOption (const std::string &name) const override
 Get the value of a specific option. More...
 
void SetOptions (const Options &options) override
 Set multiple options at once. More...
 
void SetOption (const std::string &name, const us::Any &value) override
 Set a single option value. More...
 
void AddProgressCallback (const ProgressCallback &callback) override
 Register a progress callback. More...
 
void RemoveProgressCallback (const ProgressCallback &callback) override
 Remove a previously registered progress callback. More...
 
us::ServiceRegistration< IFileWriter > RegisterService (us::ModuleContext *context=us::GetModuleContext())
 Register this writer as a CppMicroServices service. More...
 
void UnregisterService ()
 Unregister this writer from the CppMicroServices registry. More...
 
- Public Member Functions inherited from mitk::IFileWriter
 ~IFileWriter () override
 
- Public Member Functions inherited from mitk::IFileIO
virtual ~IFileIO ()
 

Protected Member Functions

 ~AbstractFileWriter () override
 
 AbstractFileWriter (const AbstractFileWriter &other)
 Copy constructor. More...
 
 AbstractFileWriter (const std::string &baseDataType)
 Construct a writer for the given BaseData type name. More...
 
 AbstractFileWriter (const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description)
 Construct a writer for the given BaseData type, MIME type, and description. More...
 
virtual us::ServiceProperties GetServiceProperties () const
 Get the service properties for registration. More...
 
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType (us::ModuleContext *context)
 Register a new CustomMimeType service object. More...
 
void SetMimeType (const CustomMimeType &mimeType)
 Set the MIME type this writer can handle. More...
 
const CustomMimeType * GetMimeType () const
 Get the MIME type this writer can handle. More...
 
void SetMimeTypePrefix (const std::string &prefix)
 Set the prefix used for auto-generated MIME type names. More...
 
std::string GetMimeTypePrefix () const
 Get the current MIME type name prefix. More...
 
void SetDescription (const std::string &description)
 Set a human-readable description of this writer. More...
 
std::string GetDescription () const
 Get the human-readable description of this writer. More...
 
void SetDefaultOptions (const Options &defaultOptions)
 Set the default options for this writer. More...
 
Options GetDefaultOptions () const
 Get the default options for this writer. More...
 
void SetRanking (int ranking)
 Set the service ranking for this file writer. More...
 
int GetRanking () const
 Get the service ranking for this file writer. More...
 
void SetBaseDataType (const std::string &baseDataType)
 Set the name of the mitk::BaseData sub-class this writer supports. More...
 
virtual std::string GetBaseDataType () const
 Get the name of the mitk::BaseData sub-class this writer supports. More...
 
void ValidateOutputLocation () const
 Validate the output location or stream. More...
 

Additional Inherited Members

- Public Types inherited from mitk::IFileIO
enum  ConfidenceLevel { Unsupported , PartiallySupported , Supported }
 A confidence level describing the reader's or writer's ability to handle the given data or file format. More...
 
typedef std::map< std::string, us::Any > Options
 Options for reading or writing data. More...
 
typedef mitk::MessageAbstractDelegate1< float > ProgressCallback
 Callback delegate type for progress reporting. More...
 
- Static Public Member Functions inherited from mitk::IFileWriter
static std::string PROP_BASEDATA_TYPE ()
 Service property name for the supported mitk::BaseData sub-class. More...
 
- Static Public Member Functions inherited from mitk::IFileIO
static std::string PROP_DESCRIPTION ()
 Service property name for a human-readable description. More...
 
static std::string PROP_MIMETYPE ()
 Service property name for the mime-type associated with this reader or writer. More...
 

Detailed Description

Base class for writing mitk::BaseData objects to files or streams.

In general, all file writers should derive from this class to ensure that the implementation is exposed to the CppMicroServices framework and is automatically available throughout MITK. Subclasses need to implement Write() and Clone().

See also
IFileWriter
AbstractFileIO
AbstractFileReader
FileWriterSelector

Definition at line 54 of file mitkAbstractFileWriter.h.

Constructor & Destructor Documentation

◆ ~AbstractFileWriter()

mitk::AbstractFileWriter::~AbstractFileWriter ( )
overrideprotected

◆ AbstractFileWriter() [1/3]

mitk::AbstractFileWriter::AbstractFileWriter ( const AbstractFileWriter &  other)
protected

Copy constructor.

Parameters
[in]otherThe writer to copy from.

◆ AbstractFileWriter() [2/3]

mitk::AbstractFileWriter::AbstractFileWriter ( const std::string &  baseDataType)
protected

Construct a writer for the given BaseData type name.

Parameters
[in]baseDataTypeThe class name of the BaseData sub-class this writer supports.

◆ AbstractFileWriter() [3/3]

mitk::AbstractFileWriter::AbstractFileWriter ( const std::string &  baseDataType,
const CustomMimeType &  mimeType,
const std::string &  description 
)
protected

Construct a writer for the given BaseData type, MIME type, and description.

Parameters
[in]baseDataTypeThe class name of the BaseData sub-class this writer supports.
[in]mimeTypeThe MIME type this writer produces.
[in]descriptionA human-readable description of this writer.

Member Function Documentation

◆ AddProgressCallback()

void mitk::AbstractFileWriter::AddProgressCallback ( const ProgressCallback &  callback)
overridevirtual

Register a progress callback.

Parameters
[in]callbackThe callback delegate to add.

Implements mitk::IFileIO.

◆ GetBaseDataType()

virtual std::string mitk::AbstractFileWriter::GetBaseDataType ( ) const
protectedvirtual

Get the name of the mitk::BaseData sub-class this writer supports.

Returns
The BaseData type name.

◆ GetConfidenceLevel()

ConfidenceLevel mitk::AbstractFileWriter::GetConfidenceLevel ( ) const
overridevirtual

Determine confidence for writing the current input data.

Returns
Supported if the input data's class hierarchy matches the writer's BaseData type, Unsupported otherwise.

Implements mitk::IFileIO.

Reimplemented in mitk::MultiLabelSegmentationStackWriterBase.

Referenced by mitk::AbstractFileIOWriter::GetWriterConfidenceLevel().

◆ GetDefaultOptions()

Options mitk::AbstractFileWriter::GetDefaultOptions ( ) const
protected

Get the default options for this writer.

Returns
A map of option names to default values.

◆ GetDescription()

std::string mitk::AbstractFileWriter::GetDescription ( ) const
protected

Get the human-readable description of this writer.

Returns
The description string.

◆ GetInput()

const BaseData* mitk::AbstractFileWriter::GetInput ( ) const
overridevirtual

Get the input data.

Returns
Pointer to the BaseData, or nullptr if none was set.

Implements mitk::IFileWriter.

◆ GetMimeType()

const CustomMimeType* mitk::AbstractFileWriter::GetMimeType ( ) const
protected

Get the MIME type this writer can handle.

Returns
Pointer to the internal CustomMimeType, or nullptr.

◆ GetMimeTypePrefix()

std::string mitk::AbstractFileWriter::GetMimeTypePrefix ( ) const
protected

Get the current MIME type name prefix.

Returns
The prefix string.

◆ GetOption()

us::Any mitk::AbstractFileWriter::GetOption ( const std::string &  name) const
overridevirtual

Get the value of a specific option.

Parameters
[in]nameThe option name.
Returns
The option value.

Implements mitk::IFileIO.

◆ GetOptions()

Options mitk::AbstractFileWriter::GetOptions ( ) const
overridevirtual

Get the current option values.

Returns
A map of option names to their current values.

Implements mitk::IFileIO.

◆ GetOutputLocation()

std::string mitk::AbstractFileWriter::GetOutputLocation ( ) const
overridevirtual

Get the current output location.

Returns
The file path or label set via SetOutputLocation() or SetOutputStream().

Implements mitk::IFileWriter.

◆ GetOutputStream()

std::ostream* mitk::AbstractFileWriter::GetOutputStream ( ) const
overridevirtual

Get the current output stream.

Returns
The output stream, or nullptr if writing to a file path.

Implements mitk::IFileWriter.

◆ GetRanking()

int mitk::AbstractFileWriter::GetRanking ( ) const
protected

Get the service ranking for this file writer.

Returns
The ranking value.

◆ GetRegisteredMimeType()

MimeType mitk::AbstractFileWriter::GetRegisteredMimeType ( ) const

Get the MIME type that was registered for this writer.

Returns
The registered MimeType, which may be invalid if not yet registered.

◆ GetServiceProperties()

virtual us::ServiceProperties mitk::AbstractFileWriter::GetServiceProperties ( ) const
protectedvirtual

Get the service properties for registration.

Returns
A map of service property names to values.

◆ RegisterMimeType()

virtual us::ServiceRegistration<CustomMimeType> mitk::AbstractFileWriter::RegisterMimeType ( us::ModuleContext *  context)
protectedvirtual

Register a new CustomMimeType service object.

Called internally from RegisterService(). The default implementation registers a new mime-type service if the mime-type has not been registered yet.

Parameters
[in]contextThe module context for registration.
Returns
The service registration for the CustomMimeType.
Exceptions
std::invalid_argumentif context is nullptr.

◆ RegisterService()

us::ServiceRegistration<IFileWriter> mitk::AbstractFileWriter::RegisterService ( us::ModuleContext *  context = us::GetModuleContext())

Register this writer as a CppMicroServices service.

Registers this writer with its mime-type in the service registry using a PrototypeServiceFactory, so that each consumer gets its own clone.

Parameters
[in]contextThe module context for service registration. Defaults to the current module context.
Returns
The service registration object, or an invalid registration if the writer could not be registered.

◆ RemoveProgressCallback()

void mitk::AbstractFileWriter::RemoveProgressCallback ( const ProgressCallback &  callback)
overridevirtual

Remove a previously registered progress callback.

Parameters
[in]callbackThe callback delegate to remove.

Implements mitk::IFileIO.

◆ SetBaseDataType()

void mitk::AbstractFileWriter::SetBaseDataType ( const std::string &  baseDataType)
protected

Set the name of the mitk::BaseData sub-class this writer supports.

Parameters
[in]baseDataTypeThe class name, as returned by BaseData::GetNameOfClass().

◆ SetDefaultOptions()

void mitk::AbstractFileWriter::SetDefaultOptions ( const Options &  defaultOptions)
protected

Set the default options for this writer.

Parameters
[in]defaultOptionsA map of option names to default values.

◆ SetDescription()

void mitk::AbstractFileWriter::SetDescription ( const std::string &  description)
protected

Set a human-readable description of this writer.

Parameters
[in]descriptionThe description string, used in file dialogs.

◆ SetInput()

void mitk::AbstractFileWriter::SetInput ( const BaseData *  data)
overridevirtual

Set the input data for writing.

Parameters
[in]dataThe BaseData object to write.

Implements mitk::IFileWriter.

◆ SetMimeType()

void mitk::AbstractFileWriter::SetMimeType ( const CustomMimeType &  mimeType)
protected

Set the MIME type this writer can handle.

Parameters
[in]mimeTypeThe CustomMimeType to associate with this writer.

◆ SetMimeTypePrefix()

void mitk::AbstractFileWriter::SetMimeTypePrefix ( const std::string &  prefix)
protected

Set the prefix used for auto-generated MIME type names.

Parameters
[in]prefixThe prefix string (e.g. "application/vnd.mitk").

◆ SetOption()

void mitk::AbstractFileWriter::SetOption ( const std::string &  name,
const us::Any &  value 
)
overridevirtual

Set a single option value.

Parameters
[in]nameThe option name.
[in]valueThe new option value.

Implements mitk::IFileIO.

◆ SetOptions()

void mitk::AbstractFileWriter::SetOptions ( const Options &  options)
overridevirtual

Set multiple options at once.

Parameters
[in]optionsA map of option names to their new values.

Implements mitk::IFileIO.

◆ SetOutputLocation()

void mitk::AbstractFileWriter::SetOutputLocation ( const std::string &  location)
overridevirtual

Set the output file-system path, clearing any output stream.

Parameters
[in]locationThe file path to write to.

Implements mitk::IFileWriter.

◆ SetOutputStream()

void mitk::AbstractFileWriter::SetOutputStream ( const std::string &  location,
std::ostream *  os 
)
overridevirtual

Set an output stream and associated location label.

Parameters
[in]locationA file-system path or custom label.
[in]osThe output stream, or nullptr to clear.

Implements mitk::IFileWriter.

◆ SetRanking()

void mitk::AbstractFileWriter::SetRanking ( int  ranking)
protected

Set the service ranking for this file writer.

Parameters
[in]rankingThe ranking value. Default is zero.

The ranking is used to determine which writer to use if several equivalent writers have been found. Use a higher ranking to override a default writer from MITK in your own project.

◆ UnregisterService()

void mitk::AbstractFileWriter::UnregisterService ( )

Unregister this writer from the CppMicroServices registry.

◆ ValidateOutputLocation()

void mitk::AbstractFileWriter::ValidateOutputLocation ( ) const
protected

Validate the output location or stream.

Exceptions
mitk::Exceptionif neither an output location nor an output stream is set.

◆ Write()

void mitk::AbstractFileWriter::Write ( )
overridepure virtual

The documentation for this class was generated from the following file: