itkMetaDataObject.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00140
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
00196
00197
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
00225 return true;
00226 }
00228
00229
00230
00231
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
00238
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 }
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
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