Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkMetaDataObject.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMetaDataObject.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-06-14 09:20:22 $
00007   Version:   $Revision: 1.27 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012   Portions of this code are covered under the VTK copyright.
00013   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
00014 
00015      This software is distributed WITHOUT ANY WARRANTY; without even 
00016      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00017      PURPOSE.  See the above copyright notices for more information.
00018 
00019 =========================================================================*/
00020 #ifndef __itkMetaDataObject_h
00021 #define __itkMetaDataObject_h
00022 
00023 #include "itkMetaDataDictionary.h"
00024 #include "itkMacro.h"
00025 #include "itkObjectFactory.h"
00026 #include "itkCommand.h"
00027 #include "itkFastMutexLock.h"
00028 
00029 #include <string.h>
00030 #include <cstring>
00031 
00032 namespace itk
00033 {
00061 template <class MetaDataObjectType>
00062 class ITK_EXPORT MetaDataObject: public MetaDataObjectBase
00063 {
00064 public:
00065 
00067   typedef MetaDataObject            Self;
00068   typedef MetaDataObjectBase        Superclass;
00069   typedef SmartPointer<Self>        Pointer;
00070   typedef SmartPointer<const Self>  ConstPointer;
00071 
00073   itkFactorylessNewMacro(Self);
00074 
00076   itkTypeMacro(MetaDataObject, MetaDataObjectBase);
00077 
00082   MetaDataObject(void);
00083 
00087   virtual ~MetaDataObject(void);
00088 
00093   MetaDataObject(const MetaDataObjectType InitializerValue);
00094 
00099   MetaDataObject(const MetaDataObject<MetaDataObjectType> &TemplateObject);
00100 
00108   virtual const char * GetMetaDataObjectTypeName(void) const;
00109 
00117   virtual const std::type_info & GetMetaDataObjectTypeInfo(void) const;
00118 
00124   const MetaDataObjectType & GetMetaDataObjectValue(void) const;
00125 
00131   void SetMetaDataObjectValue(const MetaDataObjectType & NewValue );
00132 
00137   virtual void Print(std::ostream& os) const;
00138 private:
00139   //This is made private to force the use of the MetaDataObject<MetaDataObjectType>::New() operator!
00140   //void * operator new(size_t nothing) {};//purposefully not implemented
00141 
00146   MetaDataObjectType m_MetaDataObjectValue;
00147 };
00148 
00149 
00159 template <class T>
00160 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string & key, const T &invalue)
00161 {
00162   typename MetaDataObject<T>::Pointer temp=MetaDataObject<T>::New();
00163   temp->SetMetaDataObjectValue(invalue);
00164   Dictionary[key] = temp;
00165 }
00167 
00168 template <class T>
00169 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const char *key, const T &invalue)
00170 {
00171   EncapsulateMetaData(Dictionary, std::string(key), invalue);
00172 }
00173 
00183 template <class T>
00184 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const std::string key, T &outval)
00185 {
00186   if(!Dictionary.HasKey(key))
00187     {
00188     return false;
00189     }
00190 
00191   MetaDataObjectBase::Pointer baseObjectSmartPointer = Dictionary[key];
00192   
00193   if(strcmp(typeid(T).name(),baseObjectSmartPointer->GetMetaDataObjectTypeName()) != 0)
00194     {
00195     return false;
00196     }
00197   //The following is necessary for getting this to work on
00198   //kitware's SGI computers.  It is not necessary for
00199   //for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
00200 #if (defined(__sgi) && !defined(__GNUC__))
00201 
00211   outval =
00212     reinterpret_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())->GetMetaDataObjectValue();
00213 #else
00214     {
00215     if(MetaDataObject <T> * TempMetaDataObject =dynamic_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer()))
00216       {
00217       outval = TempMetaDataObject->GetMetaDataObjectValue();
00218       }
00219     else
00220       {
00221       return false;
00222       }
00223     }
00224 #endif
00225   //                                 --------------- ^^^^^^^^^^^^
00226   //                                 SmartPointer    MetaDataObject<T>*
00227   return true;
00228 }
00230 
00231 //This is only necessary to make the borland compiler happy.  It should not be necesary for most compilers.
00232 //This should not change the behavior, it just adds an extra level of complexity to using the ExposeMetaData
00233 //with const char * keys.
00234 template <class T>
00235 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const char * const key, T &outval)
00236 {
00237   return ExposeMetaData(Dictionary, std::string(key), outval);
00238 }
00239 // const versions of ExposeMetaData just to make life easier for enduser programmers, and to maintain backwards compatibility.
00240 // The other option is to cast away constness in the main function.
00241 template <class T>
00242 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
00243 {
00244   MetaDataDictionary NonConstVersion=Dictionary;
00245   return ExposeMetaData(NonConstVersion,key,outval);
00246 }
00247 
00248 template <class T>
00249 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const char * const key, T &outval)
00250 {
00251   MetaDataDictionary NonConstVersion=Dictionary;
00252   return ExposeMetaData(Dictionary, std::string(key), outval);
00253 }
00254 
00255 } // end namespace itk
00256 
00264 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
00265 template <> \
00266 void \
00267   itk::MetaDataObject< TYPE_NAME > \
00268   ::Print(std::ostream& os) const \
00269 { \
00270   os << this->m_MetaDataObjectValue << std::endl; \
00271 } \
00272 template <> \
00273 void \
00274   itk::MetaDataObject< const TYPE_NAME > \
00275   ::Print(std::ostream& os) const \
00276 { \
00277   os << this->m_MetaDataObjectValue << std::endl; \
00278 }
00279 
00280 
00289 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA( TYPE_NAME_PART1 , TYPE_NAME_PART2 ) \
00290 template <> \
00291 void \
00292   itk::MetaDataObject< TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00293   ::Print(std::ostream& os) const \
00294 { \
00295   this->m_MetaDataObjectValue->Print(os); \
00296 } \
00297 template <> \
00298 void \
00299   itk::MetaDataObject< const TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00300   ::Print(std::ostream& os) const \
00301 { \
00302   this->m_MetaDataObjectValue->Print(os); \
00303 }
00304 
00305 
00313 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
00314   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 1 >::Pointer) \
00315   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 2 >::Pointer) \
00316   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 3 >::Pointer) \
00317   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 4 >::Pointer) \
00318   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 5 >::Pointer) \
00319   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 6 >::Pointer) \
00320   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 7 >::Pointer) \
00321   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 8 >::Pointer) \
00322 
00323 // Define instantiation macro for this template.
00324 #define ITK_TEMPLATE_MetaDataObject(_, EXPORT, x, y) namespace itk { \
00325   _(1(class EXPORT MetaDataObject< ITK_TEMPLATE_1 x >)) \
00326   namespace Templates { typedef MetaDataObject< ITK_TEMPLATE_1 x > \
00327                                          MetaDataObject##y; } \
00328   }
00329 
00330 #if ITK_TEMPLATE_EXPLICIT
00331 # include "Templates/itkMetaDataObject+-.h"
00332 #endif
00333 
00334 #if ITK_TEMPLATE_TXX
00335 # include "itkMetaDataObject.txx"
00336 #endif
00337 
00338 
00339 #endif //itkMetaDataObject_h
00340 

Generated at Mon Jul 12 2010 19:08:35 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000