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-02-17 08:35:34 $
00007   Version:   $Revision: 1.25 $
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>
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 
00157 template <class T>
00158 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string & key, const T &invalue)
00159 {
00160   typename MetaDataObject<T>::Pointer temp=MetaDataObject<T>::New();
00161   temp->SetMetaDataObjectValue(invalue);
00162   Dictionary[key] = temp;
00163 }
00165 
00166 template <class T>
00167 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const char *key, const T &invalue)
00168 {
00169   EncapsulateMetaData(Dictionary, std::string(key), invalue);
00170 }
00171 
00181 template <class T>
00182 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const std::string key, T &outval)
00183 {
00184   if(!Dictionary.HasKey(key))
00185     {
00186     return false;
00187     }
00188 
00189   MetaDataObjectBase::Pointer baseObjectSmartPointer = Dictionary[key];
00190   
00191   if(strcmp(typeid(T).name(),baseObjectSmartPointer->GetMetaDataObjectTypeName()) != 0)
00192     {
00193     return false;
00194     }
00195   //The following is necessary for getting this to work on
00196   //kitware's SGI computers.  It is not necessary for
00197   //for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
00198 #if (defined(__sgi) && !defined(__GNUC__))
00199 
00209   outval =
00210     reinterpret_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())->GetMetaDataObjectValue();
00211 #else
00212     {
00213     if(MetaDataObject <T> * TempMetaDataObject =dynamic_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer()))
00214       {
00215       outval = TempMetaDataObject->GetMetaDataObjectValue();
00216       }
00217     else
00218       {
00219       return false;
00220       }
00221     }
00222 #endif
00223   //                                 --------------- ^^^^^^^^^^^^
00224   //                                 SmartPointer    MetaDataObject<T>*
00225   return true;
00226 }
00228 
00229 //This is only necessary to make the borland compiler happy.  It should not be necesary for most compilers.
00230 //This should not change the behavior, it just adds an extra level of complexity to using the ExposeMetaData
00231 //with const char * keys.
00232 template <class T>
00233 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const char * const key, T &outval)
00234 {
00235   return ExposeMetaData(Dictionary, std::string(key), outval);
00236 }
00237 // const versions of ExposeMetaData just to make life easier for enduser programmers, and to maintain backwards compatibility.
00238 // The other option is to cast away constness in the main function.
00239 template <class T>
00240 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
00241 {
00242   MetaDataDictionary NonConstVersion=Dictionary;
00243   return ExposeMetaData(NonConstVersion,key,outval);
00244 }
00245 
00246 template <class T>
00247 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const char * const key, T &outval)
00248 {
00249   MetaDataDictionary NonConstVersion=Dictionary;
00250   return ExposeMetaData(Dictionary, std::string(key), outval);
00251 }
00252 
00253 } // end namespace itk
00254 
00262 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
00263 template <> \
00264 void \
00265   itk::MetaDataObject< TYPE_NAME > \
00266   ::Print(std::ostream& os) const \
00267 { \
00268   os << this->m_MetaDataObjectValue << std::endl; \
00269 } \
00270 template <> \
00271 void \
00272   itk::MetaDataObject< const TYPE_NAME > \
00273   ::Print(std::ostream& os) const \
00274 { \
00275   os << this->m_MetaDataObjectValue << std::endl; \
00276 }
00277 
00278 
00287 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA( TYPE_NAME_PART1 , TYPE_NAME_PART2 ) \
00288 template <> \
00289 void \
00290   itk::MetaDataObject< TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00291   ::Print(std::ostream& os) const \
00292 { \
00293   this->m_MetaDataObjectValue->Print(os); \
00294 } \
00295 template <> \
00296 void \
00297   itk::MetaDataObject< const TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00298   ::Print(std::ostream& os) const \
00299 { \
00300   this->m_MetaDataObjectValue->Print(os); \
00301 }
00302 
00303 
00311 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
00312   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 1 >::Pointer) \
00313   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 2 >::Pointer) \
00314   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 3 >::Pointer) \
00315   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 4 >::Pointer) \
00316   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 5 >::Pointer) \
00317   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 6 >::Pointer) \
00318   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 7 >::Pointer) \
00319   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 8 >::Pointer) \
00320 
00321 // Define instantiation macro for this template.
00322 #define ITK_TEMPLATE_MetaDataObject(_, EXPORT, x, y) namespace itk { \
00323   _(1(class EXPORT MetaDataObject< ITK_TEMPLATE_1 x >)) \
00324   namespace Templates { typedef MetaDataObject< ITK_TEMPLATE_1 x > \
00325                                          MetaDataObject##y; } \
00326   }
00327 
00328 #if ITK_TEMPLATE_EXPLICIT
00329 # include "Templates/itkMetaDataObject+-.h"
00330 #endif
00331 
00332 #if ITK_TEMPLATE_TXX
00333 # include "itkMetaDataObject.txx"
00334 #endif
00335 
00336 
00337 #endif //itkMetaDataObject_h
00338 

Generated at Sat Feb 28 13:00:33 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000