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