31 template <
class ScalarTypeT>
36 typedef ScalarTypeT ScalarType;
59 void SetFreeFunction(
bool noFreeFunction,
void(*deleteFunction)(
void*)=free);
96 void operator=(
const vtkBuffer&) =
delete;
99 template <
class ScalarT>
106 template <
typename ScalarT>
109 if (this->Pointer != array)
111 if(this->DeleteFunction)
113 this->DeleteFunction(this->Pointer);
115 this->Pointer = array;
120 template <
typename ScalarT>
125 this->DeleteFunction =
nullptr;
129 this->DeleteFunction = deleteFunction;
134 template <
typename ScalarT>
138 this->SetBuffer(
nullptr, 0);
141 ScalarType* newArray =
142 static_cast<ScalarType*>(malloc(
size *
sizeof(ScalarType)));
145 this->SetBuffer(newArray,
size);
146 this->DeleteFunction = free;
155 template <
typename ScalarT>
158 if (newsize == 0) {
return this->Allocate(0); }
160 if (this->Pointer && this->DeleteFunction != free)
162 ScalarType* newArray =
163 static_cast<ScalarType*>(malloc(newsize *
sizeof(ScalarType)));
168 std::copy(this->Pointer, this->Pointer + std::min(this->Size, newsize),
171 this->SetBuffer(newArray, newsize);
172 this->DeleteFunction = free;
178 ScalarType* newArray = static_cast<ScalarType*>(
179 realloc(this->Pointer, newsize *
sizeof(ScalarType)));
184 this->Pointer = newArray;
185 this->Size = newsize;
static vtkBuffer< ScalarTypeT > * New()
vtkIdType GetSize() const
Return the number of elements the current buffer can hold.
const ScalarType * GetBuffer() const
abstract base class for most VTK objects
vtkTemplateTypeMacro(vtkBuffer< ScalarTypeT >, vtkObject) typedef ScalarTypeT ScalarType
void SetFreeFunction(bool noFreeFunction, void(*deleteFunction)(void *)=free)
Set the free function to be used when releasing this object.
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
ScalarType * GetBuffer()
Access the buffer as a scalar pointer.
void SetBuffer(ScalarType *array, vtkIdType size)
Set the memory buffer that this vtkBuffer object will manage.
bool Reallocate(vtkIdType newsize)
Allocate a new buffer that holds newsize elements.
void(* DeleteFunction)(void *)
bool Allocate(vtkIdType size)
Allocate a new buffer that holds size elements.
#define VTK_STANDARD_NEW_BODY(thisClass)