Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef AbstractFileWriter_H_HEADER_INCLUDED_C1E7E521
18 #define AbstractFileWriter_H_HEADER_INCLUDED_C1E7E521
19 
20 // Macro
21 #include <MitkCoreExports.h>
22 
23 // MITK
24 #include <mitkIFileWriter.h>
25 #include <mitkMimeType.h>
26 
27 // Microservices
28 #include <usGetModuleContext.h>
29 #include <usServiceProperties.h>
30 #include <usServiceRegistration.h>
31 
32 #include <memory>
33 
34 namespace us
35 {
36  struct PrototypeServiceFactory;
37 }
38 
39 namespace mitk
40 {
41  class CustomMimeType;
42 
55  {
56  public:
57  virtual void SetInput(const BaseData *data) override;
58  virtual const BaseData *GetInput() const override;
59 
60  virtual void SetOutputLocation(const std::string &location) override;
61  virtual std::string GetOutputLocation() const override;
62 
63  virtual void SetOutputStream(const std::string &location, std::ostream *os) override;
64  virtual std::ostream *GetOutputStream() const override;
65 
82  virtual void Write() override = 0;
83 
84  virtual ConfidenceLevel GetConfidenceLevel() const override;
85 
86  MimeType GetRegisteredMimeType() const;
87 
88  virtual Options GetOptions() const override;
89  virtual us::Any GetOption(const std::string &name) const override;
90 
91  virtual void SetOptions(const Options &options) override;
92  virtual void SetOption(const std::string &name, const us::Any &value) override;
93 
94  virtual void AddProgressCallback(const ProgressCallback &callback) override;
95 
96  virtual void RemoveProgressCallback(const ProgressCallback &callback) override;
97 
98  us::ServiceRegistration<IFileWriter> RegisterService(us::ModuleContext *context = us::GetModuleContext());
99  void UnregisterService();
100 
101  protected:
111  {
112  public:
113  LocalFile(IFileWriter *writer);
114 
115  // Writes to the ostream and removes the temporary file
116  ~LocalFile();
117 
118  // Creates a temporary file for output operations.
119  std::string GetFileName();
120 
121  private:
122  // disabled
123  LocalFile();
124  LocalFile(const LocalFile &);
125  LocalFile &operator=(const LocalFile &other);
126 
127  struct Impl;
128  std::unique_ptr<Impl> d;
129  };
130 
139  class MITKCORE_EXPORT OutputStream : public std::ostream
140  {
141  public:
142  OutputStream(IFileWriter *writer, std::ios_base::openmode mode = std::ios_base::trunc | std::ios_base::out);
143  ~OutputStream();
144 
145  private:
146  std::ostream *m_Stream;
147  };
148 
150 
152 
153  AbstractFileWriter(const std::string &baseDataType);
154 
155  AbstractFileWriter(const std::string &baseDataType, const CustomMimeType &mimeType, const std::string &description);
156 
157  virtual us::ServiceProperties GetServiceProperties() const;
158 
172  virtual us::ServiceRegistration<CustomMimeType> RegisterMimeType(us::ModuleContext *context);
173 
174  void SetMimeType(const CustomMimeType &mimeType);
175 
179  const CustomMimeType *GetMimeType() const;
180 
181  void SetMimeTypePrefix(const std::string &prefix);
182  std::string GetMimeTypePrefix() const;
183 
189  void SetDescription(const std::string &description);
190  std::string GetDescription() const;
191 
192  void SetDefaultOptions(const Options &defaultOptions);
193  Options GetDefaultOptions() const;
194 
205  void SetRanking(int ranking);
206  int GetRanking() const;
207 
214  void SetBaseDataType(const std::string &baseDataType);
215  virtual std::string GetBaseDataType() const;
216 
217  void ValidateOutputLocation() const;
218 
219  private:
220  AbstractFileWriter &operator=(const AbstractFileWriter &other);
221 
222  virtual mitk::IFileWriter *Clone() const = 0;
223 
224  class Impl;
225  std::unique_ptr<Impl> d;
226  };
227 
228 } // namespace mitk
229 
230 #endif /* AbstractFileWriter_H_HEADER_INCLUDED_C1E7E521 */
Pointer Clone() const
#define MITKCORE_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:39
DataCollection - Class to facilitate loading/accessing structured data.
std::map< std::string, us::Any > Options
Options for reading or writing data.
Definition: mitkIFileIO.h:73
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
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:45
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
ConfidenceLevel
A confidence level describing the confidence of the reader or writer in handling the given data...
Definition: mitkIFileIO.h:49
The common interface of all MITK file writers.
Base class for writing mitk::BaseData objects to files or streams.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.