Orfeo Toolbox  4.0
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 "itkCommand.h"
34 #include "itkFastMutexLock.h"
35 
36 #include <cstring>
37 
38 namespace itk
39 {
72 template< typename MetaDataObjectType >
74 {
75 public:
81 
83  itkFactorylessNewMacro(Self);
84 
86  itkTypeMacro(MetaDataObject, MetaDataObjectBase);
87 
92  MetaDataObject(void);
97  virtual ~MetaDataObject(void);
102  MetaDataObject(const MetaDataObjectType InitializerValue);
114  virtual const char * GetMetaDataObjectTypeName(void) const;
115 
122  virtual const std::type_info & GetMetaDataObjectTypeInfo(void) const;
123 
129  const MetaDataObjectType & GetMetaDataObjectValue(void) const;
130 
136  void SetMetaDataObjectValue(const MetaDataObjectType & NewValue);
137 
142  virtual void Print(std::ostream & os) const;
143 
144 private:
145  // This is made private to force the use of the
146  // MetaDataObject<MetaDataObjectType>::New() operator!
147  //void * operator new(SizeValueType nothing) {};//purposefully not implemented
148 
153  MetaDataObjectType m_MetaDataObjectValue;
154 };
155 
165 template< typename T >
166 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const std::string & key, const T & invalue)
167 {
169  temp->SetMetaDataObjectValue(invalue);
170  Dictionary[key] = temp;
171 }
172 
173 template< typename T >
174 inline void EncapsulateMetaData(MetaDataDictionary & Dictionary, const char *key, const T & invalue)
175 {
176  EncapsulateMetaData(Dictionary, std::string(key), invalue);
177 }
178 
188 template< typename T >
189 inline bool ExposeMetaData(const MetaDataDictionary & Dictionary, const std::string key, T & outval)
190 {
191  if ( !Dictionary.HasKey(key) )
192  {
193  return false;
194  }
195 
196  const MetaDataObjectBase::ConstPointer baseObjectSmartPointer = Dictionary[key];
197 
198  if ( baseObjectSmartPointer.IsNull() || strcmp( typeid( T ).name(), baseObjectSmartPointer->GetMetaDataObjectTypeName() ) != 0 )
199  {
200  return false;
201  }
202  {
203  MetaDataObject< T > const * const TempMetaDataObject = dynamic_cast< MetaDataObject< T > const * >( baseObjectSmartPointer.GetPointer() );
204  if ( TempMetaDataObject != NULL )
205  {
206  outval = TempMetaDataObject->GetMetaDataObjectValue();
207  }
208  else
209  {
210  return false;
211  }
212  }
213  return true;
214 }
215 } // end namespace itk
216 
224 #define NATIVE_TYPE_METADATAPRINT(TYPE_NAME) \
225  template< > \
226  void \
227  itk::MetaDataObject< TYPE_NAME > \
228  ::Print(std::ostream & os) const \
229  { \
230  os << this->m_MetaDataObjectValue << std::endl; \
231  } \
232  template< > \
233  void \
234  itk::MetaDataObject< const TYPE_NAME > \
235  ::Print(std::ostream & os) const \
236  { \
237  os << this->m_MetaDataObjectValue << std::endl; \
238  }
239 
248 #define ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(TYPE_NAME_PART1, TYPE_NAME_PART2) \
249  template< > \
250  void \
251  itk::MetaDataObject< TYPE_NAME_PART1, TYPE_NAME_PART2 > \
252  ::Print(std::ostream & os) const \
253  { \
254  this->m_MetaDataObjectValue->Print(os); \
255  } \
256  template< > \
257  void \
258  itk::MetaDataObject< const TYPE_NAME_PART1, TYPE_NAME_PART2 > \
259  ::Print(std::ostream & os) const \
260  { \
261  this->m_MetaDataObjectValue->Print(os); \
262  }
263 
271 #define ITK_IMAGE_TYPE_METADATAPRINT(STORAGE_TYPE) \
272  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 1 >::Pointer) \
273  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 2 >::Pointer) \
274  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 3 >::Pointer) \
275  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 4 >::Pointer) \
276  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 5 >::Pointer) \
277  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 6 >::Pointer) \
278  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 7 >::Pointer) \
279  ITK_OBJECT_TYPE_METADATAPRINT_1COMMA(itk::Image< STORAGE_TYPE, 8 >::Pointer) \
280 
281 #ifndef ITK_MANUAL_INSTANTIATION
282 #include "itkMetaDataObject.hxx"
283 #endif
284 
285 #endif //itkMetaDataObject_h

Generated at Sat Mar 8 2014 15:12:51 for Orfeo Toolbox with doxygen 1.8.3.1