ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkMetaDataObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 {
72 template< typename MetaDataObjectType >
73 class ITK_TEMPLATE_EXPORT MetaDataObject:public MetaDataObjectBase
74 {
75 public:
76  ITK_DISALLOW_COPY_AND_ASSIGN(MetaDataObject);
77 
83 
85  itkFactorylessNewMacro(Self);
86 
88  itkTypeMacro(MetaDataObject, MetaDataObjectBase);
89 
96  const char * GetMetaDataObjectTypeName() const override;
97 
104  const std::type_info & GetMetaDataObjectTypeInfo() const override;
105 
111  const MetaDataObjectType & GetMetaDataObjectValue() const;
112 
118  void SetMetaDataObjectValue(const MetaDataObjectType & newValue);
119 
124  void Print(std::ostream & os) const override;
125 
126 protected:
127  MetaDataObject() = default;
128  ~MetaDataObject() override = default;
129 
130 private:
135  MetaDataObjectType m_MetaDataObjectValue;
136 };
137 
147 template< typename T >
148 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const std::string & key, const T & invalue)
149 {
151  temp->SetMetaDataObjectValue(invalue);
152  Dictionary[key] = temp;
153 }
155 
156 template< typename T >
157 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const char *key, const T & invalue)
158 {
159  EncapsulateMetaData(Dictionary, std::string(key), invalue);
160 }
161 
171 template< typename T >
172 inline bool ExposeMetaData(const MetaDataDictionary & Dictionary, const std::string key, T & outval)
173 {
174  auto keyIter = Dictionary.Find(key);
175  if ( keyIter == Dictionary.End() )
176  {
177  return false;
178  }
180 
181  auto const * const TempMetaDataObject = dynamic_cast< MetaDataObject< T > const * >( keyIter->second.GetPointer() );
182  if ( TempMetaDataObject == nullptr )
183  {
184  return false;
185  }
186 
187  outval = TempMetaDataObject->GetMetaDataObjectValue();
188  return true;
189 }
190 
191 } // end namespace itk
192 
200 #define ITK_NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
201  template< > \
202  void \
203  ::itk::MetaDataObject< TYPE_NAME > \
204  ::Print(std::ostream & os) const \
205  { \
206  os << this->m_MetaDataObjectValue << std::endl; \
207  } \
208 
209 
217 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1, TYPE_NAME_PART2) \
218  template< > \
219  void \
220  itk::MetaDataObject< TYPE_NAME_PART1, TYPE_NAME_PART2 > \
221  ::Print(std::ostream & os) const \
222  { \
223  this->m_MetaDataObjectValue->Print(os); \
224  } \
225 
226 
233 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
234  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 1 >::Pointer) \
235  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 2 >::Pointer) \
236  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 3 >::Pointer) \
237  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 4 >::Pointer) \
238  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 5 >::Pointer) \
239  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 6 >::Pointer) \
240  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 7 >::Pointer) \
241  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 8 >::Pointer) \
242 
243 #ifndef ITK_MANUAL_INSTANTIATION
244 #include "itkMetaDataObject.hxx"
245 #endif
246 
247 #endif //itkMetaDataObject_h
248 
250 #ifndef ITK_TEMPLATE_EXPLICIT_MetaDataObject
251 // Explicit instantiation is required to ensure correct dynamic_cast
252 // behavior across shared libraries.
253 //
254 // IMPORTANT: Since within the same compilation unit,
255 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
256 // need to be considered. This code *MUST* be *OUTSIDE* the header
257 // guards.
258 //
259 # if defined( ITKCommon_EXPORTS )
260 // We are building this library
261 # define ITKCommon_EXPORT_EXPLICIT ITK_TEMPLATE_EXPORT
262 # else
263 // We are using this library
264 # define ITKCommon_EXPORT_EXPLICIT ITKCommon_EXPORT
265 # endif
266 namespace itk
267 {
268 
269 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
270  ITK_GCC_PRAGMA_DIAG_PUSH()
271 #endif
272 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
273 
274 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< bool >;
275 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned char >;
276 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< char >;
277 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< signed char >;
278 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned short >;
279 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< short >;
280 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned int >;
281 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< int >;
282 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned long >;
283 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< long >;
284 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned long long >;
285 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< long long >;
286 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< float >;
287 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< double >;
288 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::string >;
289 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<float> >;
290 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<double> >;
291 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<std::vector<float> > >;
292 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<std::vector<double> > >;
293 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<char> >;
294 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<int> >;
295 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<float> >;
296 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<double> >;
297 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Matrix<double> >;
298 
299 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
300  ITK_GCC_PRAGMA_DIAG_POP()
301 #else
302  ITK_GCC_PRAGMA_DIAG(warning "-Wattributes")
303 #endif
304 
305 } // end namespace itk
306 # undef ITKCommon_EXPORT_EXPLICIT
307 #endif
Light weight base class for most itk classes.
void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string &key, const T &invalue)
MetaDataObjectType m_MetaDataObjectValue
const MetaDataObjectType & GetMetaDataObjectValue() const
#define ITKCommon_EXPORT_EXPLICIT
static Pointer New()
Allows arbitrary data types to be stored as MetaDataObjectBase types, and to be stored in a MetaDataD...
Provides a mechanism for storing a collection of arbitrary data types.
bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
Iterator Find(const std::string &key)
The common interface for MetaDataObject&#39;s.