ITK  5.4.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
22#include <algorithm> // For std::equal
23#include <vector>
24#include <map>
25#include <string>
26#include <memory>
27
28namespace itk
29{
54class ITKCommon_EXPORT MetaDataDictionary
55{
56public:
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 =
81
82 // Destructor
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
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
149 // Blacklisted by igenerator.py
151 Begin() const;
155 // Blacklisted by igenerator.py
158 // Blacklisted by igenerator.py
160 End() const;
165 Find(const std::string & key);
166
168 Find(const std::string & key) const;
169
171 void
173
174 void
176
177private:
178 bool
180
181 std::shared_ptr<MetaDataDictionaryMapType> m_Dictionary{};
182};
183
184inline void
186{
187 a.Swap(b);
188}
189
190} // namespace itk
191#endif // itkMetaDataDictionary_h
Provides a mechanism for storing a collection of arbitrary data types.
friend bool operator==(const Self &lhs, const Self &rhs)
std::shared_ptr< MetaDataDictionaryMapType > m_Dictionary
const MetaDataObjectBase * operator[](const std::string &) const
MetaDataDictionary & operator=(MetaDataDictionary &&)=default
ConstIterator End() const
const MetaDataObjectBase * Get(const std::string &) const
ConstIterator Find(const std::string &key) const
virtual void Print(std::ostream &os) const
std::map< std::string, MetaDataObjectBase::Pointer > MetaDataDictionaryMapType
friend bool operator!=(const Self &lhs, const Self &rhs)
bool Erase(const std::string &)
Iterator Find(const std::string &key)
void Set(const std::string &, MetaDataObjectBase *)
bool HasKey(const std::string &) const
void Swap(MetaDataDictionary &other)
ConstIterator Begin() const
MetaDataDictionary(MetaDataDictionary &&)=default
MetaDataDictionary(const MetaDataDictionary &)
MetaDataDictionaryMapType::iterator Iterator
std::vector< std::string > GetKeys() const
MetaDataDictionaryMapType::const_iterator ConstIterator
MetaDataObjectBase::Pointer & operator[](const std::string &)
MetaDataDictionary & operator=(const MetaDataDictionary &)
The common interface for MetaDataObject's.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void swap(Array< T > &a, Array< T > &b)
Definition: itkArray.h:242