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 template <class T>
00237 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
00238 {
00239 MetaDataDictionary NonConstVersion=Dictionary;
00240 return ExposeMetaData(NonConstVersion,key,outval);
00241 }
00242
00243 template <class T>
00244 inline bool ExposeMetaData(const MetaDataDictionary &Dictionary, const char * const key, T &outval)
00245 {
00246 MetaDataDictionary NonConstVersion=Dictionary;
00247 return ExposeMetaData(Dictionary, std::string(key), outval);
00248 }
00249
00250 }
00251
00259 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
00260 template <> \
00261 void \
00262 itk::MetaDataObject< TYPE_NAME > \
00263 ::Print(std::ostream& os) const \
00264 { \
00265 os << this->m_MetaDataObjectValue << std::endl; \
00266 } \
00267 template <> \
00268 void \
00269 itk::MetaDataObject< const TYPE_NAME > \
00270 ::Print(std::ostream& os) const \
00271 { \
00272 os << this->m_MetaDataObjectValue << std::endl; \
00273 }
00274
00275
00284 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA( TYPE_NAME_PART1 , TYPE_NAME_PART2 ) \
00285 template <> \
00286 void \
00287 itk::MetaDataObject< TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00288 ::Print(std::ostream& os) const \
00289 { \
00290 this->m_MetaDataObjectValue->Print(os); \
00291 } \
00292 template <> \
00293 void \
00294 itk::MetaDataObject< const TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00295 ::Print(std::ostream& os) const \
00296 { \
00297 this->m_MetaDataObjectValue->Print(os); \
00298 }
00299
00300
00308 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
00309 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 1 >::Pointer) \
00310 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 2 >::Pointer) \
00311 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 3 >::Pointer) \
00312 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 4 >::Pointer) \
00313 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 5 >::Pointer) \
00314 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 6 >::Pointer) \
00315 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 7 >::Pointer) \
00316 ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE , 8 >::Pointer) \
00317
00318
00319 #define ITK_TEMPLATE_MetaDataObject(_, EXPORT, x, y) namespace itk { \
00320 _(1(class EXPORT MetaDataObject< ITK_TEMPLATE_1 x >)) \
00321 namespace Templates { typedef MetaDataObject< ITK_TEMPLATE_1 x > \
00322 MetaDataObject##y; } \
00323 }
00324
00325 #if ITK_TEMPLATE_EXPLICIT
00326 # include "Templates/itkMetaDataObject+-.h"
00327 #endif
00328
00329 #if ITK_TEMPLATE_TXX
00330 # include "itkMetaDataObject.txx"
00331 #endif
00332
00333
00334 #endif //itkMetaDataObject_h
00335
00336