1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkLongArray.h,v $
6 Date: $Date: 2002/11/12 18:32:04 $
7 Version: $Revision: 1.37 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkLongArray - dynamic, self-adjusting long integer array
19 // .SECTION Description
20 // vtkLongArray is an array of long integer numbers. It provides methods
21 // for insertion and retrieval of integer values, and will
22 // automatically resize itself to hold new data.
24 #ifndef __vtkLongArray_h
25 #define __vtkLongArray_h
27 #include "vtkDataArray.h"
29 class VTK_COMMON_EXPORT vtkLongArray : public vtkDataArray
32 static vtkLongArray *New();
34 vtkTypeRevisionMacro(vtkLongArray,vtkDataArray);
35 void PrintSelf(ostream& os, vtkIndent indent);
38 // Allocate memory for this array. Delete old storage only if necessary.
39 // Note that ext is no longer used.
40 int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
43 // Release storage and reset array to initial state.
47 // Resize object to just fit data requirement. Reclaims extra memory.
48 void Squeeze() {this->ResizeAndExtend (this->MaxId+1);};
51 // Resize the array while conserving the data.
52 virtual void Resize(vtkIdType numTuples);
56 int GetDataType() {return VTK_LONG;};
59 // Return the size of the data type.
60 int GetDataTypeSize() { return sizeof(long); }
63 // Set the number of n-tuples in the array.
64 void SetNumberOfTuples(const vtkIdType number);
67 // Get a pointer to a tuple at the ith location. This is a dangerous method
68 // (it is not thread safe since a pointer is returned).
69 float *GetTuple(const vtkIdType i);
72 // Copy the tuple value into a user-provided array.
73 void GetTuple(const vtkIdType i, float * tuple);
74 void GetTuple(const vtkIdType i, double * tuple);
77 // Set the tuple value at the ith location in the array.
78 void SetTuple(const vtkIdType i, const float * tuple);
79 void SetTuple(const vtkIdType i, const double * tuple);
82 // Insert (memory allocation performed) the tuple into the ith location
84 void InsertTuple(const vtkIdType i, const float * tuple);
85 void InsertTuple(const vtkIdType i, const double * tuple);
88 // Insert (memory allocation performed) the tuple onto the end of the array.
89 vtkIdType InsertNextTuple(const float * tuple);
90 vtkIdType InsertNextTuple(const double * tuple);
93 // Get the data at a particular index.
94 long GetValue(const vtkIdType id) {return this->Array[id];};
97 // Specify the number of values for this object to hold. Does an
98 // allocation as well as setting the MaxId ivar. Used in conjunction with
99 // SetValue() method for fast insertion.
100 void SetNumberOfValues(const vtkIdType number);
103 // Set the data at a particular index. Does not do range checking. Make sure
104 // you use the method SetNumberOfValues() before inserting data.
105 void SetValue(const vtkIdType id, const long value)
106 { this->Array[id] = value;};
109 // Insert data at a specified position in the array.
110 void InsertValue(const vtkIdType id, const long i);
113 // Insert data at the end of the array. Return its location in the array.
114 vtkIdType InsertNextValue(const long);
117 // Return the data component at the ith tuple and jth component location.
118 // Note that i is less then NumberOfTuples and j is less then
119 // NumberOfComponents.
120 float GetComponent(const vtkIdType i, const int j);
123 // Set the data component at the ith tuple and jth component location.
124 // Note that i is less then NumberOfTuples and j is less then
125 // NumberOfComponents. Make sure enough memory has been allocated
126 // (use SetNumberOfTuples() and SetNumberOfComponents()).
127 void SetComponent(const vtkIdType i, const int j, float c);
130 // Insert the data component at ith tuple and jth component location.
131 // Note that memory allocation is performed as necessary to hold the data.
132 virtual void InsertComponent(const vtkIdType i, const int j, float c);
135 // Get the address of a particular data index. Performs no checks
136 // to verify that the memory has been allocated etc.
137 long *GetPointer(const vtkIdType id) {return this->Array + id;}
138 void *GetVoidPointer(const vtkIdType id)
139 {return (void *)this->GetPointer(id);};
142 // Get the address of a particular data index. Make sure data is allocated
143 // for the number of items requested. Set MaxId according to the number of
144 // data values requested.
145 long *WritePointer(const vtkIdType id, const vtkIdType number);
148 // Deep copy of another long array.
149 void DeepCopy(vtkDataArray *da);
152 // This method lets the user specify data to be held by the array. The
153 // array argument is a pointer to the data. size is the size of
154 // the array supplied by the user. Set save to 1 to keep the class
155 // from deleting the array when it cleans up or reallocates memory.
156 // The class uses the actual array provided; it does not copy the data
157 // from the suppled array.
158 void SetArray(long* array, vtkIdType size, int save);
159 void SetVoidArray(void *array, vtkIdType size, int save)
160 {this->SetArray((long*)array, size, save);};
163 vtkLongArray(vtkIdType numComp=1);
166 long *Array; // pointer to data
167 long *ResizeAndExtend(const vtkIdType sz); // function to resize data
169 int TupleSize; //used for data conversion
174 vtkLongArray(const vtkLongArray&); // Not implemented.
175 void operator=(const vtkLongArray&); // Not implemented.
178 inline void vtkLongArray::SetNumberOfValues(const vtkIdType number)
180 this->Allocate(number);
181 this->MaxId = number - 1;
184 inline long *vtkLongArray::WritePointer(const vtkIdType id,
185 const vtkIdType number)
187 vtkIdType newSize=id+number;
188 if ( newSize > this->Size )
190 this->ResizeAndExtend(newSize);
192 if ( (--newSize) > this->MaxId )
194 this->MaxId = newSize;
196 return this->Array + id;
199 inline void vtkLongArray::InsertValue(const vtkIdType id, const long i)
201 if ( id >= this->Size )
203 this->ResizeAndExtend(id+1);
206 if ( id > this->MaxId )
212 inline vtkIdType vtkLongArray::InsertNextValue(const long i)
214 this->InsertValue (++this->MaxId,i);