Orfeo Toolbox  3.16
itkMetaDataObject.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkMetaDataObject.h,v $
5  Language: C++
6  Date: $Date: 2009-06-14 09:20:22 $
7  Version: $Revision: 1.27 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  Portions of this code are covered under the VTK copyright.
13  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 #ifndef __itkMetaDataObject_h
21 #define __itkMetaDataObject_h
22 
23 #include "itkMetaDataDictionary.h"
24 #include "itkMacro.h"
25 #include "itkObjectFactory.h"
26 #include "itkCommand.h"
27 #include "itkFastMutexLock.h"
28 
29 #include <string.h>
30 #include <cstring>
31 
32 namespace itk
33 {
61 template <class MetaDataObjectType>
63 {
64 public:
70 
72  itkFactorylessNewMacro(Self);
73 
75  itkTypeMacro(MetaDataObject, MetaDataObjectBase);
76 
81  MetaDataObject(void);
85  virtual ~MetaDataObject(void);
90  MetaDataObject(const MetaDataObjectType InitializerValue);
103  virtual const char * GetMetaDataObjectTypeName(void) const;
111  virtual const std::type_info & GetMetaDataObjectTypeInfo(void) const;
117  const MetaDataObjectType & GetMetaDataObjectValue(void) const;
123  void SetMetaDataObjectValue(const MetaDataObjectType & NewValue );
128  virtual void Print(std::ostream& os) const;
129 private:
130  //This is made private to force the use of the MetaDataObject<MetaDataObjectType>::New() operator!
131  //void * operator new(size_t nothing) {}; //purposefully not implemented
136  MetaDataObjectType m_MetaDataObjectValue;
137 };
138 
139 
149 template <class T>
150 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string & key, const T &invalue)
151 {
153  temp->SetMetaDataObjectValue(invalue);
154  Dictionary[key] = temp;
155 }
156 
157 template <class T>
158 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const char *key, const T &invalue)
159 {
160  EncapsulateMetaData(Dictionary, std::string(key), invalue);
161 }
162 
172 template <class T>
173 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const std::string key, T &outval)
174 {
175  if(!Dictionary.HasKey(key))
176  {
177  return false;
178  }
179 
180  MetaDataObjectBase::Pointer baseObjectSmartPointer = Dictionary[key];
181 
182  if(strcmp(typeid(T).name(),baseObjectSmartPointer->GetMetaDataObjectTypeName()) != 0)
183  {
184  return false;
185  }
186  //The following is necessary for getting this to work on
187  //kitware's SGI computers. It is not necessary for
188  //for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
189 #if (defined(__sgi) && !defined(__GNUC__))
190 
200  outval =
201  reinterpret_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())->GetMetaDataObjectValue();
202 #else
203  {
204  if(MetaDataObject <T> * TempMetaDataObject =dynamic_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer()))
205  {
206  outval = TempMetaDataObject->GetMetaDataObjectValue();
207  }
208  else
209  {
210  return false;
211  }
212  }
213 #endif
214  // --------------- ^^^^^^^^^^^^
215  // SmartPointer MetaDataObject<T>*
216  return true;
217 }
218 
219 //This is only necessary to make the borland compiler happy. It should not be necesary for most compilers.
220 //This should not change the behavior, it just adds an extra level of complexity to using the ExposeMetaData
221 //with const char * keys.
222 template <class T>
223 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const char * const key, T &outval)
224 {
225  return ExposeMetaData(Dictionary, std::string(key), outval);
226 }
227 // const versions of ExposeMetaData just to make life easier for enduser programmers, and to maintain backwards compatibility.
228 // The other option is to cast away constness in the main function.
229 template <class T>
230 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
231 {
232  MetaDataDictionary NonConstVersion=Dictionary;
233  return ExposeMetaData(NonConstVersion,key,outval);
234 }
235 
236 template <class T>
237 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const char * const key, T &outval)
238 {
239  MetaDataDictionary NonConstVersion=Dictionary;
240  return ExposeMetaData(Dictionary, std::string(key), outval);
241 }
242 
243 } // end namespace itk
244 
252 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
253 template <> \
254 void \
255  itk::MetaDataObject< TYPE_NAME > \
256  ::Print(std::ostream& os) const \
257 { \
258  os << this->m_MetaDataObjectValue << std::endl; \
259 } \
260 template <> \
261 void \
262  itk::MetaDataObject< const TYPE_NAME > \
263  ::Print(std::ostream& os) const \
264 { \
265  os << this->m_MetaDataObjectValue << std::endl; \
266 }
267 
276 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA( TYPE_NAME_PART1 , TYPE_NAME_PART2 ) \
277 template <> \
278 void \
279  itk::MetaDataObject< TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
280  ::Print(std::ostream& os) const \
281 { \
282  this->m_MetaDataObjectValue->Print(os); \
283 } \
284 template <> \
285 void \
286  itk::MetaDataObject< const TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
287  ::Print(std::ostream& os) const \
288 { \
289  this->m_MetaDataObjectValue->Print(os); \
290 }
291 
299 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
300  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 1 >::Pointer) \
301  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 2 >::Pointer) \
302  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 3 >::Pointer) \
303  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 4 >::Pointer) \
304  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 5 >::Pointer) \
305  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 6 >::Pointer) \
306  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 7 >::Pointer) \
307  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 8 >::Pointer) \
308 
309 // Define instantiation macro for this template.
310 #define ITK_TEMPLATE_MetaDataObject(_, EXPORT, x, y) namespace itk { \
311  _(1(class EXPORT MetaDataObject< ITK_TEMPLATE_1 x >)) \
312  namespace Templates { typedef MetaDataObject< ITK_TEMPLATE_1 x > \
313  MetaDataObject##y; } \
314  }
315 
316 #if ITK_TEMPLATE_EXPLICIT
317 # include "Templates/itkMetaDataObject+-.h"
318 #endif
319 
320 #if ITK_TEMPLATE_TXX
321 # include "itkMetaDataObject.txx"
322 #endif
323 
324 
325 #endif //itkMetaDataObject_h

Generated at Sat Feb 2 2013 23:52:44 for Orfeo Toolbox with doxygen 1.8.1.1