/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 | | #include <string> |
27 | | |
28 | | namespace Exiv2::Internal { |
29 | | /*! |
30 | | * @brief Ensure that condition is true, otherwise throw an exception of the |
31 | | * type exception_t |
32 | | * |
33 | | * @tparam exception_t Exception type that is thrown, must provide a |
34 | | * constructor that accepts a single argument to which args are forwarded. |
35 | | */ |
36 | | template <typename exception_t, typename... T> |
37 | 54.8M | constexpr void enforce(bool condition, T&&... args) { |
38 | 54.8M | if (!condition) { |
39 | 12.6k | throw exception_t(std::forward<T>(args)...); |
40 | 12.6k | } |
41 | 54.8M | } void Exiv2::Internal::enforce<Exiv2::Error, Exiv2::ErrorCode&>(bool, Exiv2::ErrorCode&) Line | Count | Source | 37 | 54.6M | constexpr void enforce(bool condition, T&&... args) { | 38 | 54.6M | if (!condition) { | 39 | 12.6k | throw exception_t(std::forward<T>(args)...); | 40 | 12.6k | } | 41 | 54.6M | } |
void Exiv2::Internal::enforce<std::out_of_range, char const (&) [47]>(bool, char const (&) [47]) Line | Count | Source | 37 | 3.67k | constexpr void enforce(bool condition, T&&... args) { | 38 | 3.67k | if (!condition) { | 39 | 1 | throw exception_t(std::forward<T>(args)...); | 40 | 1 | } | 41 | 3.67k | } |
void Exiv2::Internal::enforce<std::invalid_argument, char const (&) [59]>(bool, char const (&) [59]) Line | Count | Source | 37 | 86.5k | constexpr void enforce(bool condition, T&&... args) { | 38 | 86.5k | if (!condition) { | 39 | 0 | throw exception_t(std::forward<T>(args)...); | 40 | 0 | } | 41 | 86.5k | } |
void Exiv2::Internal::enforce<std::out_of_range, char const (&) [31]>(bool, char const (&) [31]) Line | Count | Source | 37 | 86.5k | constexpr void enforce(bool condition, T&&... args) { | 38 | 86.5k | if (!condition) { | 39 | 0 | throw exception_t(std::forward<T>(args)...); | 40 | 0 | } | 41 | 86.5k | } |
void Exiv2::Internal::enforce<std::overflow_error, char const (&) [22]>(bool, char const (&) [22]) Line | Count | Source | 37 | 338 | constexpr void enforce(bool condition, T&&... args) { | 38 | 338 | if (!condition) { | 39 | 0 | throw exception_t(std::forward<T>(args)...); | 40 | 0 | } | 41 | 338 | } |
|
42 | | |
43 | | /*! |
44 | | * @brief Ensure that condition is true, otherwise throw an Exiv2::Error with |
45 | | * the given error_code & arguments. |
46 | | */ |
47 | | template <typename... T> |
48 | 54.6M | constexpr void enforce(bool condition, Exiv2::ErrorCode err_code, T&&... args) { |
49 | 54.6M | enforce<Exiv2::Error>(condition, err_code, std::forward<T>(args)...); |
50 | 54.6M | } |
51 | | } // namespace Exiv2::Internal |
52 | | #endif // EXIV2_ENFORCE_HPP |