/usr/include/vtk-6.3/vtkVariantInlineOperators.h is in libvtk6-dev 6.3.0+dfsg1-5.
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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | #include <climits>
// ----------------------------------------------------------------------
// First we have several helper functions that will determine what
// type we're actually dealing with. With any luck the compiler will
// inline these so they have very little overhead.
inline bool
IsSigned64Bit(int VariantType)
{
#if defined(VTK_TYPE_USE_LONG_LONG) && defined(VTK_TYPE_USE___INT64)
return ((VariantType == VTK_LONG_LONG) ||
(VariantType == VTK___INT64) ||
(VariantType == VTK_TYPE_INT64));
#elif defined(VTK_TYPE_USE_LONG_LONG)
return ((VariantType == VTK_LONG_LONG) ||
(VariantType == VTK_TYPE_INT64));
#elif defined(VTK_TYPE_USE___INT64)
return ((VariantType == VTK___INT64) ||
(VariantType == VTK_TYPE_INT64));
#else
return (VariantType == VTK_TYPE_INT64);
#endif
}
inline bool
IsSigned(int VariantType)
{
#if (CHAR_MIN == SCHAR_MIN && CHAR_MAX == SCHAR_MAX)
// the char type is signed on this compiler
return ((VariantType == VTK_CHAR) ||
(VariantType == VTK_SIGNED_CHAR) ||
(VariantType == VTK_SHORT) ||
(VariantType == VTK_INT) ||
(VariantType == VTK_LONG) ||
(VariantType == VTK_ID_TYPE) ||
IsSigned64Bit(VariantType));
#else
// char is unsigned
return ((VariantType == VTK_SIGNED_CHAR) ||
(VariantType == VTK_SHORT) ||
(VariantType == VTK_INT) ||
(VariantType == VTK_LONG) ||
(VariantType == VTK_ID_TYPE) ||
IsSigned64Bit(VariantType));
#endif
}
// ----------------------------------------------------------------------
inline bool
IsFloatingPoint(int VariantType)
{
return ((VariantType == VTK_FLOAT) ||
(VariantType == VTK_DOUBLE));
}
// ----------------------------------------------------------------------
inline bool
CompareSignedUnsignedEqual(const vtkVariant &SignedVariant,
const vtkVariant &UnsignedVariant)
{
// If the signed value is less than zero then they cannot possibly
// be equal.
vtkTypeInt64 A = SignedVariant.ToTypeInt64();
return (A >= 0) && (A == UnsignedVariant.ToTypeInt64());
}
// ----------------------------------------------------------------------
inline bool
CompareSignedUnsignedLessThan(const vtkVariant &SignedVariant,
const vtkVariant &UnsignedVariant)
{
vtkTypeInt64 A = SignedVariant.ToTypeInt64();
return ((A < 0) ||
(static_cast<vtkTypeUInt64>(A) < UnsignedVariant.ToTypeUInt64()));
}
// ----------------------------------------------------------------------
inline bool
CompareUnsignedSignedLessThan(const vtkVariant &UnsignedVariant,
const vtkVariant &SignedVariant)
{
vtkTypeInt64 B = SignedVariant.ToTypeInt64();
return ((B > 0) &&
(UnsignedVariant.ToTypeUInt64() < static_cast<vtkTypeUInt64>(B)));
}
// ----------------------------------------------------------------------
inline bool
CompareSignedLessThan(const vtkVariant &A,
const vtkVariant &B)
{
return (A.ToTypeInt64() < B.ToTypeInt64());
}
// ----------------------------------------------------------------------
inline bool
CompareUnsignedLessThan(const vtkVariant &A,
const vtkVariant &B)
{
return (A.ToTypeUInt64() < B.ToTypeUInt64());
}
// ----------------------------------------------------------------------
inline bool
vtkVariant::operator==(const vtkVariant &other) const
{
// First test: NULL values are always equal to one another and
// unequal to anything else.
if (! (this->Valid && other.Valid))
{
return (!(this->Valid || other.Valid));
}
// Second test: VTK objects can only be compared with other VTK
// objects.
if ((this->Type == VTK_OBJECT) || (other.Type == VTK_OBJECT))
{
return ((this->Type == VTK_OBJECT) &&
(other.Type == VTK_OBJECT) &&
(this->Data.VTKObject == other.Data.VTKObject));
}
// Third test: the STRING type dominates all else. If either item
// is a string then they must both be compared as strings.
if ((this->Type == VTK_STRING) ||
(other.Type == VTK_STRING))
{
return (this->ToString() == other.ToString());
}
// Fourth test: the Unicode STRING type dominates all else. If either item
// is a unicode string then they must both be compared as strings.
if ((this->Type == VTK_UNICODE_STRING) ||
(other.Type == VTK_UNICODE_STRING))
{
return (this->ToUnicodeString() == other.ToUnicodeString());
}
// Fifth: floating point dominates integer types.
// Demote to the lowest-floating-point precision for the comparison.
// This effectively makes the lower-precision number an interval
// corresponding to the range of double values that get rounded to
// that float. Otherwise, comparisons of numbers that cannot fit in
// the smaller mantissa exactly will never be equal to their
// corresponding higher-precision representations.
if (this->Type == VTK_FLOAT || other.Type == VTK_FLOAT)
{
return this->ToFloat() == other.ToFloat();
}
else if (this->Type == VTK_DOUBLE || other.Type == VTK_DOUBLE)
{
return (this->ToDouble() == other.ToDouble());
}
// Sixth: we must be comparing integers.
// 6A: catch signed/unsigned comparison. If the signed object is
// less than zero then they cannot be equal.
bool thisSigned = IsSigned(this->Type);
bool otherSigned = IsSigned(other.Type);
if (thisSigned ^ otherSigned)
{
if (thisSigned)
{
return CompareSignedUnsignedEqual(*this, other);
}
else
{
return CompareSignedUnsignedEqual(other, *this);
}
}
else // 6B: both are signed or both are unsigned. In either event
// all we have to do is check whether the bit patterns are
// equal.
{
return (this->ToTypeInt64() == other.ToTypeInt64());
}
}
// ----------------------------------------------------------------------
inline bool
vtkVariant::operator<(const vtkVariant &other) const
{
// First test: a NULL value is less than anything except another
// NULL value. unequal to anything else.
if (! (this->Valid && other.Valid))
{
return ((!this->Valid) && (other.Valid));
}
// Second test: VTK objects can only be compared with other VTK
// objects.
if ((this->Type == VTK_OBJECT) || (other.Type == VTK_OBJECT))
{
return ((this->Type == VTK_OBJECT) &&
(other.Type == VTK_OBJECT) &&
(this->Data.VTKObject < other.Data.VTKObject));
}
// Third test: the STRING type dominates all else. If either item
// is a string then they must both be compared as strings.
if ((this->Type == VTK_STRING) ||
(other.Type == VTK_STRING))
{
return (this->ToString() < other.ToString());
}
// Fourth test: the Unicode STRING type dominates all else. If either item
// is a unicode string then they must both be compared as strings.
if ((this->Type == VTK_UNICODE_STRING) ||
(other.Type == VTK_UNICODE_STRING))
{
return (this->ToUnicodeString() < other.ToUnicodeString());
}
// Fourth: floating point dominates integer types.
// Demote to the lowest-floating-point precision for the comparison.
// This effectively makes the lower-precision number an interval
// corresponding to the range of double values that get rounded to
// that float. Otherwise, comparisons of numbers that cannot fit in
// the smaller mantissa exactly will never be equal to their
// corresponding higher-precision representations.
if (this->Type == VTK_FLOAT || other.Type == VTK_FLOAT)
{
return this->ToFloat() < other.ToFloat();
}
else if (this->Type == VTK_DOUBLE || other.Type == VTK_DOUBLE)
{
return (this->ToDouble() < other.ToDouble());
}
// Fifth: we must be comparing integers.
// 5A: catch signed/unsigned comparison. If the signed object is
// less than zero then they cannot be equal.
bool thisSigned = IsSigned(this->Type);
bool otherSigned = IsSigned(other.Type);
if (thisSigned ^ otherSigned)
{
if (thisSigned)
{
return CompareSignedUnsignedLessThan(*this, other);
}
else
{
return CompareUnsignedSignedLessThan(*this, other);
}
}
else if (thisSigned)
{
return CompareSignedLessThan(*this, other);
}
else
{
return CompareUnsignedLessThan(*this, other);
}
}
// ----------------------------------------------------------------------
// Below this point are operators defined in terms of other operators.
// Again, this may sacrifice some speed, but reduces the chance of
// inconsistent behavior.
// ----------------------------------------------------------------------
inline bool
vtkVariant::operator!=(const vtkVariant &other) const
{
return ! (this->operator==(other));
}
inline bool
vtkVariant::operator>(const vtkVariant &other) const
{
return (!(this->operator==(other) ||
this->operator<(other)));
}
inline bool
vtkVariant::operator<=(const vtkVariant &other) const
{
return (this->operator==(other) ||
this->operator<(other));
}
inline bool
vtkVariant::operator>=(const vtkVariant &other) const
{
return (!this->operator<(other));
}
// VTK-HeaderTest-Exclude: vtkVariantInlineOperators.h
|