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.
124  MetaDataObjectBase::Pointer & operator[](const std::string &);
125 
126  // \brief Get a constant point to a DataObject
127  //
128  // If the key does not exist then nullptr is returned.
129  const MetaDataObjectBase * operator[](const std::string &) const;
130 
131  const MetaDataObjectBase *
132  Get(const std::string &) const;
133  void
134  Set(const std::string &, MetaDataObjectBase *);
135  bool
136  HasKey(const std::string &) const;
137 
138  bool
139  Erase(const std::string &);
140 
146  // Blacklisted by igenerator.py
147  Iterator
148  Begin();
149  // Blacklisted by igenerator.py
150  ConstIterator
151  Begin() const;
155  // Blacklisted by igenerator.py
156  Iterator
157  End();
158  // Blacklisted by igenerator.py
159  ConstIterator
160  End() const;
164  Iterator
165  Find(const std::string & key);
166 
167  ConstIterator
168  Find(const std::string & key) const;
169 
171  void
172  Clear();
173 
174  void
175  Swap(MetaDataDictionary & other);
176 
177 private:
178  bool
179  MakeUnique();
180 
181  std::shared_ptr<MetaDataDictionaryMapType> m_Dictionary{};
182 };
183 
184 inline void
186 {
187  a.Swap(b);
188 }
189 
190 } // namespace itk
191 #endif // itkMetaDataDictionary_h
itk::MetaDataDictionary::m_Dictionary
std::shared_ptr< MetaDataDictionaryMapType > m_Dictionary
Definition: itkMetaDataDictionary.h:181
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::Swap
void Swap(MetaDataDictionary &other)
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