/usr/include/vtk-7.1/vtkTuple.h is in libvtk7-dev 7.1.1+dfsg1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | /*=========================================================================
Program: Visualization Toolkit
Module: vtkTuple.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkTuple
* @brief templated base type for containers of constant size.
*
*
* This class is a templated data type for storing and manipulating tuples.
*/
#ifndef vtkTuple_h
#define vtkTuple_h
#include "vtkIOStream.h" // For streaming operators
#include "vtkSystemIncludes.h"
#include <cassert> // For inline assert for bounds checked methods.
#include <cstdlib> // for std::abs() with int overloads
#include <cmath> // for std::abs() with float overloads
template<typename T, int Size>
class vtkTuple
{
public:
/**
* The default constructor does not initialize values. If initializtion is
* desired, this should be done explicitly using the constructors for scalar
* initialization, or other suitable constructors taking arguments.
*/
vtkTuple()
{
}
/**
* Initialize all of the tuple's elements with the supplied scalar.
*/
explicit vtkTuple(const T& scalar)
{
for (int i = 0; i < Size; ++i)
{
this->Data[i] = scalar;
}
}
/**
* Initalize the tuple's elements with the elements of the supplied array.
* Note that the supplied pointer must contain at least as many elements as
* the tuple, or it will result in access to out of bounds memory.
*/
explicit vtkTuple(const T* init)
{
for (int i = 0; i < Size; ++i)
{
this->Data[i] = init[i];
}
}
/**
* Get the size of the tuple.
*/
int GetSize() const { return Size; }
/**
* Get a pointer to the underlying data of the tuple.
*/
T* GetData() { return this->Data; }
const T* GetData() const { return this->Data; }
/**
* Get a reference to the underlying data element of the tuple.
* This works similarly to the way C++ STL containers work. No
* bounds checking is performed.
*/
T& operator[](int i) { return this->Data[i]; }
const T& operator[](int i) const { return this->Data[i]; }
//@{
/**
* Get the value of the tuple at the index specifed. Does bounds
* checking, similar to the at(i) method of C++ STL containers, but
* only when the code is compiled in debug mode.
*/
T operator()(int i) const
{
assert("pre: index_in_bounds" && i >= 0 && i < Size);
return this->Data[i];
}
//@}
//@{
/**
* Equality operator with a tolerance to allow fuzzy comparisons.
*/
bool Compare(const vtkTuple<T, Size>& other, const T& tol) const
{
if (Size != other.GetSize())
{
return false;
}
for (int i = 0; i < Size; ++i)
{
if (std::abs(this->Data[i] - other.Data[i]) >= tol)
{
return false;
}
}
return true;
}
//@}
//@{
/**
* Cast the tuple to the specified type, returning the result.
*/
template<typename TR>
vtkTuple<TR, Size> Cast() const
{
vtkTuple<TR, Size> result;
for (int i = 0; i < Size; ++i)
{
result[i] = static_cast<TR>(this->Data[i]);
}
return result;
}
//@}
protected:
//@{
/**
* The only thing stored in memory!
*/
T Data[Size];
};
//@}
//@{
/**
* Output the contents of a tuple, mainly useful for debugging.
*/
template<typename A, int Size>
ostream& operator<<(ostream& out, const vtkTuple<A, Size>& t)
{
out << "(";
bool first = true;
for (int i = 0; i < Size; ++i)
{
if (first)
{
first = false;
}
else
{
out << ", ";
}
out << t[i];
}
out << ")";
return out;
}
// Specialize for unsigned char so that we can see the numbers!
template<int Size>
ostream& operator<<(ostream& out, const vtkTuple<unsigned char, Size>& t)
{
out << "(";
bool first = true;
for (int i = 0; i < Size; ++i)
{
if (first)
{
first = false;
}
else
{
out << ", ";
}
out << static_cast<int>(t[i]);
}
out << ")";
return out;
}
//@}
//@{
/**
* Equality operator performs an equality check on each component.
*/
template<typename A, int Size>
bool operator==(const vtkTuple<A, Size>& t1, const vtkTuple<A, Size>& t2)
{
for (int i = 0; i < Size; ++i)
{
if (t1[i] != t2[i])
{
return false;
}
}
return true;
}
//@}
/**
* Inequality for vector type.
*/
template<typename A, int Size>
bool operator!=(const vtkTuple<A, Size>& t1, const vtkTuple<A, Size>& t2)
{
return !(t1 == t2);
}
#endif // vtkTuple_h
// VTK-HeaderTest-Exclude: vtkTuple.h
|