VTK  9.7.20260715
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
19
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;
31
32class VTKCOMMONCORE_EXPORT vtkInformationKey : public vtkObjectBase
33{
34public:
37
39 void PrintSelf(ostream& os, vtkIndent indent) override;
40
45 const char* GetName() VTK_FUTURE_CONST;
46
51 const char* GetLocation() VTK_FUTURE_CONST;
52
54
61 vtkInformationKey(const char* name, const char* location);
62 ~vtkInformationKey() override;
64
70 virtual void ShallowCopy(vtkInformation* from, vtkInformation* to) = 0;
71
78 virtual void DeepCopy(vtkInformation* from, vtkInformation* to) { this->ShallowCopy(from, to); }
79
83 virtual int Has(VTK_FUTURE_CONST vtkInformation* info) VTK_FUTURE_CONST;
84
88 virtual void Remove(vtkInformation* info);
89
93 virtual void Report(vtkInformation* info, vtkGarbageCollector* collector);
94
96
99 void Print(vtkInformation* info);
100 virtual void Print(ostream& os, vtkInformation* info);
102
112 virtual bool NeedToExecute(
113 vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
114 {
115 return false;
116 }
117
132 virtual void StoreMetaData(vtkInformation* vtkNotUsed(request),
133 vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
134 {
135 }
136
145 virtual void CopyDefaultInformation(vtkInformation* vtkNotUsed(request),
146 vtkInformation* vtkNotUsed(fromInfo), vtkInformation* vtkNotUsed(toInfo))
147 {
148 }
149
150protected:
157
165 {
166 this->ManagerCallback = callback;
167 }
168
169 char* Name;
170 char* Location;
171
172#define vtkInformationKeySetStringMacro(name) \
173 virtual void Set##name(const char* _arg) \
174 { \
175 if (this->name == nullptr && _arg == nullptr) \
176 { \
177 return; \
178 } \
179 if (this->name && _arg && (!strcmp(this->name, _arg))) \
180 { \
181 return; \
182 } \
183 delete[] this->name; \
184 if (_arg) \
185 { \
186 size_t n = strlen(_arg) + 1; \
187 char* cp1 = new char[n]; \
188 const char* cp2 = (_arg); \
189 this->name = cp1; \
190 do \
191 { \
192 *cp1++ = *cp2++; \
193 } while (--n); \
194 } \
195 else \
196 { \
197 this->name = nullptr; \
198 } \
199 }
200
203
204 // Set/Get the value associated with this key instance in the given
205 // information object.
207 const vtkObjectBase* GetAsObjectBase(VTK_FUTURE_CONST vtkInformation* info) const;
209
210 // Report the object associated with this key instance in the given
211 // information object to the collector.
213
214 // Helper for debug leaks support.
215 void ConstructClass(const char*);
216
217private:
218 vtkInformationKey(const vtkInformationKey&) = delete;
219 void operator=(const vtkInformationKey&) = delete;
220
221 ManagerUnregisterCallback ManagerCallback = nullptr;
222};
223
224// Macros to define an information key instance in a C++ source file.
225// The corresponding method declaration must appear in the class
226// definition in the header file.
227#define vtkInformationKeyMacro(CLASS, NAME, type) \
228 static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
229 vtkInformation##type##Key* CLASS::NAME() \
230 { \
231 return CLASS##_##NAME; \
232 }
233#define vtkInformationKeySubclassMacro(CLASS, NAME, type, super) \
234 static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
235 vtkInformation##super##Key* CLASS::NAME() \
236 { \
237 return CLASS##_##NAME; \
238 }
239#define vtkInformationKeyRestrictedMacro(CLASS, NAME, type, required) \
240 static vtkInformation##type##Key* CLASS##_##NAME = \
241 new vtkInformation##type##Key(#NAME, #CLASS, required); \
242 vtkInformation##type##Key* CLASS::NAME() \
243 { \
244 return CLASS##_##NAME; \
245 }
246
247VTK_ABI_NAMESPACE_END
248#endif
a simple class to control print indentation
Definition vtkIndent.h:108
friend class vtkFilteringInformationKeyManager
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 char * GetLocation() VTK_FUTURE_CONST
Get the location of the key.
virtual int Has(VTK_FUTURE_CONST vtkInformation *info) VTK_FUTURE_CONST
Check whether this key appears in the given information object.
friend class vtkCommonInformationKeyManager
vtkInformationKeySetStringMacro(Name)
vtkObjectBase * GetAsObjectBase(vtkInformation *info)
virtual void StoreMetaData(vtkInformation *request, vtkInformation *pipelineInfo, vtkInformation *dobjInfo)
This function is only relevant when the pertaining key is used in a VTK pipeline.
void SetAsObjectBase(vtkInformation *info, vtkObjectBase *value)
void(*)(vtkInformationKey *) ManagerUnregisterCallback
Callback type used by information key managers to unregister a key when it is destroyed (e....
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 void DeepCopy(vtkInformation *from, vtkInformation *to)
Duplicate (new instance created) the entry associated with this key from one information object to an...
void SetManagerUnregisterCallback(ManagerUnregisterCallback callback)
Set the callback that will be invoked from the destructor to unregister this key from its manager.
const vtkObjectBase * GetAsObjectBase(VTK_FUTURE_CONST vtkInformation *info) const
virtual bool NeedToExecute(vtkInformation *pipelineInfo, vtkInformation *dobjInfo)
This function is only relevant when the pertaining key is used in a VTK pipeline.
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.
virtual void CopyDefaultInformation(vtkInformation *request, vtkInformation *fromInfo, vtkInformation *toInfo)
This function is only relevant when the pertaining key is used in a VTK pipeline.
const char * GetName() VTK_FUTURE_CONST
Get the name of the key.
Store vtkAlgorithm input/output information.
void operator=(const vtkObjectBase &)
friend class vtkInformationKey
Some classes need to clear the reference counts manually due to the way they work.
friend class vtkGarbageCollector
Some classes need to clear the reference counts manually due to the way they work.