ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkMetaDataObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef __itkMetaDataObject_h
29 #define __itkMetaDataObject_h
30 
31 #include "itkMetaDataDictionary.h"
32 #include "itkMacro.h"
33 #include "itkArray.h"
34 #include "itkMatrix.h"
35 
36 #include <cstring>
37 
38 namespace itk
39 {
72 template< typename MetaDataObjectType >
74 {
75 public:
76 
82 
84  itkFactorylessNewMacro(Self);
85 
87  itkTypeMacro(MetaDataObject, MetaDataObjectBase);
88 
95  virtual const char * GetMetaDataObjectTypeName() const ITK_OVERRIDE;
96 
103  virtual const std::type_info & GetMetaDataObjectTypeInfo() const ITK_OVERRIDE;
104 
110  const MetaDataObjectType & GetMetaDataObjectValue() const;
111 
117  void SetMetaDataObjectValue(const MetaDataObjectType & newValue);
118 
123  virtual void Print(std::ostream & os) const ITK_OVERRIDE;
124 
125 protected:
126  MetaDataObject();
127  virtual ~MetaDataObject();
128 
129 private:
130  MetaDataObject(const Self &); // purposely not implemented
131  void operator=(const Self &); // purposely not implemented
132 
137  MetaDataObjectType m_MetaDataObjectValue;
138 };
139 
149 template< typename T >
150 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const std::string & key, const T & invalue)
151 {
153  temp->SetMetaDataObjectValue(invalue);
154  Dictionary[key] = temp;
155 }
157 
158 template< typename T >
159 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const char *key, const T & invalue)
160 {
161  EncapsulateMetaData(Dictionary, std::string(key), invalue);
162 }
163 
173 template< typename T >
174 inline bool ExposeMetaData(const MetaDataDictionary & Dictionary, const std::string key, T & outval)
175 {
176  if ( !Dictionary.HasKey(key) )
177  {
178  return false;
179  }
180 
181  const MetaDataObjectBase::ConstPointer baseObjectSmartPointer = Dictionary[key];
182 
183  MetaDataObject< T > const * const TempMetaDataObject = dynamic_cast< MetaDataObject< T > const * >( baseObjectSmartPointer.GetPointer() );
184  if ( TempMetaDataObject == ITK_NULLPTR )
185  {
186  return false;
187  }
188 
189  outval = TempMetaDataObject->GetMetaDataObjectValue();
190  return true;
191 }
192 
193 #ifndef ITK_TEMPLATE_EXPLICIT_MetaDataObject
194 // Explicit instantiation is required to ensure correct dynamic_cast
195 // behavior across shared libraries.
196 #if defined( ITKCommon_EXPORTS )
197 // don't use export
198 #define ITKCommon_EXPORT_EXPLICIT
199 #else
200 // only import/hidden
201 #define ITKCommon_EXPORT_EXPLICIT ITKCommon_EXPORT
202 #endif
203 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< bool >;
204 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned char >;
205 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< char >;
206 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< signed char >;
207 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned short >;
208 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< short >;
209 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned int >;
210 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< int >;
211 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned long >;
212 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< long >;
213 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< float >;
214 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< double >;
215 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::string >;
216 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<float> >;
217 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<double> >;
218 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<std::vector<float> > >;
219 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<std::vector<double> > >;
220 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<char> >;
221 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<int> >;
222 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<float> >;
223 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<double> >;
224 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Matrix<double> >;
225 #undef ITKCommon_EXPORT_EXPLICIT
226 #endif
227 
228 } // end namespace itk
229 
237 #define ITK_NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
238  template< > \
239  void \
240  ::itk::MetaDataObject< TYPE_NAME > \
241  ::Print(std::ostream & os) const \
242  { \
243  os << this->m_MetaDataObjectValue << std::endl; \
244  } \
245 
246 
254 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1, TYPE_NAME_PART2) \
255  template< > \
256  void \
257  itk::MetaDataObject< TYPE_NAME_PART1, TYPE_NAME_PART2 > \
258  ::Print(std::ostream & os) const \
259  { \
260  this->m_MetaDataObjectValue->Print(os); \
261  } \
262 
263 
270 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
271  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 1 >::Pointer) \
272  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 2 >::Pointer) \
273  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 3 >::Pointer) \
274  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 4 >::Pointer) \
275  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 5 >::Pointer) \
276  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 6 >::Pointer) \
277  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 7 >::Pointer) \
278  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 8 >::Pointer) \
279 
280 #ifndef ITK_MANUAL_INSTANTIATION
281 #include "itkMetaDataObject.hxx"
282 #endif
283 
284 #endif //itkMetaDataObject_h
void SetMetaDataObjectValue(const MetaDataObjectType &newValue)
Light weight base class for most itk classes.
void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string &key, const T &invalue)
static Pointer New(void)
MetaDataObjectType m_MetaDataObjectValue
const MetaDataObjectType & GetMetaDataObjectValue() const
bool HasKey(const std::string &) const
#define ITKCommon_EXPORT_EXPLICIT
ObjectType * GetPointer() const
SmartPointer< const Self > ConstPointer
Allows arbitrary data types to be stored as MetaDataObjectBase types, and to be stored in a MetaDataD...
virtual const char * GetMetaDataObjectTypeName() const ITK_OVERRIDE
Provides a mechanism for storing a collection of arbitrary data types.
MetaDataObjectBase Superclass
bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
virtual const std::type_info & GetMetaDataObjectTypeInfo() const ITK_OVERRIDE
virtual void Print(std::ostream &os) const ITK_OVERRIDE
SmartPointer< Self > Pointer
The common interface for MetaDataObject&#39;s.