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 itk::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 itkNewMacro(Self);
00072
00074 itkTypeMacro(MetaDataObject, MetaDataObjectBase);
00075
00080 MetaDataObject(void);
00084 virtual ~MetaDataObject(void);
00089 MetaDataObject(const MetaDataObjectType InitializerValue);
00094 MetaDataObject(const MetaDataObject<MetaDataObjectType> &TemplateObject);
00102 virtual const char * GetMetaDataObjectTypeName(void) const;
00110 virtual const std::type_info & GetMetaDataObjectTypeInfo(void) const;
00116 const MetaDataObjectType & GetMetaDataObjectValue(void) const;
00122 void SetMetaDataObjectValue(const MetaDataObjectType & NewValue );
00127 virtual void Print(std::ostream& os) const;
00128 private:
00129
00130
00135 MetaDataObjectType m_MetaDataObjectValue;
00136 };
00137
00138
00146 template <class T>
00147 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string & key, const T &invalue)
00148 {
00149 typename MetaDataObject<T>::Pointer temp=MetaDataObject<T>::New();
00150 temp->SetMetaDataObjectValue(invalue);
00151 Dictionary[key] = temp;
00152 }
00153
00154 template <class T>
00155 inline void EncapsulateMetaData(MetaDataDictionary &Dictionary, const char *key, const T &invalue)
00156 {
00157 EncapsulateMetaData(Dictionary, std::string(key), invalue);
00158 }
00159
00169 template <class T>
00170 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const std::string key, T &outval)
00171 {
00172 if(!Dictionary.HasKey(key))
00173 {
00174 return false;
00175 }
00176
00177 MetaDataObjectBase::Pointer baseObjectSmartPointer = Dictionary[key];
00178
00179 if(strcmp(typeid(T).name(),baseObjectSmartPointer->GetMetaDataObjectTypeName()) != 0)
00180 {
00181 return false;
00182 }
00183
00184
00185
00186 #if (defined(__sgi) && !defined(__GNUC__))
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 outval =
00198 reinterpret_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())->GetMetaDataObjectValue();
00199 #else
00200 {
00201 if(MetaDataObject <T> * TempMetaDataObject =dynamic_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer()))
00202 {
00203 outval = TempMetaDataObject->GetMetaDataObjectValue();
00204 }
00205 else
00206 {
00207 return false;
00208 }
00209 }
00210 #endif
00211
00212
00213 return true;
00214 }
00215
00216
00217
00218
00219 template <class T>
00220 inline bool ExposeMetaData(MetaDataDictionary &Dictionary, const char * const key, T &outval)
00221 {
00222 return ExposeMetaData(Dictionary, std::string(key), outval);
00223 }
00224
00225 }
00226
00234 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
00235 template <> \
00236 void \
00237 itk::MetaDataObject< TYPE_NAME > \
00238 ::Print(std::ostream& os) const \
00239 { \
00240 os << this->m_MetaDataObjectValue << std::endl; \
00241 } \
00242 template <> \
00243 void \
00244 itk::MetaDataObject< const TYPE_NAME > \
00245 ::Print(std::ostream& os) const \
00246 { \
00247 os << this->m_MetaDataObjectValue << std::endl; \
00248 }
00249
00258 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA( TYPE_NAME_PART1 , TYPE_NAME_PART2 ) \
00259 template <> \
00260 void \
00261 itk::MetaDataObject< TYPE_NAME_PART1 , TYPE_NAME_PART2 > \
00262 ::Print(std::ostream& os) const \
00263 { \
00264 this->m_MetaDataObjectValue->Print(os); \
00265 } \
00266 template <> \
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 //itkMetaDataObject_h
00296