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: 2005/08/15 18:56:14 $
00007   Version:   $Revision: 1.17 $
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 itk::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         itkNewMacro(Self);
00072 
00074         itkTypeMacro(MetaDataObject, MetaDataObjectBase);
00075 
00080         MetaDataObject(void);
00084         virtual ~MetaDataObject(void);
00089         MetaDataObject(const MetaDataObjectType InitializerValue);
00094         MetaDataObject(const MetaDataObject<MetaDataObjectType> &TemplateObject);
00102         virtual const char * GetMetaDataObjectTypeName(void) const;
00110         virtual const std::type_info & GetMetaDataObjectTypeInfo(void) const;
00116         const MetaDataObjectType & GetMetaDataObjectValue(void) const;
00122         void SetMetaDataObjectValue(const MetaDataObjectType & NewValue );
00127         virtual void Print(std::ostream& os) const;
00128       private:
00129         //This is made private to force the use of the MetaDataObject<MetaDataObjectType>::New() operator!
00130         //void * operator new(size_t nothing) {};//purposefully not implemented
00135         MetaDataObjectType m_MetaDataObjectValue;
00136     };
00137 
00138 
00146   template <class T>
00147     inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string & key, const T &invalue)
00148     {
00149       typename MetaDataObject<T>::Pointer temp=MetaDataObject<T>::New();
00150       temp->SetMetaDataObjectValue(invalue);
00151       Dictionary[key] = temp;
00152     }
00153 
00154   template <class T>
00155     inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const char *key, const T &invalue)
00156     {
00157       EncapsulateMetaData(Dictionary, std::string(key), invalue);
00158     }
00159 
00169   template <class T>
00170     inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const std::string key, T &outval)
00171     {
00172       if(!Dictionary.HasKey(key))
00173       {
00174         return false;
00175       }
00176 
00177       MetaDataObjectBase::Pointer baseObjectSmartPointer = Dictionary[key];
00178 
00179       if(strcmp(typeid(T).name(),baseObjectSmartPointer->GetMetaDataObjectTypeName()) != 0)
00180       {
00181         return false;
00182       }
00183       //The following is necessary for getting this to work on
00184       //kitware's SGI computers.  It is not necessary for
00185       //for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
00186 #if (defined(__sgi) && !defined(__GNUC__))
00187       /*
00188        * from page 10.4.11 pg 256 of the Stroustrup book:
00189        * ========================================================================
00190        * The reinterpret_cast is the crudest and potentially nastiest of the type
00191        * conversion operators.  In most caes, it simply yeilds a value with the
00192        * same bit pattern as it's argument wit the type required .  Thus, it can
00193        * be used for the inherently implementation-depend, dangerous, and
00194        * occasionally absolutely necessary activity of converting interger values
00195        * to pointers, and  vice versa.
00196        */
00197       outval =
00198         reinterpret_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())->GetMetaDataObjectValue();
00199 #else
00200       {
00201         if(MetaDataObject <T> * TempMetaDataObject =dynamic_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer()))
00202         {
00203           outval = TempMetaDataObject->GetMetaDataObjectValue();
00204         }
00205         else
00206         {
00207           return false;
00208         }
00209       }
00210 #endif
00211       //                                 --------------- ^^^^^^^^^^^^
00212       //                                 SmartPointer    MetaDataObject<T>*
00213       return true;
00214     }
00215 
00216   //This is only necessary to make the borland compiler happy.  It should not be necesary for most compilers.
00217   //This should not change the behavior, it just adds an extra level of complexity to using the ExposeMetaData
00218   //with const char * keys.
00219 template <class T>
00220   inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const char * const key, T &outval)
00221   {
00222     return ExposeMetaData(Dictionary, std::string(key), outval);
00223   }
00224 
00225 } // end namespace itk
00226 
00234 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
00235 template <> \
00236 void \
00237   itk::MetaDataObject< TYPE_NAME > \
00238   ::Print(std::ostream& os) const \
00239 { \
00240   os << this->m_MetaDataObjectValue << std::endl; \
00241 } \
00242 template <> \
00243 void \
00244   itk::MetaDataObject< const TYPE_NAME > \
00245   ::Print(std::ostream& os) const \
00246 { \
00247   os << this->m_MetaDataObjectValue << std::endl; \
00248 }
00249 
00258 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA( TYPE_NAME_PART1 , TYPE_NAME_PART2 ) \
00259 template <> \
00260 void \
00261   itk::MetaDataObject< TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00262   ::Print(std::ostream& os) const \
00263 { \
00264   this->m_MetaDataObjectValue->Print(os); \
00265 } \
00266 template <> \
00267 void \
00268   itk::MetaDataObject< const TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00269   ::Print(std::ostream& os) const \
00270 { \
00271   this->m_MetaDataObjectValue->Print(os); \
00272 }
00273 
00281 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
00282   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 1 >::Pointer) \
00283   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 2 >::Pointer) \
00284   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 3 >::Pointer) \
00285   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 4 >::Pointer) \
00286   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 5 >::Pointer) \
00287   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 6 >::Pointer) \
00288   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 7 >::Pointer) \
00289   ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 8 >::Pointer) \
00290 
00291 #ifndef ITK_MANUAL_INSTANTIATION
00292 #include "itkMetaDataObject.txx"
00293 #endif
00294 
00295 #endif //itkMetaDataObject_h
00296 

Generated at Wed May 24 23:40:25 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000