VTK  9.2.20220703
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 "vtkObject.h" // Need vtkTypeMacro
37 #include "vtkObjectBase.h"
38 
39 class vtkInformation;
40 
41 class VTKCOMMONCORE_EXPORT vtkInformationKey : public vtkObjectBase
42 {
43 public:
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) { this->ShallowCopy(from, to); }
95 
99  virtual int Has(vtkInformation* info);
100 
104  virtual void Remove(vtkInformation* info);
105 
109  virtual void Report(vtkInformation* info, vtkGarbageCollector* collector);
110 
112 
116  virtual void Print(ostream& os, vtkInformation* info);
118 
128  virtual bool NeedToExecute(
129  vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
130  {
131  return false;
132  }
133 
148  virtual void StoreMetaData(vtkInformation* vtkNotUsed(request),
149  vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
150  {
151  }
152 
161  virtual void CopyDefaultInformation(vtkInformation* vtkNotUsed(request),
162  vtkInformation* vtkNotUsed(fromInfo), vtkInformation* vtkNotUsed(toInfo))
163  {
164  }
165 
166 protected:
167  char* Name;
168  char* Location;
169 
170 #define vtkInformationKeySetStringMacro(name) \
171  virtual void Set##name(const char* _arg) \
172  { \
173  if (this->name == nullptr && _arg == nullptr) \
174  { \
175  return; \
176  } \
177  if (this->name && _arg && (!strcmp(this->name, _arg))) \
178  { \
179  return; \
180  } \
181  delete[] this->name; \
182  if (_arg) \
183  { \
184  size_t n = strlen(_arg) + 1; \
185  char* cp1 = new char[n]; \
186  const char* cp2 = (_arg); \
187  this->name = cp1; \
188  do \
189  { \
190  *cp1++ = *cp2++; \
191  } while (--n); \
192  } \
193  else \
194  { \
195  this->name = nullptr; \
196  } \
197  }
198 
201 
202  // Set/Get the value associated with this key instance in the given
203  // information object.
207 
208  // Report the object associated with this key instance in the given
209  // information object to the collector.
211 
212  // Helper for debug leaks support.
213  void ConstructClass(const char*);
214 
215 private:
216  vtkInformationKey(const vtkInformationKey&) = delete;
217  void operator=(const vtkInformationKey&) = delete;
218 };
219 
220 // Macros to define an information key instance in a C++ source file.
221 // The corresponding method declaration must appear in the class
222 // definition in the header file.
223 #define vtkInformationKeyMacro(CLASS, NAME, type) \
224  static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
225  vtkInformation##type##Key* CLASS::NAME() { return CLASS##_##NAME; }
226 #define vtkInformationKeySubclassMacro(CLASS, NAME, type, super) \
227  static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
228  vtkInformation##super##Key* CLASS::NAME() { return CLASS##_##NAME; }
229 #define vtkInformationKeyRestrictedMacro(CLASS, NAME, type, required) \
230  static vtkInformation##type##Key* CLASS##_##NAME = \
231  new vtkInformation##type##Key(#NAME, #CLASS, required); \
232  vtkInformation##type##Key* CLASS::NAME() { return CLASS##_##NAME; }
233 
234 #endif
Detect and break reference loops.
a simple class to control print indentation
Definition: vtkIndent.h:119
Superclass for vtkInformation keys.
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.
virtual void Report(vtkInformation *info, vtkGarbageCollector *collector)
Report a reference this key has in the given information object.
void ReportAsObjectBase(vtkInformation *info, vtkGarbageCollector *collector)
vtkInformationKeySetStringMacro(Location)
void Print(vtkInformation *info)
Print the key's value in an information object to a stream.
vtkBaseTypeMacro(vtkInformationKey, vtkObjectBase)
const vtkObjectBase * GetAsObjectBase(vtkInformation *info) const
vtkInformationKeySetStringMacro(Name)
void UnRegister(vtkObjectBase *) override
Prevent normal vtkObject reference counting behavior.
~vtkInformationKey() override
Key instances are static data that need to be created and destroyed.
void SetAsObjectBase(vtkInformation *info, vtkObjectBase *value)
vtkObjectBase * GetAsObjectBase(vtkInformation *info)
vtkInformationKey(const char *name, const char *location)
Key instances are static data that need to be created and destroyed.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual int Has(vtkInformation *info)
Check whether this key appears in the given information object.
void Register(vtkObjectBase *) override
Prevent normal vtkObject reference counting behavior.
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.
virtual bool NeedToExecute(vtkInformation *vtkNotUsed(pipelineInfo), vtkInformation *vtkNotUsed(dobjInfo))
This function is only relevant when the pertaining key is used in a VTK pipeline.
virtual void DeepCopy(vtkInformation *from, vtkInformation *to)
Duplicate (new instance created) the entry associated with this key from one information object to an...
const char * GetLocation()
Get the location of the key.
virtual void Remove(vtkInformation *info)
Remove this key from the given information object.
void ConstructClass(const char *)
virtual void ShallowCopy(vtkInformation *from, vtkInformation *to)=0
Copy the entry associated with this key from one information object to another.
virtual void Print(ostream &os, vtkInformation *info)
Print the key's value in an information object to a stream.
const char * GetName()
Get the name of the key.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:74
void operator=(const vtkObjectBase &)
friend class vtkInformationKey
Some classes need to clear the reference counts manually due to the way they work.
@ location
Definition: vtkX3D.h:412
@ info
Definition: vtkX3D.h:382
@ value
Definition: vtkX3D.h:226
@ name
Definition: vtkX3D.h:225