VTK  9.4.20241213
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
27VTK_ABI_NAMESPACE_BEGIN
28class vtkInformation;
29
30class VTKCOMMONCORE_EXPORT vtkInformationKey : public vtkObjectBase
31{
32public:
34 void PrintSelf(ostream& os, vtkIndent indent) override;
35
40 const char* GetName();
41
46 const char* GetLocation();
47
49
56 vtkInformationKey(const char* name, const char* location);
59
65 virtual void ShallowCopy(vtkInformation* from, vtkInformation* to) = 0;
66
73 virtual void DeepCopy(vtkInformation* from, vtkInformation* to) { this->ShallowCopy(from, to); }
74
78 virtual int Has(vtkInformation* info);
79
83 virtual void Remove(vtkInformation* info);
84
88 virtual void Report(vtkInformation* info, vtkGarbageCollector* collector);
89
91
94 void Print(vtkInformation* info);
95 virtual void Print(ostream& os, vtkInformation* info);
97
107 virtual bool NeedToExecute(
108 vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
109 {
110 return false;
111 }
112
127 virtual void StoreMetaData(vtkInformation* vtkNotUsed(request),
128 vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
129 {
130 }
131
140 virtual void CopyDefaultInformation(vtkInformation* vtkNotUsed(request),
141 vtkInformation* vtkNotUsed(fromInfo), vtkInformation* vtkNotUsed(toInfo))
142 {
143 }
144
145protected:
146 char* Name;
147 char* Location;
148
149#define vtkInformationKeySetStringMacro(name) \
150 virtual void Set##name(const char* _arg) \
151 { \
152 if (this->name == nullptr && _arg == nullptr) \
153 { \
154 return; \
155 } \
156 if (this->name && _arg && (!strcmp(this->name, _arg))) \
157 { \
158 return; \
159 } \
160 delete[] this->name; \
161 if (_arg) \
162 { \
163 size_t n = strlen(_arg) + 1; \
164 char* cp1 = new char[n]; \
165 const char* cp2 = (_arg); \
166 this->name = cp1; \
167 do \
168 { \
169 *cp1++ = *cp2++; \
170 } while (--n); \
171 } \
172 else \
173 { \
174 this->name = nullptr; \
175 } \
176 }
177
180
181 // Set/Get the value associated with this key instance in the given
182 // information object.
186
187 // Report the object associated with this key instance in the given
188 // information object to the collector.
190
191 // Helper for debug leaks support.
192 void ConstructClass(const char*);
193
194private:
195 vtkInformationKey(const vtkInformationKey&) = delete;
196 void operator=(const vtkInformationKey&) = delete;
197};
198
199// Macros to define an information key instance in a C++ source file.
200// The corresponding method declaration must appear in the class
201// definition in the header file.
202#define vtkInformationKeyMacro(CLASS, NAME, type) \
203 static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
204 vtkInformation##type##Key* CLASS::NAME() \
205 { \
206 return CLASS##_##NAME; \
207 }
208#define vtkInformationKeySubclassMacro(CLASS, NAME, type, super) \
209 static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
210 vtkInformation##super##Key* CLASS::NAME() \
211 { \
212 return CLASS##_##NAME; \
213 }
214#define vtkInformationKeyRestrictedMacro(CLASS, NAME, type, required) \
215 static vtkInformation##type##Key* CLASS##_##NAME = \
216 new vtkInformation##type##Key(#NAME, #CLASS, required); \
217 vtkInformation##type##Key* CLASS::NAME() \
218 { \
219 return CLASS##_##NAME; \
220 }
221
222VTK_ABI_NAMESPACE_END
223#endif
Detect and break reference loops.
a simple class to control print indentation
Definition vtkIndent.h:108
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)
vtkInformationKeySetStringMacro(Name)
vtkObjectBase * GetAsObjectBase(vtkInformation *info)
~vtkInformationKey() override
Key instances are static data that need to be created and destroyed.
void SetAsObjectBase(vtkInformation *info, vtkObjectBase *value)
const char * GetName()
Get the name of the key.
const char * GetLocation()
Get the location of the key.
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.
const vtkObjectBase * GetAsObjectBase(vtkInformation *info) const
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...
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.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
void operator=(const vtkObjectBase &)
friend class vtkInformationKey
Some classes need to clear the reference counts manually due to the way they work.