ITK  5.3.0
Insight Toolkit
itkMetaDataObject.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  * http://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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkMetaDataObject_h
29 #define itkMetaDataObject_h
30 
31 #include "itkMetaDataDictionary.h"
32 #include "itkMacro.h"
33 #include "itkArray.h"
34 #include "itkMatrix.h"
35 
36 #include <cstring>
37 
38 namespace itk
39 {
74 template <typename MetaDataObjectType>
75 class ITK_TEMPLATE_EXPORT MetaDataObject : public MetaDataObjectBase
76 {
77 public:
78  ITK_DISALLOW_COPY_AND_MOVE(MetaDataObject);
79 
85 
87  itkFactorylessNewMacro(Self);
88 
90  itkTypeMacro(MetaDataObject, MetaDataObjectBase);
91 
98  const char *
99  GetMetaDataObjectTypeName() const override;
100 
107  const std::type_info &
108  GetMetaDataObjectTypeInfo() const override;
109 
115  const MetaDataObjectType &
116  GetMetaDataObjectValue() const;
117 
123  void
124  SetMetaDataObjectValue(const MetaDataObjectType & newValue);
125 
130  void
131  Print(std::ostream & os) const override;
132 
134  friend bool
135  operator==(const Self & lhs, const Self & rhs)
136  {
138  }
139 
141  friend bool
142  operator!=(const Self & lhs, const Self & rhs)
143  {
144  return !(lhs == rhs);
145  }
146 
147 protected:
148  MetaDataObject() = default;
149  ~MetaDataObject() override = default;
150 
151 private:
153  bool
154  Equal(const MetaDataObjectBase & metaDataObjectBase) const override
155  {
156  const auto metaDataObject = dynamic_cast<const Self *>(&metaDataObjectBase);
157  return (metaDataObject != nullptr) && (*this == *metaDataObject);
158  }
160 
165  MetaDataObjectType m_MetaDataObjectValue;
166 };
167 
177 template <typename T>
178 inline void
179 EncapsulateMetaData(MetaDataDictionary & Dictionary, const std::string & key, const T & invalue)
180 {
182  temp->SetMetaDataObjectValue(invalue);
183  Dictionary[key] = temp;
184 }
186 
187 template <typename T>
188 inline void
189 EncapsulateMetaData(MetaDataDictionary & Dictionary, const char * key, const T & invalue)
190 {
191  EncapsulateMetaData(Dictionary, std::string(key), invalue);
192 }
193 
203 template <typename T>
204 inline bool
205 ExposeMetaData(const MetaDataDictionary & Dictionary, const std::string key, T & outval)
206 {
207  auto keyIter = Dictionary.Find(key);
208  if (keyIter == Dictionary.End())
209  {
210  return false;
211  }
213 
214  auto const * const TempMetaDataObject = dynamic_cast<MetaDataObject<T> const *>(keyIter->second.GetPointer());
215  if (TempMetaDataObject == nullptr)
216  {
217  return false;
218  }
219 
220  outval = TempMetaDataObject->GetMetaDataObjectValue();
221  return true;
222 }
223 
224 } // end namespace itk
225 
233 #define ITK_NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
234  template <> \
235  void ::itk::MetaDataObject<TYPE_NAME>::Print(std::ostream & os) const \
236  { \
237  os << this->m_MetaDataObjectValue << std::endl; \
238  }
239 
248 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1, TYPE_NAME_PART2) \
249  template <> \
250  void itk::MetaDataObject<TYPE_NAME_PART1, TYPE_NAME_PART2>::Print(std::ostream & os) const \
251  { \
252  this->m_MetaDataObjectValue->Print(os); \
253  }
254 
262 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
263  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 1>::Pointer) \
264  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 2>::Pointer) \
265  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 3>::Pointer) \
266  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 4>::Pointer) \
267  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 5>::Pointer) \
268  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 6>::Pointer) \
269  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 7>::Pointer) \
270  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 8>::Pointer)
271 
272 #ifndef ITK_MANUAL_INSTANTIATION
273 # include "itkMetaDataObject.hxx"
274 #endif
275 
276 #endif // itkMetaDataObject_h
277 
279 #ifndef ITK_TEMPLATE_EXPLICIT_MetaDataObject
280 // Explicit instantiation is required to ensure correct dynamic_cast
281 // behavior across shared libraries.
282 //
283 // IMPORTANT: Since within the same compilation unit,
284 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
285 // need to be considered. This code *MUST* be *OUTSIDE* the header
286 // guards.
287 //
288 #if defined(ITKCommon_EXPORTS)
289 // We are building this library
290 # define ITKCommon_EXPORT_EXPLICIT ITK_TEMPLATE_EXPORT
291 #else
292 // We are using this library
293 # define ITKCommon_EXPORT_EXPLICIT ITKCommon_EXPORT
294 #endif
295 namespace itk
296 {
297 
298 ITK_GCC_PRAGMA_DIAG_PUSH()
299 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
300 
301 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<bool>;
302 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned char>;
303 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<char>;
304 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<signed char>;
305 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned short>;
306 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<short>;
307 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned int>;
308 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<int>;
309 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned long>;
310 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<long>;
311 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned long long>;
312 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<long long>;
313 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<float>;
314 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<double>;
315 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::string>;
316 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::vector<float>>;
317 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::vector<double>>;
318 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::vector<std::vector<float>>>;
319 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::vector<std::vector<double>>>;
320 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Array<char>>;
321 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Array<int>>;
322 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Array<float>>;
323 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Array<double>>;
324 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Matrix<double>>;
325 
326 ITK_GCC_PRAGMA_DIAG_POP()
327 
328 } // end namespace itk
329 #undef ITKCommon_EXPORT_EXPLICIT
330 #endif
itk::MetaDataObject
Allows arbitrary data types to be stored as MetaDataObjectBase types, and to be stored in a MetaDataD...
Definition: itkMetaDataObject.h:75
itk::MetaDataObject::GetMetaDataObjectValue
const MetaDataObjectType & GetMetaDataObjectValue() const
itk::EncapsulateMetaData
void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string &key, const T &invalue)
Definition: itkMetaDataObject.h:179
itkMatrix.h
itk::MetaDataObjectBase
The common interface for MetaDataObject's.
Definition: itkMetaDataObjectBase.h:47
itk::MetaDataObject::operator==
friend bool operator==(const Self &lhs, const Self &rhs)
Definition: itkMetaDataObject.h:135
itk::MetaDataObject::operator!=
friend bool operator!=(const Self &lhs, const Self &rhs)
Definition: itkMetaDataObject.h:142
itk::SmartPointer< Self >
itk::MetaDataObject::m_MetaDataObjectValue
MetaDataObjectType m_MetaDataObjectValue
Definition: itkMetaDataObject.h:165
itk::MetaDataDictionary
Provides a mechanism for storing a collection of arbitrary data types.
Definition: itkMetaDataDictionary.h:54
itk::MetaDataDictionary::Find
Iterator Find(const std::string &key)
itkMacro.h
itk::ExposeMetaData
bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
Definition: itkMetaDataObject.h:205
itk::MetaDataObject::Equal
bool Equal(const MetaDataObjectBase &metaDataObjectBase) const override
Definition: itkMetaDataObject.h:154
itkArray.h
itkMetaDataDictionary.h
itk::MetaDataDictionary::End
Iterator End()
ITKCommon_EXPORT_EXPLICIT
#define ITKCommon_EXPORT_EXPLICIT
Definition: itkMetaDataObject.h:293
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::MetaDataObject::New
static Pointer New()