VTK
vtkInformationKey.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkInformationKey.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
32 #ifndef vtkInformationKey_h
33 #define vtkInformationKey_h
34 
35 #include "vtkCommonCoreModule.h" // For export macro
36 #include "vtkObjectBase.h"
37 #include "vtkObject.h" // Need vtkTypeMacro
38 
39 class vtkInformation;
40 
41 class VTKCOMMONCORE_EXPORT vtkInformationKey : public vtkObjectBase
42 {
43 public:
44  vtkBaseTypeMacro(vtkInformationKey,vtkObjectBase);
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
50  void Register(vtkObjectBase*) override;
51 
55  void UnRegister(vtkObjectBase*) override;
56 
61  const char* GetName();
62 
67  const char* GetLocation();
68 
70 
77  vtkInformationKey(const char* name, const char* location);
78  ~vtkInformationKey() override;
80 
86  virtual void ShallowCopy(vtkInformation* from, vtkInformation* to)=0;
87 
94  virtual void DeepCopy(vtkInformation *from, vtkInformation *to)
95  { this->ShallowCopy(from, to); }
96 
100  virtual int Has(vtkInformation* info);
101 
105  virtual void Remove(vtkInformation* info);
106 
110  virtual void Report(vtkInformation* info, vtkGarbageCollector* collector);
111 
113 
116  void Print(vtkInformation* info);
117  virtual void Print(ostream& os, vtkInformation* info);
119 
129  virtual bool NeedToExecute(vtkInformation* vtkNotUsed(pipelineInfo),
130  vtkInformation* vtkNotUsed(dobjInfo)) {return false;}
131 
146  virtual void StoreMetaData(vtkInformation* vtkNotUsed(request),
147  vtkInformation* vtkNotUsed(pipelineInfo),
148  vtkInformation* vtkNotUsed(dobjInfo)) {}
149 
158  virtual void CopyDefaultInformation(vtkInformation* vtkNotUsed(request),
159  vtkInformation* vtkNotUsed(fromInfo),
160  vtkInformation* vtkNotUsed(toInfo)) {}
161 
162 protected:
163  char* Name;
164  char* Location;
165 
166 #define vtkInformationKeySetStringMacro(name) \
167 virtual void Set##name (const char* _arg) \
168 { \
169  if ( this->name == nullptr && _arg == nullptr) { return;} \
170  if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
171  delete [] this->name; \
172  if (_arg) \
173  { \
174  size_t n = strlen(_arg) + 1; \
175  char *cp1 = new char[n]; \
176  const char *cp2 = (_arg); \
177  this->name = cp1; \
178  do { *cp1++ = *cp2++; } while ( --n ); \
179  } \
180  else \
181  { \
182  this->name = nullptr; \
183  } \
184 }
185 
188 
189  // Set/Get the value associated with this key instance in the given
190  // information object.
191  void SetAsObjectBase(vtkInformation* info, vtkObjectBase* value);
192  const vtkObjectBase* GetAsObjectBase(vtkInformation* info) const;
193  vtkObjectBase* GetAsObjectBase(vtkInformation* info);
194 
195  // Report the object associated with this key instance in the given
196  // information object to the collector.
197  void ReportAsObjectBase(vtkInformation* info,
198  vtkGarbageCollector* collector);
199 
200  // Helper for debug leaks support.
201  void ConstructClass(const char*);
202 
203 private:
204  vtkInformationKey(const vtkInformationKey&) = delete;
205  void operator=(const vtkInformationKey&) = delete;
206 };
207 
208 // Macros to define an information key instance in a C++ source file.
209 // The corresponding method declaration must appear in the class
210 // definition in the header file.
211 #define vtkInformationKeyMacro(CLASS, NAME, type) \
212  static vtkInformation##type##Key* CLASS##_##NAME = \
213  new vtkInformation##type##Key(#NAME, #CLASS); \
214  vtkInformation##type##Key* CLASS::NAME() \
215  { \
216  return CLASS##_##NAME; \
217  }
218 #define vtkInformationKeySubclassMacro(CLASS, NAME, type, super) \
219  static vtkInformation##type##Key* CLASS##_##NAME = \
220  new vtkInformation##type##Key(#NAME, #CLASS); \
221  vtkInformation##super##Key* CLASS::NAME() \
222  { \
223  return CLASS##_##NAME; \
224  }
225 #define vtkInformationKeyRestrictedMacro(CLASS, NAME, type, required) \
226  static vtkInformation##type##Key* CLASS##_##NAME = \
227  new vtkInformation##type##Key(#NAME, #CLASS, required); \
228  vtkInformation##type##Key* CLASS::NAME() \
229  { \
230  return CLASS##_##NAME; \
231  }
232 
233 
234 #endif
vtkObjectBase::operator=
void operator=(const vtkObjectBase &)
Definition: vtkObjectBase.h:226
vtkInformationKey::Location
char * Location
Definition: vtkInformationKey.h:164
vtkInformationKey::DeepCopy
virtual void DeepCopy(vtkInformation *from, vtkInformation *to)
Duplicate (new instance created) the entry associated with this key from one information object to an...
Definition: vtkInformationKey.h:94
vtkObjectBase.h
vtkObjectBase::Print
void Print(ostream &os)
Print an object to an ostream.
vtkX3D::value
Definition: vtkX3D.h:220
vtkObjectBase::Register
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
vtkInformationKey::NeedToExecute
virtual bool NeedToExecute(vtkInformation *vtkNotUsed(pipelineInfo), vtkInformation *vtkNotUsed(dobjInfo))
This function is only relevant when the pertaining key is used in a VTK pipeline.
Definition: vtkInformationKey.h:129
vtkInformationKeySetStringMacro
#define vtkInformationKeySetStringMacro(name)
Definition: vtkInformationKey.h:166
vtkInformationKey::Name
char * Name
Definition: vtkInformationKey.h:163
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkInformationKey::StoreMetaData
virtual void StoreMetaData(vtkInformation *vtkNotUsed(request), vtkInformation *vtkNotUsed(pipelineInfo), vtkInformation *vtkNotUsed(dobjInfo))
This function is only relevant when the pertaining key is used in a VTK pipeline.
Definition: vtkInformationKey.h:146
vtkX3D::name
Definition: vtkX3D.h:219
vtkGarbageCollector
Detect and break reference loops.
Definition: vtkGarbageCollector.h:99
vtkObject.h
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:70
vtkX3D::info
Definition: vtkX3D.h:376
vtkObjectBase::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkInformationKey::CopyDefaultInformation
virtual void CopyDefaultInformation(vtkInformation *vtkNotUsed(request), vtkInformation *vtkNotUsed(fromInfo), vtkInformation *vtkNotUsed(toInfo))
This function is only relevant when the pertaining key is used in a VTK pipeline.
Definition: vtkInformationKey.h:158
vtkX3D::location
Definition: vtkX3D.h:406
vtkInformationKey
Superclass for vtkInformation keys.
Definition: vtkInformationKey.h:41
vtkObjectBase::UnRegister
virtual void UnRegister(vtkObjectBase *o)
Decrease the reference count (release by another object).