ITK  5.2.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 
133 protected:
134  MetaDataObject() = default;
135  ~MetaDataObject() override = default;
136 
137 private:
142  MetaDataObjectType m_MetaDataObjectValue;
143 };
144 
154 template <typename T>
155 inline void
156 EncapsulateMetaData(MetaDataDictionary & Dictionary, const std::string & key, const T & invalue)
157 {
159  temp->SetMetaDataObjectValue(invalue);
160  Dictionary[key] = temp;
161 }
163 
164 template <typename T>
165 inline void
166 EncapsulateMetaData(MetaDataDictionary & Dictionary, const char * key, const T & invalue)
167 {
168  EncapsulateMetaData(Dictionary, std::string(key), invalue);
169 }
170 
180 template <typename T>
181 inline bool
182 ExposeMetaData(const MetaDataDictionary & Dictionary, const std::string key, T & outval)
183 {
184  auto keyIter = Dictionary.Find(key);
185  if (keyIter == Dictionary.End())
186  {
187  return false;
188  }
190 
191  auto const * const TempMetaDataObject = dynamic_cast<MetaDataObject<T> const *>(keyIter->second.GetPointer());
192  if (TempMetaDataObject == nullptr)
193  {
194  return false;
195  }
196 
197  outval = TempMetaDataObject->GetMetaDataObjectValue();
198  return true;
199 }
200 
201 } // end namespace itk
202 
210 #define ITK_NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
211  template <> \
212  void ::itk::MetaDataObject<TYPE_NAME>::Print(std::ostream & os) const \
213  { \
214  os << this->m_MetaDataObjectValue << std::endl; \
215  }
216 
225 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1, TYPE_NAME_PART2) \
226  template <> \
227  void itk::MetaDataObject<TYPE_NAME_PART1, TYPE_NAME_PART2>::Print(std::ostream & os) const \
228  { \
229  this->m_MetaDataObjectValue->Print(os); \
230  }
231 
239 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
240  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 1>::Pointer) \
241  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 2>::Pointer) \
242  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 3>::Pointer) \
243  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 4>::Pointer) \
244  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 5>::Pointer) \
245  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 6>::Pointer) \
246  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 7>::Pointer) \
247  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image<STORAGE_TYPE, 8>::Pointer)
248 
249 #ifndef ITK_MANUAL_INSTANTIATION
250 # include "itkMetaDataObject.hxx"
251 #endif
252 
253 #endif // itkMetaDataObject_h
254 
256 #ifndef ITK_TEMPLATE_EXPLICIT_MetaDataObject
257 // Explicit instantiation is required to ensure correct dynamic_cast
258 // behavior across shared libraries.
259 //
260 // IMPORTANT: Since within the same compilation unit,
261 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
262 // need to be considered. This code *MUST* be *OUTSIDE* the header
263 // guards.
264 //
265 #if defined(ITKCommon_EXPORTS)
266 // We are building this library
267 # define ITKCommon_EXPORT_EXPLICIT ITK_TEMPLATE_EXPORT
268 #else
269 // We are using this library
270 # define ITKCommon_EXPORT_EXPLICIT ITKCommon_EXPORT
271 #endif
272 namespace itk
273 {
274 
275 ITK_GCC_PRAGMA_DIAG_PUSH()
276 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
277 
278 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<bool>;
279 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned char>;
280 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<char>;
281 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<signed char>;
282 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned short>;
283 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<short>;
284 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned int>;
285 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<int>;
286 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned long>;
287 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<long>;
288 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<unsigned long long>;
289 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<long long>;
290 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<float>;
291 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<double>;
292 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::string>;
293 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::vector<float>>;
294 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::vector<double>>;
295 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::vector<std::vector<float>>>;
296 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<std::vector<std::vector<double>>>;
297 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Array<char>>;
298 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Array<int>>;
299 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Array<float>>;
300 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Array<double>>;
301 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject<Matrix<double>>;
302 
303 ITK_GCC_PRAGMA_DIAG_POP()
304 
305 } // end namespace itk
306 #undef ITKCommon_EXPORT_EXPLICIT
307 #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:156
itkMatrix.h
itk::MetaDataObjectBase
The common interface for MetaDataObject's.
Definition: itkMetaDataObjectBase.h:47
itk::SmartPointer< Self >
itk::MetaDataObject::m_MetaDataObjectValue
MetaDataObjectType m_MetaDataObjectValue
Definition: itkMetaDataObject.h:142
itk::MetaDataDictionary
Provides a mechanism for storing a collection of arbitrary data types.
Definition: itkMetaDataDictionary.h:53
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
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:182
itkArray.h
itkMetaDataDictionary.h
itk::MetaDataDictionary::End
Iterator End()
ITKCommon_EXPORT_EXPLICIT
#define ITKCommon_EXPORT_EXPLICIT
Definition: itkMetaDataObject.h:270
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::MetaDataObject::New
static Pointer New()