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: 2003/09/10 14:29:16 $ 00007 Version: $Revision: 1.12 $ 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 MetaDataObject_h_h 00021 #define MetaDataObject_h_h 00022 00023 #if defined(_MSC_VER) 00024 #pragma warning ( disable : 4786 ) 00025 #endif 00026 00027 #include "itkMetaDataDictionary.h" 00028 #include "itkMacro.h" 00029 #include "itkObjectFactory.h" 00030 #include "itkCommand.h" 00031 #include "itkFastMutexLock.h" 00032 #include <string> 00033 00034 00035 namespace itk 00036 { 00064 template <class MetaDataObjectType> 00065 class ITK_EXPORT MetaDataObject: public itk::MetaDataObjectBase 00066 { 00067 public: 00069 typedef MetaDataObject Self; 00070 typedef MetaDataObjectBase Superclass; 00071 typedef SmartPointer<Self> Pointer; 00072 typedef SmartPointer<const Self> ConstPointer; 00073 00075 itkNewMacro(Self); 00076 00078 itkTypeMacro(MetaDataObject, MetaDataObjectBase); 00079 00084 MetaDataObject(void); 00088 virtual ~MetaDataObject(void); 00093 MetaDataObject(const MetaDataObjectType InitializerValue); 00098 MetaDataObject(const MetaDataObject<MetaDataObjectType> &TemplateObject); 00106 virtual const char * GetMetaDataObjectTypeName(void) const; 00114 virtual const std::type_info & GetMetaDataObjectTypeInfo(void) const; 00120 const MetaDataObjectType & GetMetaDataObjectValue(void) const; 00126 void SetMetaDataObjectValue(const MetaDataObjectType & NewValue ); 00131 virtual void Print(std::ostream& os) const; 00132 private: 00133 //This is made private to force the use of the MetaDataObject<MetaDataObjectType>::New() operator! 00134 //void * operator new(size_t nothing) {};//purposefully not implemented 00139 MetaDataObjectType m_MetaDataObjectValue; 00140 }; 00141 00142 00150 template <class T> 00151 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string & key, const T &invalue) 00152 { 00153 typename MetaDataObject<T>::Pointer temp=MetaDataObject<T>::New(); 00154 temp->SetMetaDataObjectValue(invalue); 00155 Dictionary[key] = temp; 00156 } 00157 00158 template <class T> 00159 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const char *key, const T &invalue) 00160 { 00161 EncapsulateMetaData(Dictionary, std::string(key), invalue); 00162 } 00163 00173 template <class T> 00174 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const std::string key, T &outval) 00175 { 00176 if(!Dictionary.HasKey(key)) 00177 { 00178 return false; 00179 } 00180 00181 MetaDataObjectBase::Pointer baseObjectSmartPointer = Dictionary[key]; 00182 00183 if(strcmp(typeid(T).name(),baseObjectSmartPointer->GetMetaDataObjectTypeName()) != 0) 00184 { 00185 return false; 00186 } 00187 //The following is necessary for getting this to work on 00188 //kitware's SGI computers. It is not necessary for 00189 //for IRIX 6.5.18m with MIPSPro 7.3.1.3m. 00190 #if (defined(__sgi) && !defined(__GNUC__)) 00191 /* 00192 * from page 10.4.11 pg 256 of the Stroustrup book: 00193 * ======================================================================== 00194 * The reinterpret_cast is the crudest and potentially nastiest of the type 00195 * conversion operators.  In most caes, it simply yeilds a value with the 00196 * same bit pattern as it's argument wit the type required .  Thus, it can 00197 * be used for the inherently implementation-depend, dangerous, and 00198 * occasionally absolutely necessary activity of converting interger values 00199 * to pointers, and  vice versa. 00200 */ 00201 outval = 00202 reinterpret_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())->GetMetaDataObjectValue(); 00203 #else 00204 { 00205 if(MetaDataObject <T> * TempMetaDataObject =dynamic_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())) 00206 { 00207 outval = TempMetaDataObject->GetMetaDataObjectValue(); 00208 } 00209 else 00210 { 00211 return false; 00212 } 00213 } 00214 #endif 00215 // --------------- ^^^^^^^^^^^^ 00216 // SmartPointer MetaDataObject<T>* 00217 return true; 00218 } 00219 00220 //This is only necessary to make the borland compiler happy. It should not be necesary for most compilers. 00221 //This should not chanage the behavior, it just adds an extra level of complexity to using the ExposeMetaData 00222 //with const char * keys. 00223 template <class T> 00224 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const char * const key, T &outval) 00225 { 00226 return ExposeMetaData(Dictionary, std::string(key), outval); 00227 } 00228 00229 } // end namespace itk 00230 00238 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \ 00239 void \ 00240 itk::MetaDataObject<TYPE_NAME> \ 00241 ::Print(std::ostream& os) const \ 00242 { \ 00243 os << this->m_MetaDataObjectValue << std::endl; \ 00244 } \ 00245 void \ 00246 itk::MetaDataObject<const TYPE_NAME> \ 00247 ::Print(std::ostream& os) const \ 00248 { \ 00249 os << this->m_MetaDataObjectValue << std::endl; \ 00250 } 00251 00260 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1,TYPE_NAME_PART2) \ 00261 void \ 00262 itk::MetaDataObject<TYPE_NAME_PART1,TYPE_NAME_PART2> \ 00263 ::Print(std::ostream& os) const \ 00264 { \ 00265 this->m_MetaDataObjectValue->Print(os); \ 00266 } \ 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 //MetaDataObject_h_h 00296

Generated at Sun Apr 1 02:37:48 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000