VTK  9.4.20250227
vtkXMLDataHeaderPrivate.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
3
4#ifndef vtkXMLDataHeaderPrivate_DoNotInclude
5#error "do not include unless you know what you are doing"
6#endif
7
8#ifndef vtkXMLDataHeaderPrivate_h
9#define vtkXMLDataHeaderPrivate_h
10
11#include "vtkType.h"
12#include <vector>
13
14// Abstract interface using type vtkTypeUInt64 to access an array
15// of either vtkTypeUInt32 or vtkTypeUInt64. Shared by vtkXMLWriter
16// and vtkXMLDataParser to write/read binary data headers.
17VTK_ABI_NAMESPACE_BEGIN
19{
20public:
21 virtual void Resize(size_t count) = 0;
22 virtual vtkTypeUInt64 Get(size_t index) const = 0;
23 virtual bool Set(size_t index, vtkTypeUInt64 value) = 0;
24 virtual size_t WordSize() const = 0;
25 virtual size_t WordCount() const = 0;
26 virtual unsigned char* Data() = 0;
27 size_t DataSize() const { return this->WordCount() * this->WordSize(); }
28 virtual ~vtkXMLDataHeader() = default;
29 static inline vtkXMLDataHeader* New(int width, size_t count);
30};
31
32template <typename T>
34{
35 std::vector<T> Header;
36
37public:
39 : Header(n, 0)
40 {
41 }
42 void Resize(size_t count) override { this->Header.resize(count, 0); }
43 vtkTypeUInt64 Get(size_t index) const override { return this->Header[index]; }
44 bool Set(size_t index, vtkTypeUInt64 value) override
45 {
46 this->Header[index] = T(value);
47 return vtkTypeUInt64(this->Header[index]) == value;
48 }
49 size_t WordSize() const override { return sizeof(T); }
50 size_t WordCount() const override { return this->Header.size(); }
51 unsigned char* Data() override { return reinterpret_cast<unsigned char*>(&this->Header[0]); }
52};
53
54vtkXMLDataHeader* vtkXMLDataHeader::New(int width, size_t count)
55{
56 switch (width)
57 {
58 case 32:
60 case 64:
62 }
63 return nullptr;
64}
65
66VTK_ABI_NAMESPACE_END
67#endif
68// VTK-HeaderTest-Exclude: vtkXMLDataHeaderPrivate.h
bool Set(size_t index, vtkTypeUInt64 value) override
size_t WordCount() const override
vtkTypeUInt64 Get(size_t index) const override
unsigned char * Data() override
void Resize(size_t count) override
size_t WordSize() const override
virtual vtkTypeUInt64 Get(size_t index) const =0
static vtkXMLDataHeader * New(int width, size_t count)
virtual size_t WordCount() const =0
virtual bool Set(size_t index, vtkTypeUInt64 value)=0
virtual unsigned char * Data()=0
virtual size_t WordSize() const =0
virtual void Resize(size_t count)=0
virtual ~vtkXMLDataHeader()=default