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
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
00138
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
00194
00195
00196 #if (defined(__sgi) && !defined(__GNUC__))
00197
00198
00199
00200
00201
00202
00203
00204
00205
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
00223 return true;
00224 }
00225
00226
00227
00228
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 }
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
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