ITK  4.4.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 "itkCommand.h"
34 #include "itkFastMutexLock.h"
35 
36 #include <cstring>
37 
38 namespace itk
39 {
72 template< class MetaDataObjectType >
73 class ITK_EXPORT MetaDataObject:public MetaDataObjectBase
74 {
75 public:
76 
82 
84  itkFactorylessNewMacro(Self);
85 
87  itkTypeMacro(MetaDataObject, MetaDataObjectBase);
88 
93  MetaDataObject(void);
94 
99  virtual ~MetaDataObject(void);
100 
105  MetaDataObject(const MetaDataObjectType InitializerValue);
106 
112 
119  virtual const char * GetMetaDataObjectTypeName(void) const;
120 
127  virtual const std::type_info & GetMetaDataObjectTypeInfo(void) const;
128 
134  const MetaDataObjectType & GetMetaDataObjectValue(void) const;
135 
141  void SetMetaDataObjectValue(const MetaDataObjectType & NewValue);
142 
147  virtual void Print(std::ostream & os) const;
148 
149 private:
150  // This is made private to force the use of the
151  // MetaDataObject<MetaDataObjectType>::New() operator!
152  //void * operator new(SizeValueType nothing) {};//purposefully not implemented
153 
158  MetaDataObjectType m_MetaDataObjectValue;
159 };
160 
170 template< class T >
171 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const std::string & key, const T & invalue)
172 {
174  temp->SetMetaDataObjectValue(invalue);
175  Dictionary[key] = temp;
176 }
178 
179 template< class T >
180 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const char *key, const T & invalue)
181 {
182  EncapsulateMetaData(Dictionary, std::string(key), invalue);
183 }
184 
194 template< class T >
195 inline bool ExposeMetaData(const MetaDataDictionary & Dictionary, const std::string key, T & outval)
196 {
197  if ( !Dictionary.HasKey(key) )
198  {
199  return false;
200  }
201 
202  const MetaDataObjectBase::ConstPointer baseObjectSmartPointer = Dictionary[key];
203 
204  if ( baseObjectSmartPointer.IsNull() || strcmp( typeid( T ).name(), baseObjectSmartPointer->GetMetaDataObjectTypeName() ) != 0 )
205  {
206  return false;
207  }
208  {
209  MetaDataObject< T > const * const TempMetaDataObject = dynamic_cast< MetaDataObject< T > const * >( baseObjectSmartPointer.GetPointer() );
210  if ( TempMetaDataObject != NULL )
211  {
212  outval = TempMetaDataObject->GetMetaDataObjectValue();
213  }
214  else
215  {
216  return false;
217  }
218  }
219  return true;
220 }
221 } // end namespace itk
222 
230 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
231  template< > \
232  void \
233  itk::MetaDataObject< TYPE_NAME > \
234  ::Print(std::ostream & os) const \
235  { \
236  os << this->m_MetaDataObjectValue << std::endl; \
237  } \
238  template< > \
239  void \
240  itk::MetaDataObject< const TYPE_NAME > \
241  ::Print(std::ostream & os) const \
242  { \
243  os << this->m_MetaDataObjectValue << std::endl; \
244  }
245 
246 
255 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1, TYPE_NAME_PART2) \
256  template< > \
257  void \
258  itk::MetaDataObject< TYPE_NAME_PART1, TYPE_NAME_PART2 > \
259  ::Print(std::ostream & os) const \
260  { \
261  this->m_MetaDataObjectValue->Print(os); \
262  } \
263  template< > \
264  void \
265  itk::MetaDataObject< const TYPE_NAME_PART1, TYPE_NAME_PART2 > \
266  ::Print(std::ostream & os) const \
267  { \
268  this->m_MetaDataObjectValue->Print(os); \
269  }
270 
271 
279 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
280  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 1 >::Pointer) \
281  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 2 >::Pointer) \
282  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 3 >::Pointer) \
283  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 4 >::Pointer) \
284  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 5 >::Pointer) \
285  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 6 >::Pointer) \
286  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 7 >::Pointer) \
287  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 8 >::Pointer) \
288 
289 #ifndef ITK_MANUAL_INSTANTIATION
290 #include "itkMetaDataObject.hxx"
291 #endif
292 
293 #endif //itkMetaDataObject_h
294