VTK
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 =========================================================================*/
29 #ifndef vtkInformationKey_h
30 #define vtkInformationKey_h
31 
32 #include "vtkCommonCoreModule.h" // For export macro
33 #include "vtkObject.h" // Need vtkTypeMacro
34 #include "vtkObjectBase.h"
35 
36 class vtkInformation;
37 
38 class VTKCOMMONCORE_EXPORT vtkInformationKey : public vtkObjectBase
39 {
40 public:
41  vtkBaseTypeMacro(vtkInformationKey, vtkObjectBase);
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
47  void Register(vtkObjectBase*) override;
48 
52  void UnRegister(vtkObjectBase*) override;
53 
58  const char* GetName();
59 
64  const char* GetLocation();
65 
67 
74  vtkInformationKey(const char* name, const char* location);
75  ~vtkInformationKey() override;
77 
83  virtual void ShallowCopy(vtkInformation* from, vtkInformation* to) = 0;
84 
91  virtual void DeepCopy(vtkInformation* from, vtkInformation* to) { this->ShallowCopy(from, to); }
92 
96  virtual int Has(vtkInformation* info);
97 
101  virtual void Remove(vtkInformation* info);
102 
106  virtual void Report(vtkInformation* info, vtkGarbageCollector* collector);
107 
109 
112  void Print(vtkInformation* info);
113  virtual void Print(ostream& os, vtkInformation* info);
115 
125  virtual bool NeedToExecute(
126  vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
127  {
128  return false;
129  }
130 
145  virtual void StoreMetaData(vtkInformation* vtkNotUsed(request),
146  vtkInformation* vtkNotUsed(pipelineInfo), vtkInformation* vtkNotUsed(dobjInfo))
147  {
148  }
149 
158  virtual void CopyDefaultInformation(vtkInformation* vtkNotUsed(request),
159  vtkInformation* vtkNotUsed(fromInfo), vtkInformation* vtkNotUsed(toInfo))
160  {
161  }
162 
163 protected:
164  char* Name;
165  char* Location;
166 
167 #define vtkInformationKeySetStringMacro(name) \
168  virtual void Set##name(const char* _arg) \
169  { \
170  if (this->name == nullptr && _arg == nullptr) \
171  { \
172  return; \
173  } \
174  if (this->name && _arg && (!strcmp(this->name, _arg))) \
175  { \
176  return; \
177  } \
178  delete[] this->name; \
179  if (_arg) \
180  { \
181  size_t n = strlen(_arg) + 1; \
182  char* cp1 = new char[n]; \
183  const char* cp2 = (_arg); \
184  this->name = cp1; \
185  do \
186  { \
187  *cp1++ = *cp2++; \
188  } while (--n); \
189  } \
190  else \
191  { \
192  this->name = nullptr; \
193  } \
194  }
195 
198 
199  // Set/Get the value associated with this key instance in the given
200  // information object.
201  void SetAsObjectBase(vtkInformation* info, vtkObjectBase* value);
202  const vtkObjectBase* GetAsObjectBase(vtkInformation* info) const;
203  vtkObjectBase* GetAsObjectBase(vtkInformation* info);
204 
205  // Report the object associated with this key instance in the given
206  // information object to the collector.
207  void ReportAsObjectBase(vtkInformation* info, vtkGarbageCollector* collector);
208 
209  // Helper for debug leaks support.
210  void ConstructClass(const char*);
211 
212 private:
213  vtkInformationKey(const vtkInformationKey&) = delete;
214  void operator=(const vtkInformationKey&) = delete;
215 };
216 
217 // Macros to define an information key instance in a C++ source file.
218 // The corresponding method declaration must appear in the class
219 // definition in the header file.
220 #define vtkInformationKeyMacro(CLASS, NAME, type) \
221  static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
222  vtkInformation##type##Key* CLASS::NAME() { return CLASS##_##NAME; }
223 #define vtkInformationKeySubclassMacro(CLASS, NAME, type, super) \
224  static vtkInformation##type##Key* CLASS##_##NAME = new vtkInformation##type##Key(#NAME, #CLASS); \
225  vtkInformation##super##Key* CLASS::NAME() { return CLASS##_##NAME; }
226 #define vtkInformationKeyRestrictedMacro(CLASS, NAME, type, required) \
227  static vtkInformation##type##Key* CLASS##_##NAME = \
228  new vtkInformation##type##Key(#NAME, #CLASS, required); \
229  vtkInformation##type##Key* CLASS::NAME() { return CLASS##_##NAME; }
230 
231 #endif
vtkObjectBase::operator=
void operator=(const vtkObjectBase &)
Definition: vtkObjectBase.h:219
vtkInformationKey::Location
char * Location
Definition: vtkInformationKey.h:165
vtkInformationKey::DeepCopy
virtual void DeepCopy(vtkInformation *from, vtkInformation *to)
Duplicate (new instance created) the entry associated with this key from one information object to an...
Definition: vtkInformationKey.h:91
vtkObjectBase.h
vtkObjectBase::Print
void Print(ostream &os)
Print an object to an ostream.
vtkX3D::value
Definition: vtkX3D.h:226
vtkObjectBase::Register
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
vtkInformationKey::NeedToExecute
virtual bool NeedToExecute(vtkInformation *vtkNotUsed(pipelineInfo), vtkInformation *vtkNotUsed(dobjInfo))
This function is only relevant when the pertaining key is used in a VTK pipeline.
Definition: vtkInformationKey.h:125
vtkInformationKeySetStringMacro
#define vtkInformationKeySetStringMacro(name)
Definition: vtkInformationKey.h:167
vtkInformationKey::Name
char * Name
Definition: vtkInformationKey.h:164
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:63
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkInformationKey::StoreMetaData
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.
Definition: vtkInformationKey.h:145
vtkX3D::name
Definition: vtkX3D.h:225
vtkGarbageCollector
Detect and break reference loops.
Definition: vtkGarbageCollector.h:94
vtkObject.h
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:64
vtkX3D::info
Definition: vtkX3D.h:382
vtkObjectBase::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkInformationKey::CopyDefaultInformation
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.
Definition: vtkInformationKey.h:158
vtkX3D::location
Definition: vtkX3D.h:412
vtkInformationKey
Superclass for vtkInformation keys.
Definition: vtkInformationKey.h:38
vtkObjectBase::UnRegister
virtual void UnRegister(vtkObjectBase *o)
Decrease the reference count (release by another object).