File: boundschecking.hh

package info (click to toggle)
dune-common 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,048 kB
  • sloc: cpp: 54,403; python: 4,136; sh: 1,657; makefile: 17
file content (43 lines) | stat: -rw-r--r-- 1,094 bytes parent folder | download | duplicates (2)
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
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_BOUNDSCHECKING_HH
#define DUNE_BOUNDSCHECKING_HH

#include <dune/common/exceptions.hh>

/**
 * \file
 * \brief Macro for wrapping boundary checks
 */

/**
 * @addtogroup Common
 *
 * @{
 */

#ifndef DUNE_ASSERT_BOUNDS
#if defined(DUNE_CHECK_BOUNDS) || defined(DOXYGEN)

/**
 * \brief If `DUNE_CHECK_BOUNDS` is defined: check if condition
 * \a cond holds; otherwise, do nothing.
 *
 * Meant to be used for conditions that assure writes and reads
 * do not occur outside of memory limits or pre-defined patterns
 * and related conditions.
 */
#define DUNE_ASSERT_BOUNDS(cond)                            \
  do {                                                      \
    if (!(cond))                                            \
      DUNE_THROW(Dune::RangeError, "Index out of bounds."); \
  } while (false)

#else
#define DUNE_ASSERT_BOUNDS(cond)
#endif
#endif

/** @} */

#endif // DUNE_BOUNDSCHECKING_HH