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:
00066 typedef MetaDataObject Self;
00067 typedef MetaDataObjectBase Superclass;
00068 typedef SmartPointer<Self> Pointer;
00069 typedef SmartPointer<const Self> ConstPointer;
00070
00072 itkFactorylessNewMacro(Self);
00073
00075 itkTypeMacro(MetaDataObject, MetaDataObjectBase);
00076
00081 MetaDataObject(void);
00082
00086 virtual ~MetaDataObject(void);
00087
00092 MetaDataObject(const MetaDataObjectType InitializerValue);
00093
00098 MetaDataObject(const MetaDataObject<MetaDataObjectType> &TemplateObject);
00099
00107 virtual const char * GetMetaDataObjectTypeName(void) const;
00108
00116 virtual const std::type_info & GetMetaDataObjectTypeInfo(void) const;
00117
00123 const MetaDataObjectType & GetMetaDataObjectValue(void) const;
00124
00130 void SetMetaDataObjectValue(const MetaDataObjectType & NewValue );
00131
00136 virtual void Print(std::ostream& os) const;
00137 private:
00138
00139
00140
00145 MetaDataObjectType m_MetaDataObjectValue;
00146 };
00147
00148
00156 template <class T>
00157 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string & key, const T &invalue)
00158 {
00159 typename MetaDataObject<T>::Pointer temp=MetaDataObject<T>::New();
00160 temp->SetMetaDataObjectValue(invalue);
00161 Dictionary[key] = temp;
00162 }
00164
00165 template <class T>
00166 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const char *key, const T &invalue)
00167 {
00168 EncapsulateMetaData(Dictionary, std::string(key), invalue);
00169 }
00170
00180 template <class T>
00181 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const std::string key, T &outval)
00182 {
00183 if(!Dictionary.HasKey(key))
00184 {
00185 return false;
00186 }
00187
00188 MetaDataObjectBase::Pointer baseObjectSmartPointer = Dictionary[key];
00189
00190 if(strcmp(typeid(T).name(),baseObjectSmartPointer->GetMetaDataObjectTypeName()) != 0)
00191 {
00192 return false;
00193 }
00194
00195
00196
00197 #if (defined(__sgi) && !defined(__GNUC__))
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 outval =
00209 reinterpret_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())->GetMetaDataObjectValue();
00210 #else
00211 {
00212 if(MetaDataObject <T> * TempMetaDataObject =dynamic_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer()))
00213 {
00214 outval = TempMetaDataObject->GetMetaDataObjectValue();
00215 }
00216 else
00217 {
00218 return false;
00219 }
00220 }
00221 #endif
00222
00223
00224 return true;
00225 }
00226
00227
00228
00229
00230 template <class T>
00231 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const char * const key, T &outval)
00232 {
00233 return ExposeMetaData(Dictionary, std::string(key), outval);
00234 }
00235
00236
00237 template <class T>
00238 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
00239 {
00240 MetaDataDictionary NonConstVersion=Dictionary;
00241 return ExposeMetaData(NonConstVersion,key,outval);
00242 }
00243
00244 template <class T>
00245 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const char * const key, T &outval)
00246 {
00247 MetaDataDictionary NonConstVersion=Dictionary;
00248 return ExposeMetaData(Dictionary, std::string(key), outval);
00249 }
00250
00251 }
00252
00260 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
00261 template <> \
00262 void \
00263 itk::MetaDataObject< TYPE_NAME > \
00264 ::Print(std::ostream& os) const \
00265 { \
00266 os << this->m_MetaDataObjectValue << std::endl; \
00267 } \
00268 template <> \
00269 void \
00270 itk::MetaDataObject< const TYPE_NAME > \
00271 ::Print(std::ostream& os) const \
00272 { \
00273 os << this->m_MetaDataObjectValue << std::endl; \
00274 }
00275
00276
00285 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA( TYPE_NAME_PART1 , TYPE_NAME_PART2 ) \
00286 template <> \
00287 void \
00288 itk::MetaDataObject< TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00289 ::Print(std::ostream& os) const \
00290 { \
00291 this->m_MetaDataObjectValue->Print(os); \
00292 } \
00293 template <> \
00294 void \
00295 itk::MetaDataObject< const TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00296 ::Print(std::ostream& os) const \
00297 { \
00298 this->m_MetaDataObjectValue->Print(os); \
00299 }
00300
00301
00309 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
00310 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 1 >::Pointer) \
00311 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 2 >::Pointer) \
00312 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 3 >::Pointer) \
00313 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 4 >::Pointer) \
00314 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 5 >::Pointer) \
00315 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 6 >::Pointer) \
00316 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 7 >::Pointer) \
00317 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 8 >::Pointer) \
00318
00319
00320 #define ITK_TEMPLATE_MetaDataObject(_, EXPORT, x, y) namespace itk { \
00321 _(1(class EXPORT MetaDataObject< ITK_TEMPLATE_1 x >)) \
00322 namespace Templates { typedef MetaDataObject< ITK_TEMPLATE_1 x > \
00323 MetaDataObject##y; } \
00324 }
00325
00326 #if ITK_TEMPLATE_EXPLICIT
00327 # include "Templates/itkMetaDataObject+-.h"
00328 #endif
00329
00330 #if ITK_TEMPLATE_TXX
00331 # include "itkMetaDataObject.txx"
00332 #endif
00333
00334
00335 #endif //itkMetaDataObject_h
00336
00337