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: 2007/01/30 20:56:09 $
00007   Version:   $Revision: 1.20 $
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 
00031 namespace itk
00032 {
00060   template <class MetaDataObjectType>
00061     class ITK_EXPORT MetaDataObject: public MetaDataObjectBase
00062     {
00063       public:
00065         typedef MetaDataObject  Self;
00066         typedef MetaDataObjectBase  Superclass;
00067         typedef SmartPointer<Self>  Pointer;
00068         typedef SmartPointer<const Self>  ConstPointer;
00069 
00071         itkFactorylessNewMacro(Self);
00072 
00074         itkTypeMacro(MetaDataObject, MetaDataObjectBase);
00075 
00080         MetaDataObject(void);
00081 
00085         virtual ~MetaDataObject(void);
00086 
00091         MetaDataObject(const MetaDataObjectType InitializerValue);
00092 
00097         MetaDataObject(const MetaDataObject<MetaDataObjectType> &TemplateObject);
00098 
00106         virtual const char * GetMetaDataObjectTypeName(void) const;
00107 
00115         virtual const std::type_info & GetMetaDataObjectTypeInfo(void) const;
00116 
00122         const MetaDataObjectType & GetMetaDataObjectValue(void) const;
00123 
00129         void SetMetaDataObjectValue(const MetaDataObjectType & NewValue );
00130 
00135         virtual void Print(std::ostream& os) const;
00136       private:
00137         //This is made private to force the use of the MetaDataObject<MetaDataObjectType>::New() operator!
00138         //void * operator new(size_t nothing) {};//purposefully not implemented
00139 
00144         MetaDataObjectType m_MetaDataObjectValue;
00145     };
00146 
00147 
00155   template <class T>
00156     inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string & key, const T &invalue)
00157     {
00158       typename MetaDataObject<T>::Pointer temp=MetaDataObject<T>::New();
00159       temp->SetMetaDataObjectValue(invalue);
00160       Dictionary[key] = temp;
00161     }
00163 
00164   template <class T>
00165     inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const char *key, const T &invalue)
00166     {
00167       EncapsulateMetaData(Dictionary, std::string(key), invalue);
00168     }
00169 
00179   template <class T>
00180     inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const std::string key, T &outval)
00181     {
00182       if(!Dictionary.HasKey(key))
00183       {
00184         return false;
00185       }
00186 
00187       MetaDataObjectBase::Pointer baseObjectSmartPointer = Dictionary[key];
00188 
00189       if(strcmp(typeid(T).name(),baseObjectSmartPointer->GetMetaDataObjectTypeName()) != 0)
00190       {
00191         return false;
00192       }
00193       //The following is necessary for getting this to work on
00194       //kitware's SGI computers.  It is not necessary for
00195       //for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
00196 #if (defined(__sgi) && !defined(__GNUC__))
00197       /*
00198        * from page 10.4.11 pg 256 of the Stroustrup book:
00199        * ========================================================================
00200        * The reinterpret_cast is the crudest and potentially nastiest of the type
00201        * conversion operators.  In most caes, it simply yeilds a value with the
00202        * same bit pattern as it's argument wit the type required .  Thus, it can
00203        * be used for the inherently implementation-depend, dangerous, and
00204        * occasionally absolutely necessary activity of converting interger values
00205        * to pointers, and  vice versa.
00206        */
00207       outval =
00208         reinterpret_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())->GetMetaDataObjectValue();
00209 #else
00210       {
00211         if(MetaDataObject <T> * TempMetaDataObject =dynamic_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer()))
00212         {
00213           outval = TempMetaDataObject->GetMetaDataObjectValue();
00214         }
00215         else
00216         {
00217           return false;
00218         }
00219       }
00220 #endif
00221       //                                 --------------- ^^^^^^^^^^^^
00222       //                                 SmartPointer    MetaDataObject<T>*
00223       return true;
00224     }
00225 
00226   //This is only necessary to make the borland compiler happy.  It should not be necesary for most compilers.
00227   //This should not change the behavior, it just adds an extra level of complexity to using the ExposeMetaData
00228   //with const char * keys.
00229 template <class T>
00230   inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const char * const key, T &outval)
00231   {
00232     return ExposeMetaData(Dictionary, std::string(key), outval);
00233   }
00234 
00235 } // end namespace itk
00236 
00244 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
00245 template <> \
00246 void \
00247   itk::MetaDataObject< TYPE_NAME > \
00248   ::Print(std::ostream& os) const \
00249 { \
00250   os << this->m_MetaDataObjectValue << std::endl; \
00251 } \
00252 template <> \
00253 void \
00254   itk::MetaDataObject< const TYPE_NAME > \
00255   ::Print(std::ostream& os) const \
00256 { \
00257   os << this->m_MetaDataObjectValue << std::endl; \
00258 }
00259 
00260 
00269 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA( TYPE_NAME_PART1 , TYPE_NAME_PART2 ) \
00270 template <> \
00271 void \
00272   itk::MetaDataObject< TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00273   ::Print(std::ostream& os) const \
00274 { \
00275   this->m_MetaDataObjectValue->Print(os); \
00276 } \
00277 template <> \
00278 void \
00279   itk::MetaDataObject< const TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00280   ::Print(std::ostream& os) const \
00281 { \
00282   this->m_MetaDataObjectValue->Print(os); \
00283 }
00284 
00285 
00293 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
00294   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 1 >::Pointer) \
00295   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 2 >::Pointer) \
00296   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 3 >::Pointer) \
00297   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 4 >::Pointer) \
00298   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 5 >::Pointer) \
00299   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 6 >::Pointer) \
00300   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 7 >::Pointer) \
00301   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 8 >::Pointer) \
00302 
00303 // Define instantiation macro for this template.
00304 #define ITK_TEMPLATE_MetaDataObject(_, EXPORT, x, y) namespace itk { \
00305   _(1(class EXPORT MetaDataObject< ITK_TEMPLATE_1 x >)) \
00306   namespace Templates { typedef MetaDataObject< ITK_TEMPLATE_1 x > \
00307                                          MetaDataObject##y; } \
00308   }
00309 
00310 #if ITK_TEMPLATE_EXPLICIT
00311 # include "Templates/itkMetaDataObject+-.h"
00312 #endif
00313 
00314 #if ITK_TEMPLATE_TXX
00315 # include "itkMetaDataObject.txx"
00316 #endif
00317 
00318 
00319 #endif //itkMetaDataObject_h
00320 
00321 

Generated at Mon Mar 12 01:38:22 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000