VTK  9.3.20240420
vtkXMLOffsetsManager.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
30#ifndef vtkXMLOffsetsManager_DoNotInclude
31#error "do not include unless you know what you are doing"
32#endif
33
34#ifndef vtkXMLOffsetsManager_h
35#define vtkXMLOffsetsManager_h
36
37#include "vtkSystemIncludes.h"
38#include <cassert>
39#include <vector>
40
41//----------------------------------------------------------------------------
42VTK_ABI_NAMESPACE_BEGIN
44{
45public:
46 // Construct with default (vtkMTimeType)-1 MTime
48 {
49 this->LastMTime = static_cast<vtkMTimeType>(-1); // almost invalid state
50 }
51 void Allocate(int numTimeStep)
52 {
53 assert(numTimeStep > 0);
54 this->Positions.resize(numTimeStep);
55 this->RangeMinPositions.resize(numTimeStep);
56 this->RangeMaxPositions.resize(numTimeStep);
57 this->OffsetValues.resize(numTimeStep);
58 }
59 vtkTypeInt64& GetPosition(unsigned int t)
60 {
61 assert(t < this->Positions.size());
62 return this->Positions[t];
63 }
64 vtkTypeInt64& GetRangeMinPosition(unsigned int t)
65 {
66 assert(t < this->RangeMinPositions.size());
67 return this->RangeMinPositions[t];
68 }
69 vtkTypeInt64& GetRangeMaxPosition(unsigned int t)
70 {
71 assert(t < this->RangeMaxPositions.size());
72 return this->RangeMaxPositions[t];
73 }
74 vtkTypeInt64& GetOffsetValue(unsigned int t)
75 {
76 assert(t < this->OffsetValues.size());
77 return this->OffsetValues[t];
78 }
79 vtkMTimeType& GetLastMTime() { return this->LastMTime; }
80
81private:
82 vtkMTimeType LastMTime; // Previously written dataarray mtime
83 // at some point these vectors could become a vector of map <string,ul>
84 // where the string is the name of the offset, but that would be pretty fat
85 // and slow, but if another couple offsets are added then we should
86 // consider doing it
87 // Position in the stream to write the offset
88 std::vector<vtkTypeInt64> Positions;
89 std::vector<vtkTypeInt64> RangeMinPositions; // Where is this
90 std::vector<vtkTypeInt64> RangeMaxPositions; // Whee is this
91
92 std::vector<vtkTypeInt64> OffsetValues; // Value of offset
93};
94
95//----------------------------------------------------------------------------
97{
98public:
99 // This is kind of a hack since we need to consider both the case of Points
100 // with only one array over time and PointData with possibly multiple array
101 // over time therefore we need to use a OffsetsManagerGroup for
102 // representing offset from Points but OffsetsManagerArray for
103 // PointData. In both case the toplevel structure is a container of
104 // Pieces...
105 OffsetsManager& GetPiece(unsigned int index)
106 {
107 assert(index < this->Internals.size());
108 OffsetsManager& e = this->Internals[index];
109 return e;
110 }
111 // GetElement should be used when manipulating a OffsetsManagerArray
112 OffsetsManager& GetElement(unsigned int index)
113 {
114 // commenting the following out, this is an heisenbug which only appears
115 // on gcc when exporting GLIBCPP_NEW=1. If you try to print the value or
116 // run through gdb it disappears //assert( index <
117 // this->Internals.size());
118 OffsetsManager& e = this->Internals[index];
119 return e;
120 }
121 unsigned int GetNumberOfElements() { return static_cast<unsigned int>(this->Internals.size()); }
122 void Allocate(int numElements)
123 {
124 assert(numElements >= 0); // allow 0 for empty FieldData
125 this->Internals.resize(numElements);
126 }
127 void Allocate(int numElements, int numTimeSteps)
128 {
129 assert(numElements >= 0); // allow 0 for empty FieldData
130 assert(numTimeSteps > 0);
131 this->Internals.resize(numElements);
132 for (int i = 0; i < numElements; i++)
133 {
134 this->Internals[i].Allocate(numTimeSteps);
135 }
136 }
137
138private:
139 std::vector<OffsetsManager> Internals;
140};
141
142//----------------------------------------------------------------------------
144{
145public:
146 OffsetsManagerGroup& GetPiece(unsigned int index)
147 {
148 assert(index < this->Internals.size());
149 return this->Internals[index];
150 }
151 void Allocate(int numPieces)
152 {
153 assert(numPieces > 0);
154 // Force re-initialization of values.
155 this->Internals.resize(0);
156 this->Internals.resize(numPieces);
157 }
158 void Allocate(int numPieces, int numElements, int numTimeSteps)
159 {
160 assert(numPieces > 0);
161 assert(numElements > 0);
162 assert(numTimeSteps > 0);
163
164 // Force re-initialization of values.
165 this->Internals.resize(0);
166 this->Internals.resize(numPieces);
167 for (int i = 0; i < numPieces; i++)
168 {
169 this->Internals[i].Allocate(numElements, numTimeSteps);
170 }
171 }
172
173private:
174 std::vector<OffsetsManagerGroup> Internals;
175};
176
177VTK_ABI_NAMESPACE_END
178#endif
179// VTK-HeaderTest-Exclude: vtkXMLOffsetsManager.h
void Allocate(int numPieces)
OffsetsManagerGroup & GetPiece(unsigned int index)
void Allocate(int numPieces, int numElements, int numTimeSteps)
OffsetsManager & GetPiece(unsigned int index)
void Allocate(int numElements)
unsigned int GetNumberOfElements()
OffsetsManager & GetElement(unsigned int index)
void Allocate(int numElements, int numTimeSteps)
Helper class due to PIMPL excess.
void Allocate(int numTimeStep)
vtkTypeInt64 & GetPosition(unsigned int t)
vtkTypeInt64 & GetRangeMaxPosition(unsigned int t)
vtkTypeInt64 & GetOffsetValue(unsigned int t)
vtkMTimeType & GetLastMTime()
vtkTypeInt64 & GetRangeMinPosition(unsigned int t)
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270