Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFileWriter.cpp
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 #include "mitkFileWriter.h"
18 
20 {
21  // TODO #345 check for writing permission
22  if (node == nullptr || node->GetData() == nullptr)
23  return false;
24  return node->GetData()->GetNameOfClass() == this->GetSupportedBaseData();
25 }
26 
28 {
29  return "";
30 }
31 
33 {
34  this->SetNthInput(0, data);
35 }
36 
38 {
39  return "";
40 }
41 
43 {
44  std::vector<std::string> possibleFileExtensions = this->GetPossibleFileExtensions();
45  std::stringstream stream;
46  for (unsigned int i = 0; i < possibleFileExtensions.size() - 1; i++)
47  {
48  stream << "*" << possibleFileExtensions.at(i) << " ";
49  }
50  stream << "*" << possibleFileExtensions.at(possibleFileExtensions.size() - 1);
51  return stream.str();
52 }
53 
54 bool mitk::FileWriter::IsExtensionValid(std::string extension)
55 {
56  std::vector<std::string> possibleFileExtensions = this->GetPossibleFileExtensions();
57  for (unsigned int i = 0; i < possibleFileExtensions.size(); i++)
58  {
59  if (strcmp(extension.c_str(), possibleFileExtensions.at(i).c_str()) == 0)
60  return true;
61  }
62  return false;
63 }
64 
65 mitk::FileWriter::FileWriter() : m_CanWriteToMemory(false), m_WriteToMemory(false)
66 {
67 }
68 
70 {
71 }
72 
74 {
75  return m_CanWriteToMemory;
76 }
78 {
79  m_WriteToMemory = write;
80 }
82 {
83  return m_WriteToMemory;
84 }
86 {
87  return (const char *)m_MemoryBuffer;
88 }
90 {
91  return m_MemoryBufferSize;
92 }
94 {
95  // do nothing here
96 }
bool IsExtensionValid(std::string extension)
Checks if given extension is valid for file writer.
Base of all data objects.
Definition: mitkBaseData.h:39
virtual void SetWriteToMemory(bool write)
Set/Get functions to advise the file writer to use tis internal memory array as file writing destinat...
virtual bool CanWriteDataType(DataNode *)
Check if the Writer can write this type of data of the DataTreenode.
virtual std::string GetPossibleFileExtensionsAsString()
possible file extensions for the data type associated with the writer as string
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
void SetInput(BaseData *data)
virtual std::string GetFileExtension()
Return the extension to be added to the filename.
virtual const char * GetMemoryPointer()
To be used along with a call of SetWriteToMemory(true). This returns the memory buffer where the file...
virtual unsigned int GetMemorySize()
To be used along with a call of SetWriteToMemory(true). This returns the size of the memory buffer wh...
virtual void ReleaseMemory()
CAUTION: It's up to the user to call this function to release the memory buffer after use in case the...
virtual std::string GetWritenMIMEType()
Return the MimeType of the saved File.
virtual bool CanWriteToMemory()
Specifies, whether the file writer also can write a file to a memory buffer.
virtual bool GetWriteToMemory()
virtual std::string GetSupportedBaseData() const =0
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66