Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkMimeType.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 "mitkMimeType.h"
18 
19 #include "mitkCustomMimeType.h"
20 
21 #include <memory>
22 
23 namespace mitk
24 {
25  struct MimeType::Impl : us::SharedData
26  {
27  Impl() : m_CustomMimeType(new CustomMimeType()), m_Rank(-1), m_Id(-1) {}
28  Impl(const CustomMimeType &x, int rank, long id) : m_CustomMimeType(x.Clone()), m_Rank(rank), m_Id(id) {}
29  std::unique_ptr<CustomMimeType> m_CustomMimeType;
30 
31  int m_Rank;
32  long m_Id;
33  };
34 
35  MimeType::MimeType() : m_Data(new Impl) {}
36  MimeType::MimeType(const MimeType &other) : m_Data(other.m_Data) {}
37  MimeType::MimeType(const CustomMimeType &x, int rank, long id) : m_Data(new Impl(x, rank, id)) {}
40  {
41  m_Data = other.m_Data;
42  return *this;
43  }
44 
45  bool MimeType::operator==(const MimeType &other) const { return this->GetName() == other.GetName(); }
46  bool MimeType::operator<(const MimeType &other) const
47  {
48  if (m_Data->m_Rank != other.m_Data->m_Rank)
49  {
50  return m_Data->m_Rank < other.m_Data->m_Rank;
51  }
52  return other.m_Data->m_Id < m_Data->m_Id;
53  }
54 
55  std::string MimeType::GetName() const { return m_Data->m_CustomMimeType->GetName(); }
56  std::string MimeType::GetCategory() const { return m_Data->m_CustomMimeType->GetCategory(); }
57  std::vector<std::string> MimeType::GetExtensions() const { return m_Data->m_CustomMimeType->GetExtensions(); }
58  std::string MimeType::GetComment() const { return m_Data->m_CustomMimeType->GetComment(); }
59  std::string MimeType::GetFilenameWithoutExtension(const std::string &path) const
60  {
61  return m_Data->m_CustomMimeType->GetFilenameWithoutExtension(path);
62  }
63 
64  bool MimeType::AppliesTo(const std::string &path) const { return m_Data->m_CustomMimeType->AppliesTo(path); }
65  bool MimeType::MatchesExtension(const std::string &path) const
66  {
67  return m_Data->m_CustomMimeType->MatchesExtension(path);
68  }
69 
70  bool MimeType::IsValid() const
71  {
72  return m_Data.Data() != NULL && m_Data->m_CustomMimeType.get() != NULL &&
73  !m_Data->m_CustomMimeType->GetName().empty();
74  }
75 
76  void MimeType::Swap(MimeType &m) { m_Data.Swap(m.m_Data); }
77  void swap(MimeType &m1, MimeType &m2) { m1.Swap(m2); }
78  std::ostream &operator<<(std::ostream &os, const MimeType &mimeType)
79  {
80  os << mimeType.GetName() << " (" << mimeType.GetCategory() << ", " << mimeType.GetComment() << ") ";
81  std::vector<std::string> extensions = mimeType.GetExtensions();
82  for (std::vector<std::string>::const_iterator iter = extensions.begin(), endIter = extensions.end();
83  iter != endIter;
84  ++iter)
85  {
86  if (iter != extensions.begin())
87  os << ", ";
88  os << *iter;
89  }
90  return os;
91  }
92 }
bool AppliesTo(const std::string &path) const
Pointer Clone() const
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
void Swap(SharedDataPointer &other)
Definition: usSharedData.h:115
bool IsValid() const
DataCollection - Class to facilitate loading/accessing structured data.
std::vector< std::string > GetExtensions() const
void Swap(MimeType &m)
std::string GetName() const
std::string GetFilenameWithoutExtension(const std::string &path) const
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
MimeType & operator=(const MimeType &other)
bool operator<(const MimeType &other) const
void swap(CustomMimeType &l, CustomMimeType &r)
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
Definition: mitkMimeType.h:45
std::string GetComment() const
std::string GetCategory() const
bool operator==(const MimeType &other) const
bool MatchesExtension(const std::string &path) const