VTK  9.3.0
vtkInformationKey.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
20 #ifndef vtkInformationKey_h
21 #define vtkInformationKey_h
22 
23 #include "vtkCommonCoreModule.h" // For export macro
24 #include "vtkObject.h" // Need vtkTypeMacro
25 #include "vtkObjectBase.h"
26 
27 VTK_ABI_NAMESPACE_BEGIN
28 class vtkInformation;
29 
30 class VTKCOMMONCORE_EXPORT vtkInformationKey : public vtkObjectBase
31 {
32 public:
34  void PrintSelf(ostream& os, vtkIndent indent) override;
35 
39  void Register(vtkObjectBase*) override;
40 
44  void UnRegister(vtkObjectBase*) override;
45 
50  const char* GetName();
51 
56  const char* GetLocation();
57 
59 
66  vtkInformationKey(const char* name, const char* location);
67  ~vtkInformationKey() override;
69 
75  virtual void ShallowCopy(vtkInformation* from, vtkInformation* to) = 0;
76 
83  virtual void DeepCopy(vtkInformation* from, vtkInformation* to) { this->ShallowCopy(from, to); }
84 
88  virtual int Has(vtkInformation* info);
89 
93  virtual void Remove(vtkInformation* info);
94 
98  virtual void Report(vtkInformation* info, vtkGarbageCollector* collector);
99 
101 
105  virtual void Print(ostream& os, vtkInformation* info);
107 
117  virtual bool NeedToExecute(
118  vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
119  {
120  return false;
121  }
122 
137  virtual void StoreMetaData(vtkInformation* vtkNotUsed(request),
138  vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
139  {
140  }
141 
150  virtual void CopyDefaultInformation(vtkInformation* vtkNotUsed(request),
151  vtkInformation* vtkNotUsed(fromInfo), vtkInformation* vtkNotUsed(toInfo))
152  {
153  }
154 
155 protected:
156  char* Name;
157  char* Location;
158 
159 #define vtkInformationKeySetStringMacro(name) \
160  virtual void Set##name(const char* _arg) \
161  { \
162  if (this->name == nullptr && _arg == nullptr) \
163  { \
164  return; \
165  } \
166  if (this->name && _arg && (!strcmp(this->name, _arg))) \
167  { \
168  return; \
169  } \
170  delete[] this->name; \
171  if (_arg) \
172  { \
173  size_t n = strlen(_arg) + 1; \
174  char* cp1 = new char[n]; \
175  const char* cp2 = (_arg); \
176  this->name = cp1; \
177  do \
178  { \
179  *cp1++ = *cp2++; \
180  } while (--n); \
181  } \
182  else \
183  { \
184  this->name = nullptr; \
185  } \
186  }
187 
190 
191  // Set/Get the value associated with this key instance in the given
192  // information object.
196 
197  // Report the object associated with this key instance in the given
198  // information object to the collector.
200 
201  // Helper for debug leaks support.
202  void ConstructClass(const char*);
203 
204 private:
205  vtkInformationKey(const vtkInformationKey&) = delete;
206  void operator=(const vtkInformationKey&) = delete;
207 };
208 
209 // Macros to define an information key instance in a C++ source file.
210 // The corresponding method declaration must appear in the class
211 // definition in the header file.
212 #define vtkInformationKeyMacro(CLASS, NAME, type) \
213  static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
214  vtkInformation##type##Key* CLASS::NAME() { return CLASS##_##NAME; }
215 #define vtkInformationKeySubclassMacro(CLASS, NAME, type, super) \
216  static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
217  vtkInformation##super##Key* CLASS::NAME() { return CLASS##_##NAME; }
218 #define vtkInformationKeyRestrictedMacro(CLASS, NAME, type, required) \
219  static vtkInformation##type##Key* CLASS##_##NAME = \
220  new vtkInformation##type##Key(#NAME, #CLASS, required); \
221  vtkInformation##type##Key* CLASS::NAME() { return CLASS##_##NAME; }
222 
223 VTK_ABI_NAMESPACE_END
224 #endif
Detect and break reference loops.
a simple class to control print indentation
Definition: vtkIndent.h:29
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:63
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:406
@ info
Definition: vtkX3D.h:376
@ value
Definition: vtkX3D.h:220
@ name
Definition: vtkX3D.h:219