VTK  9.7.20260927
vtkMemoryDescriptor.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
64
65#ifndef vtkMemoryDescriptor_h
66#define vtkMemoryDescriptor_h
67
68#include "vtkCommonCoreModule.h" // For export macro
69#include "vtkObject.h"
70#include "vtkType.h" // For vtkTypeInt64
71
72VTK_ABI_NAMESPACE_BEGIN
73
74class VTKCOMMONCORE_EXPORT vtkMemoryDescriptor : public vtkObject
75{
76public:
79 void PrintSelf(ostream& os, vtkIndent indent) override;
80
89 using ReleaseFunction = void (*)(void* context);
90
92
96 vtkSetMacro(Pointer, vtkTypeInt64);
97 vtkGetMacro(Pointer, vtkTypeInt64);
99
101
104 vtkSetMacro(SizeInBytes, vtkTypeInt64);
105 vtkGetMacro(SizeInBytes, vtkTypeInt64);
107
109
112 vtkSetStringMacro(MemorySpace);
113 vtkGetStringMacro(MemorySpace);
115
117
124 vtkSetStringMacro(Role);
125 vtkGetStringMacro(Role);
127
131 void Set(vtkTypeInt64 pointer, vtkTypeInt64 sizeInBytes, const char* memorySpace,
132 const char* role = "data");
133
135
144 void SetOwner(vtkObject* owner);
145 vtkGetObjectMacro(Owner, vtkObject);
147
157 void SetRelease(ReleaseFunction release, void* context);
158
171 void SetReleaseAddress(vtkTypeInt64 release, vtkTypeInt64 context);
172
174
177 ReleaseFunction GetRelease() const { return this->Release; }
178 void* GetReleaseContext() const { return this->ReleaseContext; }
180
182
186 vtkTypeInt64 GetReleaseAddress() const { return reinterpret_cast<vtkTypeInt64>(this->Release); }
187 vtkTypeInt64 GetReleaseContextAddress() const
188 {
189 return reinterpret_cast<vtkTypeInt64>(this->ReleaseContext);
190 }
191
192
196 bool HasOwnership() const { return this->Owner != nullptr || this->Release != nullptr; }
197
209 bool TakeRelease(ReleaseFunction& release, void*& context);
210
211protected:
214
215 vtkTypeInt64 Pointer = 0;
216 vtkTypeInt64 SizeInBytes = 0;
217 char* MemorySpace = nullptr;
218 char* Role = nullptr;
219
220 vtkObject* Owner = nullptr;
222 void* ReleaseContext = nullptr;
223
224private:
226 void operator=(const vtkMemoryDescriptor&) = delete;
227
229 void ClearOwnership();
230};
231
232VTK_ABI_NAMESPACE_END
233#endif // vtkMemoryDescriptor_h
a simple class to control print indentation
Definition vtkIndent.h:108
void * GetReleaseContext() const
The release callback and its context, or nullptr if none is held.
vtkTypeInt64 GetReleaseContextAddress() const
The release callback and its context as integers, for wrapped callers.
bool TakeRelease(ReleaseFunction &release, void *&context)
Hand the release duty to the caller.
void Set(vtkTypeInt64 pointer, vtkTypeInt64 sizeInBytes, const char *memorySpace, const char *role="data")
Convenience: set the description in one call.
void SetOwner(vtkObject *owner)
Keep a VTK object alive for as long as this descriptor lives.
void(*)(void *context) ReleaseFunction
Signature of a release callback.
ReleaseFunction GetRelease() const
The release callback and its context, or nullptr if none is held.
void SetRelease(ReleaseFunction release, void *context)
Keep non-VTK memory alive by holding a release callback.
vtkTypeInt64 GetReleaseAddress() const
The release callback and its context as integers, for wrapped callers.
void SetReleaseAddress(vtkTypeInt64 release, vtkTypeInt64 context)
As SetRelease(), taking both addresses as integers.
~vtkMemoryDescriptor() override
bool HasOwnership() const
Whether this descriptor currently keeps the memory alive.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkMemoryDescriptor * New()