Coverage Report

Created: 2026-07-30 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/exiv2/src/enforce.hpp
Line
Count
Source
1
// ***************************************************************** -*- C++ -*-
2
/*
3
 * Copyright (C) 2004-2021 Exiv2 authors
4
 * This program is part of the Exiv2 distribution.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
19
 */
20
21
#ifndef EXIV2_ENFORCE_HPP
22
#define EXIV2_ENFORCE_HPP
23
24
#include "error.hpp"
25
26
namespace Exiv2::Internal {
27
/*!
28
 * @brief Ensure that condition is true, otherwise throw an exception of the
29
 * type exception_t
30
 *
31
 * @tparam exception_t  Exception type that is thrown, must provide a
32
 * constructor that accepts a single argument to which args are forwarded.
33
 */
34
template <typename exception_t, typename... T>
35
334k
constexpr void enforce(bool condition, T&&... args) {
36
334k
  if (!condition) {
37
2.11k
    throw exception_t(std::forward<T>(args)...);
38
2.11k
  }
39
334k
}
void Exiv2::Internal::enforce<Exiv2::Error, Exiv2::ErrorCode&>(bool, Exiv2::ErrorCode&)
Line
Count
Source
35
334k
constexpr void enforce(bool condition, T&&... args) {
36
334k
  if (!condition) {
37
2.11k
    throw exception_t(std::forward<T>(args)...);
38
2.11k
  }
39
334k
}
Unexecuted instantiation: void Exiv2::Internal::enforce<std::out_of_range, char const (&) [47]>(bool, char const (&) [47])
Unexecuted instantiation: void Exiv2::Internal::enforce<std::invalid_argument, char const (&) [59]>(bool, char const (&) [59])
Unexecuted instantiation: void Exiv2::Internal::enforce<std::out_of_range, char const (&) [31]>(bool, char const (&) [31])
Unexecuted instantiation: void Exiv2::Internal::enforce<std::overflow_error, char const (&) [22]>(bool, char const (&) [22])
40
41
/*!
42
 * @brief Ensure that condition is true, otherwise throw an Exiv2::Error with
43
 * the given error_code & arguments.
44
 */
45
template <typename... T>
46
334k
constexpr void enforce(bool condition, Exiv2::ErrorCode err_code, T&&... args) {
47
334k
  enforce<Exiv2::Error>(condition, err_code, std::forward<T>(args)...);
48
334k
}
49
}  // namespace Exiv2::Internal
50
#endif  // EXIV2_ENFORCE_HPP