VTK  9.5.2
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 }