File: vtkAssume.h

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (59 lines) | stat: -rw-r--r-- 2,360 bytes parent folder | download
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkAssume.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.

=========================================================================*/
// .NAME VTK_ASSUME - Provide compiler hints for non-obvious conditions.

#ifndef vtkAssume_h
#define vtkAssume_h

#include "vtkConfigure.h"

#include <cassert>

// Description:
// VTK_ASSUME instructs the compiler that a certain non-obvious condition will
// *always* be true. Beware that if cond is false at runtime, the results are
// unpredictable (and likely catastrophic). A runtime assertion is added so
// that debugging builds may easily catch violations of the condition.
//
// A useful application of this macro is when a vtkGenericDataArray subclass has
// a known number of components at compile time. Adding, for example,
// VTK_ASSUME(array->GetNumberOfComponents() == 3); allows the compiler to
// provide faster access through the GetTypedComponent method, as the fixed data
// stride in AOS arrays allows advanced optimization of the accesses.
//
// A more detailed description of this class and related tools can be found
// \ref VTK-7-1-ArrayDispatch "here".
#define VTK_ASSUME(cond) \
  do { \
  const bool c = cond; \
  assert("Bad assumption in VTK_ASSUME: " #cond && c); \
  VTK_ASSUME_IMPL(c); \
  (void)c; /* Prevents unused var warnings */ \
  } while (false) /* do-while prevents extra semicolon warnings */

// VTK_ASSUME_IMPL is compiler-specific:
#if defined(VTK_COMPILER_MSVC) || defined(VTK_COMPILER_ICC)
# define VTK_ASSUME_IMPL(cond) __assume(cond)
#elif defined(VTK_COMPILER_GCC) && VTK_COMPILER_GCC_VERSION >= 40500
// Added in 4.5.0:
# define VTK_ASSUME_IMPL(cond) if (!(cond)) __builtin_unreachable()
#elif defined(VTK_COMPILER_CLANG)
# define VTK_ASSUME_IMPL(cond) if (!(cond)) __builtin_unreachable()
#else
# define VTK_ASSUME_IMPL(cond) do {} while (false) /* no-op */
#endif

#endif // vtkAssume_h
// VTK-HeaderTest-Exclude: vtkAssume.h