Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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 AbstractFileWriter_H_HEADER_INCLUDED_C1E7E521
14 #define AbstractFileWriter_H_HEADER_INCLUDED_C1E7E521
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 
51  {
52  public:
53  void SetInput(const BaseData *data) override;
54  const BaseData *GetInput() const override;
55 
56  void SetOutputLocation(const std::string &location) override;
57  std::string GetOutputLocation() const override;
58 
59  void SetOutputStream(const std::string &location, std::ostream *os) override;
60  std::ostream *GetOutputStream() const override;
61 
78  void Write() override = 0;
79 
80  ConfidenceLevel GetConfidenceLevel() const override;
81 
82  MimeType GetRegisteredMimeType() const;
83 
84  Options GetOptions() const override;
85  us::Any GetOption(const std::string &name) const override;
86 
87  void SetOptions(const Options &options) override;
88  void SetOption(const std::string &name, const us::Any &value) override;
89 
90  void AddProgressCallback(const ProgressCallback &callback) override;
91 
92  void RemoveProgressCallback(const ProgressCallback &callback) override;
93 
94  us::ServiceRegistration<IFileWriter> RegisterService(us::ModuleContext *context = us::GetModuleContext());
95  void UnregisterService();
96 
97  protected:
107  {
108  public:
109  LocalFile(IFileWriter *writer);
110 
111  // Writes to the ostream and removes the temporary file
112  ~LocalFile();
113 
114  // Creates a temporary file for output operations.
115  std::string GetFileName();
116 
117  private:
118  // disabled
119  LocalFile();
120  LocalFile(const LocalFile &);
121  LocalFile &operator=(const LocalFile &other);
122 
123  struct Impl;
124  std::unique_ptr<Impl> d;
125  };
126 
135  class MITKCORE_EXPORT OutputStream : public std::ostream
136  {
137  public:
138  OutputStream(IFileWriter *writer, std::ios_base::openmode mode = std::ios_base::trunc | std::ios_base::out);
139  ~OutputStream() override;
140 
141  private:
142  std::ostream *m_Stream;
143  };
144 
145  ~AbstractFileWriter() override;
146 
148 
149  AbstractFileWriter(const std::string &baseDataType);
150 
151  AbstractFileWriter(const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description);
152 
153  virtual us::ServiceProperties GetServiceProperties() const;
154 
168  virtual us::ServiceRegistration<CustomMimeType> RegisterMimeType(us::ModuleContext *context);
169 
170  void SetMimeType(const CustomMimeType &mimeType);
171 
175  const CustomMimeType *GetMimeType() const;
176 
177  void SetMimeTypePrefix(const std::string &prefix);
178  std::string GetMimeTypePrefix() const;
179 
185  void SetDescription(const std::string &description);
186  std::string GetDescription() const;
187 
188  void SetDefaultOptions(const Options &defaultOptions);
189  Options GetDefaultOptions() const;
190 
201  void SetRanking(int ranking);
202  int GetRanking() const;
203 
210  void SetBaseDataType(const std::string &baseDataType);
211  virtual std::string GetBaseDataType() const;
212 
213  void ValidateOutputLocation() const;
214 
215  private:
216  AbstractFileWriter &operator=(const AbstractFileWriter &other);
217 
218  virtual mitk::IFileWriter *Clone() const = 0;
219 
220  class Impl;
221  std::unique_ptr<Impl> d;
222  };
223 
224 } // namespace mitk
225 
226 #endif /* AbstractFileWriter_H_HEADER_INCLUDED_C1E7E521 */
#define MITKCORE_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:37
DataCollection - Class to facilitate loading/accessing structured data.
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:69
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:45
Definition: usAny.h:163
A local file representation for streams.
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
Definition: mitkMimeType.h:36
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
The common interface of all MITK file writers.
static mitk::PlanarFigure::Pointer Clone(mitk::PlanarFigure::Pointer original)
Base class for writing mitk::BaseData objects to files or streams.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.