ITK  4.13.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 ITK_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() ITK_OVERRIDE;
128 
129 private:
130  ITK_DISALLOW_COPY_AND_ASSIGN(MetaDataObject);
131 
136  MetaDataObjectType m_MetaDataObjectValue;
137 };
138 
148 template< typename T >
149 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const std::string & key, const T & invalue)
150 {
152  temp->SetMetaDataObjectValue(invalue);
153  Dictionary[key] = temp;
154 }
156 
157 template< typename T >
158 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const char *key, const T & invalue)
159 {
160  EncapsulateMetaData(Dictionary, std::string(key), invalue);
161 }
162 
172 template< typename T >
173 inline bool ExposeMetaData(const MetaDataDictionary & Dictionary, const std::string key, T & outval)
174 {
175  if ( !Dictionary.HasKey(key) )
176  {
177  return false;
178  }
179 
180  const MetaDataObjectBase::ConstPointer baseObjectSmartPointer = Dictionary[key];
181  MetaDataObject< T > const * const TempMetaDataObject = dynamic_cast< MetaDataObject< T > const * >( baseObjectSmartPointer.GetPointer() );
182  if ( TempMetaDataObject == ITK_NULLPTR )
183  {
184  return false;
185  }
186 
187  outval = TempMetaDataObject->GetMetaDataObjectValue();
188  return true;
189 }
190 
191 } // end namespace itk
192 
200 #define ITK_NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
201  template< > \
202  void \
203  ::itk::MetaDataObject< TYPE_NAME > \
204  ::Print(std::ostream & os) const \
205  { \
206  os << this->m_MetaDataObjectValue << std::endl; \
207  } \
208 
209 
217 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1, TYPE_NAME_PART2) \
218  template< > \
219  void \
220  itk::MetaDataObject< TYPE_NAME_PART1, TYPE_NAME_PART2 > \
221  ::Print(std::ostream & os) const \
222  { \
223  this->m_MetaDataObjectValue->Print(os); \
224  } \
225 
226 
233 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
234  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 1 >::Pointer) \
235  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 2 >::Pointer) \
236  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 3 >::Pointer) \
237  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 4 >::Pointer) \
238  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 5 >::Pointer) \
239  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 6 >::Pointer) \
240  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 7 >::Pointer) \
241  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 8 >::Pointer) \
242 
243 #ifndef ITK_MANUAL_INSTANTIATION
244 #include "itkMetaDataObject.hxx"
245 #endif
246 
247 #endif //itkMetaDataObject_h
248 
250 #ifndef ITK_TEMPLATE_EXPLICIT_MetaDataObject
251 // Explicit instantiation is required to ensure correct dynamic_cast
252 // behavior across shared libraries.
253 //
254 // IMPORTANT: Since within the same compilation unit,
255 // ITK_TEMPLATE_EXPLICIT_<classname> defined and undefined states
256 // need to be considered. This code *MUST* be *OUTSIDE* the header
257 // guards.
258 //
259 # if defined( ITKCommon_EXPORTS )
260 // We are building this library
261 # define ITKCommon_EXPORT_EXPLICIT ITK_TEMPLATE_EXPORT
262 # else
263 // We are using this library
264 # define ITKCommon_EXPORT_EXPLICIT ITKCommon_EXPORT
265 # endif
266 namespace itk
267 {
268 
269 #ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
270  ITK_GCC_PRAGMA_DIAG_PUSH()
271 #endif
272 ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes")
273 
274 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< bool >;
275 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned char >;
276 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< char >;
277 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< signed char >;
278 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned short >;
279 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< short >;
280 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned int >;
281 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< int >;
282 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned long >;
283 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< long >;
284 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< unsigned long long >;
285 extern template class ITKCommon_EXPORT_EXPLICIT MetaDataObject< long 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.