ITK  4.9.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 >
73 class ITKCommon_TEMPLATE_EXPORT MetaDataObject:public MetaDataObjectBase
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 &) ITK_DELETE_FUNCTION;
131  void operator=(const Self &) ITK_DELETE_FUNCTION;
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 } // end namespace itk
194 
202 #define ITK_NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
203  template< > \
204  void \
205  ::itk::MetaDataObject< TYPE_NAME > \
206  ::Print(std::ostream & os) const \
207  { \
208  os << this->m_MetaDataObjectValue << std::endl; \
209  } \
210 
211 
219 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1, TYPE_NAME_PART2) \
220  template< > \
221  void \
222  itk::MetaDataObject< TYPE_NAME_PART1, TYPE_NAME_PART2 > \
223  ::Print(std::ostream & os) const \
224  { \
225  this->m_MetaDataObjectValue->Print(os); \
226  } \
227 
228 
235 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
236  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 1 >::Pointer) \
237  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 2 >::Pointer) \
238  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 3 >::Pointer) \
239  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 4 >::Pointer) \
240  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 5 >::Pointer) \
241  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 6 >::Pointer) \
242  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 7 >::Pointer) \
243  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 8 >::Pointer) \
244 
245 #ifndef ITK_MANUAL_INSTANTIATION
246 #include "itkMetaDataObject.hxx"
247 #endif
248 
249 #endif //itkMetaDataObject_h
250 
252 #ifndef ITK_TEMPLATE_EXPLICIT_MetaDataObject
253 // Explicit instantiation is required to ensure correct dynamic_cast
254 // behavior across shared libraries.
255 //
256 // IMPORTANT: Since within the same compilation unit,
257 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
258 // need to be considered. This code *MUST* be *OUTSIDE* the header
259 // guards.
260 //
261 # if defined( ITKCommon_EXPORTS )
262 // We are building this library
263 # define ITKCommon_EXPORT_EXPLICIT
264 # else
265 // We are using this library
266 # define ITKCommon_EXPORT_EXPLICIT ITKCommon_EXPORT
267 # endif
268 namespace itk
269 {
270 
271 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
272  ITK_GCC_PRAGMA_DIAG_PUSH()
273 #endif
274 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
275 
276 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< bool >;
277 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned char >;
278 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< char >;
279 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< signed char >;
280 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned short >;
281 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< short >;
282 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned int >;
283 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< int >;
284 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned long >;
285 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< long >;
286 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< float >;
287 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< double >;
288 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::string >;
289 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<float> >;
290 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<double> >;
291 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<std::vector<float> > >;
292 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< std::vector<std::vector<double> > >;
293 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<char> >;
294 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<int> >;
295 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<float> >;
296 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Array<double> >;
297 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< Matrix<double> >;
298 
299 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
300  ITK_GCC_PRAGMA_DIAG_POP()
301 #else
302  ITK_GCC_PRAGMA_DIAG(warning "-Wattributes")
303 #endif
304 
305 } // end namespace itk
306 # undef ITKCommon_EXPORT_EXPLICIT
307 #endif
Light weight base class for most itk classes.
void EncapsulateMetaData(MetaDataDictionary &Dictionary, const std::string &key, const T &invalue)
const MetaDataObjectType & GetMetaDataObjectValue() const
bool HasKey(const std::string &) const
#define ITKCommon_EXPORT_EXPLICIT
static Pointer New()
ObjectType * GetPointer() const
SmartPointer< const Self > ConstPointer
Allows arbitrary data types to be stored as MetaDataObjectBase types, and to be stored in a MetaDataD...
Provides a mechanism for storing a collection of arbitrary data types.
MetaDataObjectBase Superclass
bool ExposeMetaData(const MetaDataDictionary &Dictionary, const std::string key, T &outval)
SmartPointer< Self > Pointer
The common interface for MetaDataObject&#39;s.