VTK  9.6.20251228
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;
29
30class VTKCOMMONCORE_EXPORT vtkInformationKey : public vtkObjectBase
31{
32public:
34 void PrintSelf(ostream& os, vtkIndent indent) override;
35
40 const char* GetName() VTK_FUTURE_CONST;
41
46 const char* GetLocation() VTK_FUTURE_CONST;
47
49
56 vtkInformationKey(const char* name, const char* location);
57 ~vtkInformationKey() override;
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(VTK_FUTURE_CONST vtkInformation* info) VTK_FUTURE_CONST;
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.
184 const vtkObjectBase* GetAsObjectBase(VTK_FUTURE_CONST vtkInformation* info) const;
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
a simple class to control print indentation
Definition vtkIndent.h:108
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.
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)
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...
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.