VTK  9.2.20221001
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 VTK_ABI_NAMESPACE_BEGIN
40 class vtkInformation;
41 
42 class VTKCOMMONCORE_EXPORT vtkInformationKey : public vtkObjectBase
43 {
44 public:
46  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
51  void Register(vtkObjectBase*) override;
52 
56  void UnRegister(vtkObjectBase*) override;
57 
62  const char* GetName();
63 
68  const char* GetLocation();
69 
71 
78  vtkInformationKey(const char* name, const char* location);
79  ~vtkInformationKey() override;
81 
87  virtual void ShallowCopy(vtkInformation* from, vtkInformation* to) = 0;
88 
95  virtual void DeepCopy(vtkInformation* from, vtkInformation* to) { 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 
117  virtual void Print(ostream& os, vtkInformation* info);
119 
129  virtual bool NeedToExecute(
130  vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
131  {
132  return false;
133  }
134 
149  virtual void StoreMetaData(vtkInformation* vtkNotUsed(request),
150  vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
151  {
152  }
153 
162  virtual void CopyDefaultInformation(vtkInformation* vtkNotUsed(request),
163  vtkInformation* vtkNotUsed(fromInfo), vtkInformation* vtkNotUsed(toInfo))
164  {
165  }
166 
167 protected:
168  char* Name;
169  char* Location;
170 
171 #define vtkInformationKeySetStringMacro(name) \
172  virtual void Set##name(const char* _arg) \
173  { \
174  if (this->name == nullptr && _arg == nullptr) \
175  { \
176  return; \
177  } \
178  if (this->name && _arg && (!strcmp(this->name, _arg))) \
179  { \
180  return; \
181  } \
182  delete[] this->name; \
183  if (_arg) \
184  { \
185  size_t n = strlen(_arg) + 1; \
186  char* cp1 = new char[n]; \
187  const char* cp2 = (_arg); \
188  this->name = cp1; \
189  do \
190  { \
191  *cp1++ = *cp2++; \
192  } while (--n); \
193  } \
194  else \
195  { \
196  this->name = nullptr; \
197  } \
198  }
199 
202 
203  // Set/Get the value associated with this key instance in the given
204  // information object.
208 
209  // Report the object associated with this key instance in the given
210  // information object to the collector.
212 
213  // Helper for debug leaks support.
214  void ConstructClass(const char*);
215 
216 private:
217  vtkInformationKey(const vtkInformationKey&) = delete;
218  void operator=(const vtkInformationKey&) = delete;
219 };
220 
221 // Macros to define an information key instance in a C++ source file.
222 // The corresponding method declaration must appear in the class
223 // definition in the header file.
224 #define vtkInformationKeyMacro(CLASS, NAME, type) \
225  static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
226  vtkInformation##type##Key* CLASS::NAME() { return CLASS##_##NAME; }
227 #define vtkInformationKeySubclassMacro(CLASS, NAME, type, super) \
228  static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
229  vtkInformation##super##Key* CLASS::NAME() { return CLASS##_##NAME; }
230 #define vtkInformationKeyRestrictedMacro(CLASS, NAME, type, required) \
231  static vtkInformation##type##Key* CLASS##_##NAME = \
232  new vtkInformation##type##Key(#NAME, #CLASS, required); \
233  vtkInformation##type##Key* CLASS::NAME() { return CLASS##_##NAME; }
234 
235 VTK_ABI_NAMESPACE_END
236 #endif
Detect and break reference loops.
a simple class to control print indentation
Definition: vtkIndent.h:120
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:75
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:418
@ info
Definition: vtkX3D.h:388
@ value
Definition: vtkX3D.h:232
@ name
Definition: vtkX3D.h:231