Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkAbstractFileWriter.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkAbstractFileWriter_h
14 #define mitkAbstractFileWriter_h
15 
16 // Macro
17 #include <MitkCoreExports.h>
18 
19 // MITK
20 #include <mitkIFileWriter.h>
21 #include <mitkMimeType.h>
22 
23 // Microservices
24 #include <usGetModuleContext.h>
25 #include <usServiceProperties.h>
26 #include <usServiceRegistration.h>
27 
28 #include <memory>
29 
30 namespace us
31 {
32  struct PrototypeServiceFactory;
33 }
34 
35 namespace mitk
36 {
37  class CustomMimeType;
38 
55  {
56  public:
61  void SetInput(const BaseData *data) override;
62 
67  const BaseData *GetInput() const override;
68 
73  void SetOutputLocation(const std::string &location) override;
74 
79  std::string GetOutputLocation() const override;
80 
86  void SetOutputStream(const std::string &location, std::ostream *os) override;
87 
92  std::ostream *GetOutputStream() const override;
93 
109  void Write() override = 0;
110 
117 
123 
128  Options GetOptions() const override;
129 
135  us::Any GetOption(const std::string &name) const override;
136 
141  void SetOptions(const Options &options) override;
142 
148  void SetOption(const std::string &name, const us::Any &value) override;
149 
154  void AddProgressCallback(const ProgressCallback &callback) override;
155 
160  void RemoveProgressCallback(const ProgressCallback &callback) override;
161 
174 
179 
180  protected:
191  {
192  public:
198 
204 
210  std::string GetFileName();
211 
212  private:
213  // disabled
214  LocalFile();
215  LocalFile(const LocalFile &);
216  LocalFile &operator=(const LocalFile &other);
217 
218  struct Impl;
219  std::unique_ptr<Impl> d;
220  };
221 
232  class MITKCORE_EXPORT OutputStream : public std::ostream
233  {
234  public:
240  OutputStream(IFileWriter *writer, std::ios_base::openmode mode = std::ios_base::trunc | std::ios_base::out);
241 
242  ~OutputStream() override;
243 
244  private:
245  std::ostream *m_Stream;
246  };
247 
249 
255 
260  AbstractFileWriter(const std::string &baseDataType);
261 
268  AbstractFileWriter(const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description);
269 
275 
288 
293  void SetMimeType(const CustomMimeType &mimeType);
294 
299  const CustomMimeType *GetMimeType() const;
300 
305  void SetMimeTypePrefix(const std::string &prefix);
306 
311  std::string GetMimeTypePrefix() const;
312 
317  void SetDescription(const std::string &description);
318 
323  std::string GetDescription() const;
324 
329  void SetDefaultOptions(const Options &defaultOptions);
330 
336 
345  void SetRanking(int ranking);
346 
351  int GetRanking() const;
352 
357  void SetBaseDataType(const std::string &baseDataType);
358 
363  virtual std::string GetBaseDataType() const;
364 
370 
371  private:
372  AbstractFileWriter &operator=(const AbstractFileWriter &other);
373 
374  virtual mitk::IFileWriter *Clone() const = 0;
375 
376  class Impl;
377  std::unique_ptr<Impl> d;
378  };
379 
380 } // namespace mitk
381 
382 #endif
#define MITKCORE_EXPORT
A local file representation for writers that cannot use streams.
~LocalFile()
Destructor. Writes temporary file contents to the output stream (if any) and removes the temporary fi...
std::string GetFileName()
Get a local file name for writing.
LocalFile(IFileWriter *writer)
Construct a LocalFile for the given writer.
An output stream wrapper for writer implementations.
OutputStream(IFileWriter *writer, std::ios_base::openmode mode=std::ios_base::trunc|std::ios_base::out)
Construct an OutputStream from a writer's configured output.
Base class for writing mitk::BaseData objects to files or streams.
const BaseData * GetInput() const override
Get the input data.
void SetInput(const BaseData *data) override
Set the input data for writing.
AbstractFileWriter(const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description)
Construct a writer for the given BaseData type, MIME type, and description.
void SetDefaultOptions(const Options &defaultOptions)
Set the default options for this writer.
int GetRanking() const
Get the service ranking for this file writer.
Options GetOptions() const override
Get the current option values.
void SetOutputStream(const std::string &location, std::ostream *os) override
Set an output stream and associated location label.
~AbstractFileWriter() override
ConfidenceLevel GetConfidenceLevel() const override
Determine confidence for writing the current input data.
virtual us::ServiceProperties GetServiceProperties() const
Get the service properties for registration.
std::string GetOutputLocation() const override
Get the current output location.
void ValidateOutputLocation() const
Validate the output location or stream.
void AddProgressCallback(const ProgressCallback &callback) override
Register a progress callback.
void SetOutputLocation(const std::string &location) override
Set the output file-system path, clearing any output stream.
void SetOptions(const Options &options) override
Set multiple options at once.
std::string GetDescription() const
Get the human-readable description of this writer.
virtual std::string GetBaseDataType() const
Get the name of the mitk::BaseData sub-class this writer supports.
void SetDescription(const std::string &description)
Set a human-readable description of this writer.
void SetBaseDataType(const std::string &baseDataType)
Set the name of the mitk::BaseData sub-class this writer supports.
Options GetDefaultOptions() const
Get the default options for this writer.
void UnregisterService()
Unregister this writer from the CppMicroServices registry.
us::Any GetOption(const std::string &name) const override
Get the value of a specific option.
MimeType GetRegisteredMimeType() const
Get the MIME type that was registered for this writer.
std::string GetMimeTypePrefix() const
Get the current MIME type name prefix.
void SetMimeTypePrefix(const std::string &prefix)
Set the prefix used for auto-generated MIME type names.
void Write() override=0
Write the base data to the specified location or output stream.
virtual us::ServiceRegistration< CustomMimeType > RegisterMimeType(us::ModuleContext *context)
Register a new CustomMimeType service object.
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Register this writer as a CppMicroServices service.
const CustomMimeType * GetMimeType() const
Get the MIME type this writer can handle.
void SetMimeType(const CustomMimeType &mimeType)
Set the MIME type this writer can handle.
void SetOption(const std::string &name, const us::Any &value) override
Set a single option value.
AbstractFileWriter(const std::string &baseDataType)
Construct a writer for the given BaseData type name.
void RemoveProgressCallback(const ProgressCallback &callback) override
Remove a previously registered progress callback.
void SetRanking(int ranking)
Set the service ranking for this file writer.
std::ostream * GetOutputStream() const override
Get the current output stream.
AbstractFileWriter(const AbstractFileWriter &other)
Copy constructor.
Base class of all data objects.
Definition: mitkBaseData.h:60
A custom mime-type that can be registered as a service object.
Abstract base class for message delegates with one parameter.
Definition: mitkMessage.h:101
Immutable, value-type wrapper for a registered mime-type.
Definition: mitkMimeType.h:45
An Any class represents a general type and is capable of storing any type, supporting type-safe extra...
Definition: usAny.h:145
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
std::unordered_map< std::string, Any > ServiceProperties
Find image slices visible on a given plane.
ConfidenceLevel
A confidence level describing the reader's or writer's ability to handle the given data or file forma...
Definition: mitkIFileIO.h:57
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:80
The common interface of all MITK file writers.