ITK  6.0.0
Insight Toolkit
itkMetaDataDictionary.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkMetaDataDictionary_h
19 #define itkMetaDataDictionary_h
20 
21 #include "itkMetaDataObjectBase.h"
22 #include <algorithm> // For std::equal
23 #include <vector>
24 #include <map>
25 #include <string>
26 #include <memory>
27 
28 namespace itk
29 {
54 class ITKCommon_EXPORT MetaDataDictionary
55 {
56 public:
62  virtual void
63  Print(std::ostream & os) const;
64 
65  // Declare the datastructure that will be used to hold the
66  // dictionary.
67  using MetaDataDictionaryMapType = std::map<std::string, MetaDataObjectBase::Pointer>;
68  using Iterator = MetaDataDictionaryMapType::iterator;
69  using ConstIterator = MetaDataDictionaryMapType::const_iterator;
70 
71  // Constructor
73  // Copy Constructor
76  // operator =
78  operator=(const MetaDataDictionary &);
80  operator=(MetaDataDictionary &&) = default;
81 
82  // Destructor
83  virtual ~MetaDataDictionary();
84 
86  friend bool
87  operator==(const Self & lhs, const Self & rhs)
88  {
89  using KeyValuePair = MetaDataDictionaryMapType::value_type;
90 
91  return (lhs.m_Dictionary == rhs.m_Dictionary) ||
92  ((lhs.m_Dictionary != nullptr) && (rhs.m_Dictionary != nullptr) &&
93  (lhs.m_Dictionary->size() == rhs.m_Dictionary->size()) &&
94  std::equal(lhs.m_Dictionary->cbegin(),
95  lhs.m_Dictionary->cend(),
96  rhs.m_Dictionary->cbegin(),
97  [](const KeyValuePair & keyValuePair1, const KeyValuePair & keyValuePair2) {
98  const auto & value1 = keyValuePair1.second;
99  const auto & value2 = keyValuePair2.second;
100  return (keyValuePair1.first == keyValuePair2.first) &&
101  ((value1 == value2) ||
102  ((value1 != nullptr) && (value2 != nullptr) && (*value1 == *value2)));
103  }));
104  }
105 
107  friend bool
108  operator!=(const Self & lhs, const Self & rhs)
109  {
110  return !(lhs == rhs);
111  }
112 
113 
117  std::vector<std::string>
118  GetKeys() const;
119 
120  // Implement map's api. On some Microsoft compilers, stl containers
121  // cannot be exported. This causes problems when building DLL's.
122  // Here we inherit privately from std::map and provide a simple
123  // API. The implementation will be in the DLL.
125  operator[](const std::string &);
126 
127  // \brief Get a constant point to a DataObject
128  //
129  // If the key does not exist then nullptr is returned.
130  const MetaDataObjectBase *
131  operator[](const std::string &) const;
132 
133  const MetaDataObjectBase *
134  Get(const std::string &) const;
135  void
136  Set(const std::string &, MetaDataObjectBase *);
137  bool
138  HasKey(const std::string &) const;
139 
140  bool
141  Erase(const std::string &);
142 
148  // Blacklisted by igenerator.py
149  Iterator
150  Begin();
151  // Blacklisted by igenerator.py
152  ConstIterator
153  Begin() const;
157  // Blacklisted by igenerator.py
158  Iterator
159  End();
160  // Blacklisted by igenerator.py
161  ConstIterator
162  End() const;
166  Iterator
167  Find(const std::string & key);
168 
169  ConstIterator
170  Find(const std::string & key) const;
171 
173  void
174  Clear();
175 
176  void
177  Swap(MetaDataDictionary & other);
178 
179 private:
180  bool
181  MakeUnique();
182 
183  std::shared_ptr<MetaDataDictionaryMapType> m_Dictionary{};
184 };
185 
186 inline void
188 {
189  a.Swap(b);
190 }
191 
192 } // namespace itk
193 #endif // itkMetaDataDictionary_h
itk::MetaDataDictionary::m_Dictionary
std::shared_ptr< MetaDataDictionaryMapType > m_Dictionary
Definition: itkMetaDataDictionary.h:183
itk::MetaDataObjectBase
The common interface for MetaDataObject's.
Definition: itkMetaDataObjectBase.h:47
itkMetaDataObjectBase.h
itk::MetaDataDictionary::operator!=
friend bool operator!=(const Self &lhs, const Self &rhs)
Definition: itkMetaDataDictionary.h:108
itk::MetaDataDictionary::operator==
friend bool operator==(const Self &lhs, const Self &rhs)
Definition: itkMetaDataDictionary.h:87
itk::SmartPointer< Self >
itk::MetaDataDictionary::ConstIterator
MetaDataDictionaryMapType::const_iterator ConstIterator
Definition: itkMetaDataDictionary.h:69
itk::MetaDataDictionary
Provides a mechanism for storing a collection of arbitrary data types.
Definition: itkMetaDataDictionary.h:54
itk::MetaDataDictionary::MetaDataDictionaryMapType
std::map< std::string, MetaDataObjectBase::Pointer > MetaDataDictionaryMapType
Definition: itkMetaDataDictionary.h:67
itk::swap
void swap(Array< T > &a, Array< T > &b) noexcept
Definition: itkArray.h:242
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::MetaDataDictionary::Iterator
MetaDataDictionaryMapType::iterator Iterator
Definition: itkMetaDataDictionary.h:68