VTK
vtkAOSDataArrayTemplate.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkAOSDataArrayTemplate.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=========================================================================*/
34#ifndef vtkAOSDataArrayTemplate_h
35#define vtkAOSDataArrayTemplate_h
36
37#include "vtkCommonCoreModule.h" // For export macro
38#include "vtkGenericDataArray.h"
39#include "vtkBuffer.h" // For storage buffer.
40
41// The export macro below makes no sense, but is necessary for older compilers
42// when we export instantiations of this class from vtkCommonCore.
43template <class ValueTypeT>
44class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate :
45 public vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>, ValueTypeT>
46{
49public:
52 typedef typename Superclass::ValueType ValueType;
53
55 {
58 };
59
61
65 inline ValueType GetValue(vtkIdType valueIdx) const
66 {
67 return this->Buffer->GetBuffer()[valueIdx];
68 }
69
73 inline void SetValue(vtkIdType valueIdx, ValueType value)
74 {
75 this->Buffer->GetBuffer()[valueIdx] = value;
76 }
77
79
82 inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
83 {
84 const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
85 std::copy(this->Buffer->GetBuffer() + valueIdx,
86 this->Buffer->GetBuffer() + valueIdx + this->NumberOfComponents,
87 tuple);
88 }
90
92
95 inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
96 {
97 const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
98 std::copy(tuple, tuple + this->NumberOfComponents,
99 this->Buffer->GetBuffer() + valueIdx);
100 }
102
106 inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
107 {
108 return this->Buffer->GetBuffer()[this->NumberOfComponents*tupleIdx + comp];
109 }
110
112
115 inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
116 {
117 const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents + comp;
118 this->SetValue(valueIdx, value);
119 }
121
123
129 void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) VTK_OVERRIDE;
131
133
141 void* GetVoidPointer(vtkIdType valueIdx) VTK_OVERRIDE;
143
145
156 void SetArray(ValueType* array, vtkIdType size, int save, int deleteMethod);
158 void SetVoidArray(void* array, vtkIdType size, int save) VTK_OVERRIDE;
159 void SetVoidArray(void* array, vtkIdType size, int save,
160 int deleteMethod) VTK_OVERRIDE;
162
174
179 typedef ValueType* Iterator;
180 Iterator Begin() { return Iterator(this->GetVoidPointer(0)); }
181 Iterator End() { return Iterator(this->GetVoidPointer(this->MaxId + 1)); }
182
184
193 {
194 if (source)
195 {
196 switch (source->GetArrayType())
197 {
199 if (vtkDataTypesCompare(source->GetDataType(),
201 {
202 return static_cast<vtkAOSDataArrayTemplate<ValueType>*>(source);
203 }
204 break;
205 }
206 }
207 return NULL;
208 }
210
213 bool HasStandardMemoryLayout() VTK_OVERRIDE { return true; }
214 void ShallowCopy(vtkDataArray *other) VTK_OVERRIDE;
215
217
221 VTK_LEGACY(void GetTupleValue(vtkIdType tupleIdx, ValueType *tuple));
222 VTK_LEGACY(void SetTupleValue(vtkIdType tupleIdx, const ValueType *tuple));
223 VTK_LEGACY(void InsertTupleValue(vtkIdType tupleIdx, const ValueType *tuple));
224 VTK_LEGACY(vtkIdType InsertNextTupleValue(const ValueType *tuple));
226
227 // Reimplemented for efficiency:
228 void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
229 vtkAbstractArray* source) VTK_OVERRIDE;
230 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
231 // using Superclass::InsertTuples;
232 void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
233 vtkAbstractArray *source) VTK_OVERRIDE
234 { this->Superclass::InsertTuples(dstIds, srcIds, source); }
235
236protected:
239
244 bool AllocateTuples(vtkIdType numTuples);
245
250 bool ReallocateTuples(vtkIdType numTuples);
251
253
254private:
255 vtkAOSDataArrayTemplate(const vtkAOSDataArrayTemplate&) VTK_DELETE_FUNCTION;
256 void operator=(const vtkAOSDataArrayTemplate&) VTK_DELETE_FUNCTION;
257
258 friend class vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>,
259 ValueTypeT>;
260
261};
262
263// Declare vtkArrayDownCast implementations for AoS containers:
265
266// This macro is used by the subclasses to create dummy
267// declarations for these functions such that the wrapper
268// can see them. The wrappers ignore vtkAOSDataArrayTemplate.
269#define vtkCreateWrappedArrayInterface(T) \
270 int GetDataType(); \
271 void GetTypedTuple(vtkIdType i, T* tuple); \
272 void SetTypedTuple(vtkIdType i, const T* tuple); \
273 void InsertTypedTuple(vtkIdType i, const T* tuple); \
274 vtkIdType InsertNextTypedTuple(const T* tuple); \
275 T GetValue(vtkIdType id); \
276 void SetValue(vtkIdType id, T value); \
277 void SetNumberOfValues(vtkIdType number); \
278 void InsertValue(vtkIdType id, T f); \
279 vtkIdType InsertNextValue(T f); \
280 T *GetValueRange(int comp); \
281 T *GetValueRange(); \
282 T* WritePointer(vtkIdType id, vtkIdType number); \
283 T* GetPointer(vtkIdType id)/*; \
284
285 * These methods are not wrapped to avoid wrappers exposing these
286 * easy-to-get-wrong methods because passing in the wrong value for 'save' is
287 * guaranteed to cause a memory issue down the line. Either the wrappers
288 * didn't use malloc to allocate the memory or the memory isn't actually
289 * persisted because a temporary array is used that doesn't persist like this
290 * method expects.
291
292 void SetArray(T* array, vtkIdType size, int save); \
293 void SetArray(T* array, vtkIdType size, int save, int deleteMethod) */
294
295#endif // header guard
296
297// This portion must be OUTSIDE the include blockers. This is used to tell
298// libraries other than vtkCommonCore that instantiations of
299// vtkAOSDataArrayTemplate can be found externally. This prevents each library
300// from instantiating these on their own.
301#ifdef VTK_AOS_DATA_ARRAY_TEMPLATE_INSTANTIATING
302#define VTK_AOS_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
303 template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate< T >
304#elif defined(VTK_USE_EXTERN_TEMPLATE)
305#ifndef VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
306#define VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
307#ifdef _MSC_VER
308#pragma warning (push)
309// The following is needed when the vtkAOSDataArrayTemplate is declared
310// dllexport and is used from another class in vtkCommonCore
311#pragma warning (disable: 4910) // extern and dllexport incompatible
312#endif
314 extern template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate)
315#ifdef _MSC_VER
316#pragma warning (pop)
317#endif
318#endif // VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
319
320// The following clause is only for MSVC 2008 and 2010
321#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
322#pragma warning (push)
323
324// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
325#pragma warning (disable: 4091)
326
327// Compiler-specific extension warning.
328#pragma warning (disable: 4231)
329
330// We need to disable warning 4910 and do an extern dllexport
331// anyway. When deriving vtkCharArray and other types from an
332// instantiation of this template the compiler does an explicit
333// instantiation of the base class. From outside the vtkCommon
334// library we block this using an extern dllimport instantiation.
335// For classes inside vtkCommon we should be able to just do an
336// extern instantiation, but VS 2008 complains about missing
337// definitions. We cannot do an extern dllimport inside vtkCommon
338// since the symbols are local to the dll. An extern dllexport
339// seems to be the only way to convince VS 2008 to do the right
340// thing, so we just disable the warning.
341#pragma warning (disable: 4910) // extern and dllexport incompatible
342
343// Use an "extern explicit instantiation" to give the class a DLL
344// interface. This is a compiler-specific extension.
346 extern template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate)
347
348#pragma warning (pop)
349
350#endif
351
352// VTK-HeaderTest-Exclude: vtkAOSDataArrayTemplate.h
Array-Of-Structs implementation of vtkGenericDataArray.
static vtkAOSDataArrayTemplate< ValueType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkAOSDataArrayTemplate.
void SetVoidArray(void *array, vtkIdType size, int save) override
void SetArray(ValueType *array, vtkIdType size, int save)
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
VTK_NEWINSTANCE vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source) override
Copy n consecutive tuples starting at srcStart from the source array to this array,...
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
void DataElementChanged(vtkIdType)
Tell the array explicitly that a single data element has changed.
void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod) override
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Get the address of a particular data index.
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
void InsertTupleValue(vtkIdType tupleIdx, const ValueType *tuple)
vtkIdType InsertNextTupleValue(const ValueType *tuple)
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
void * WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override
Get the address of a particular data index.
void SetArray(ValueType *array, vtkIdType size, int save, int deleteMethod)
This method lets the user specify data to be held by the array.
void SetTupleValue(vtkIdType tupleIdx, const ValueType *tuple)
void * GetVoidPointer(vtkIdType valueIdx) override
Return a void pointer.
ValueType * GetPointer(vtkIdType valueIdx)
Get the address of a particular data index.
static vtkAOSDataArrayTemplate * New()
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
~vtkAOSDataArrayTemplate() override
void ShallowCopy(vtkDataArray *other) override
Create a shallow copy of other into this, if possible.
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Get component comp of the tuple at tupleIdx.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
ValueType * Iterator
Legacy support for array-of-structs value iteration.
vtkAOSDataArrayTemplate< ValueTypeT > SelfType
void GetTupleValue(vtkIdType tupleIdx, ValueType *tuple)
Abstract superclass for all arrays.
Abstract superclass to iterate over elements in an vtkAbstractArray.
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition: vtkBuffer.h:33
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
Base interface for all typed vtkDataArray subclasses.
void DataChanged() override
Tell the array explicitly that the data has changed.
vtkTemplateTypeMacro(SelfType, vtkDataArray) enum
Compile time access to the VTK type identifier.
void * GetVoidPointer(vtkIdType valueIdx) override
Default implementation raises a runtime error.
list of point or cell ids
Definition: vtkIdList.h:37
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
@ value
Definition: vtkX3D.h:220
@ size
Definition: vtkX3D.h:253
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:32
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition: vtkType.h:345
int vtkIdType
Definition: vtkType.h:287
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition: vtkType.h:325
vtkArrayDownCast_TemplateFastCastMacro(vtkTypedDataArray) template< class Scalar > inline typename vtkTypedDataArray< Scalar >
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
#define VTK_NEWINSTANCE