00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#ifndef MetaDataObject_h_h
00021
#define MetaDataObject_h_h
00022
00023
#if defined(_MSC_VER)
00024
#pragma warning ( disable : 4786 )
00025
#endif
00026
00027
#include "itkMetaDataDictionary.h"
00028
#include "itkMacro.h"
00029
#include "itkObjectFactory.h"
00030
#include "itkCommand.h"
00031
#include "itkFastMutexLock.h"
00032
#include <string>
00033
00034
00035
namespace itk
00036 {
00064
template <
class MetaDataObjectType>
00065 class ITK_EXPORT MetaDataObject:
public itk::
MetaDataObjectBase
00066 {
00067
public:
00069 typedef MetaDataObject
Self;
00070 typedef MetaDataObjectBase Superclass;
00071 typedef SmartPointer<Self> Pointer;
00072 typedef SmartPointer<const Self> ConstPointer;
00073
00075
itkNewMacro(
Self);
00076
00078
itkTypeMacro(MetaDataObject,
MetaDataObjectBase);
00079
00084 MetaDataObject(
void);
00088
virtual ~MetaDataObject(
void);
00093 MetaDataObject(
const MetaDataObjectType InitializerValue);
00098 MetaDataObject(
const MetaDataObject<MetaDataObjectType> &TemplateObject);
00106
virtual const char * GetMetaDataObjectTypeName(
void) const;
00114 virtual const std::type_info & GetMetaDataObjectTypeInfo(
void) const;
00120 const MetaDataObjectType & GetMetaDataObjectValue(
void) const;
00126
void SetMetaDataObjectValue(const MetaDataObjectType & NewValue );
00131 virtual
void Print(std::ostream& os) const;
00132 private:
00133
00134
00139 MetaDataObjectType m_MetaDataObjectValue;
00140 };
00141
00142
00150 template <class T>
00151 inline
void EncapsulateMetaData(
MetaDataDictionary &Dictionary, const std::string & key, const T &invalue)
00152 {
00153
typename MetaDataObject<T>::Pointer temp=
MetaDataObject<T>::New();
00154 temp->
SetMetaDataObjectValue(invalue);
00155 Dictionary[key] = temp;
00156 }
00157
00158
template <
class T>
00159
inline void EncapsulateMetaData(
MetaDataDictionary &Dictionary,
const char *key,
const T &invalue)
00160 {
00161
EncapsulateMetaData(Dictionary, std::string(key), invalue);
00162 }
00163
00173
template <
class T>
00174
inline bool ExposeMetaData(MetaDataDictionary &Dictionary,
const std::string key, T &outval)
00175 {
00176
if(!Dictionary.HasKey(key))
00177 {
00178
return false;
00179 }
00180
00181 MetaDataObjectBase::Pointer baseObjectSmartPointer = Dictionary[key];
00182
00183
if(strcmp(
typeid(T).name(),baseObjectSmartPointer->GetMetaDataObjectTypeName()) != 0)
00184 {
00185
return false;
00186 }
00187
00188
00189
00190
#if (defined(__sgi) && !defined(__GNUC__))
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 outval =
00202 reinterpret_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer())->GetMetaDataObjectValue();
00203
#else
00204
{
00205
if(MetaDataObject <T> * TempMetaDataObject =dynamic_cast<MetaDataObject <T> *>(Dictionary[key].GetPointer()))
00206 {
00207 outval = TempMetaDataObject->GetMetaDataObjectValue();
00208 }
00209
else
00210 {
00211
return false;
00212 }
00213 }
00214
#endif
00215
00216
00217
return true;
00218 }
00219
00220
00221
00222
00223
template <
class T>
00224
inline bool ExposeMetaData(MetaDataDictionary &Dictionary,
const char *
const key, T &outval)
00225 {
00226
return ExposeMetaData(Dictionary, std::string(key), outval);
00227 }
00228
00229 }
00230
00238
#define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
00239
void \
00240
itk::MetaDataObject<TYPE_NAME> \
00241
::Print(std::ostream& os) const \
00242
{ \
00243
os << this->m_MetaDataObjectValue << std::endl; \
00244
} \
00245
void \
00246
itk::MetaDataObject<const TYPE_NAME> \
00247
::Print(std::ostream& os) const \
00248 { \
00249
os << this->m_MetaDataObjectValue << std::endl; \
00250
}
00251
00260
#define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1,TYPE_NAME_PART2) \
00261
void \
00262
itk::MetaDataObject<TYPE_NAME_PART1,TYPE_NAME_PART2> \
00263
::Print(std::ostream& os) const \
00264
{ \
00265
this->m_MetaDataObjectValue->Print(os); \
00266
} \
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 //MetaDataObject_h_h
00296