Exiv2
enforce.hpp
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 #include <string>
22 
23 #include "error.hpp"
24 
25 namespace Exiv2::Internal {
36 template <typename exception_t, typename T>
37 inline void enforce(bool condition, const T& arg1) {
38  if (!condition) {
39  throw exception_t(arg1);
40  }
41 }
42 
47 inline void enforce(bool condition, Exiv2::ErrorCode err_code) {
48  if (!condition) {
49  throw Exiv2::Error(err_code);
50  }
51 }
52 
57 template <typename T>
58 inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1) {
59  if (!condition) {
60  throw Exiv2::Error(err_code, arg1);
61  }
62 }
63 
68 template <typename T, typename U>
69 inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1, const U& arg2) {
70  if (!condition) {
71  throw Exiv2::Error(err_code, arg1, arg2);
72  }
73 }
74 
79 template <typename T, typename U, typename V>
80 inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1, const U& arg2, const V& arg3) {
81  if (!condition) {
82  throw Exiv2::Error(err_code, arg1, arg2, arg3);
83  }
84 }
85 } // namespace Exiv2::Internal
Simple error class used for exceptions. An output operator is provided to print errors to a stream...
Definition: error.hpp:235
void enforce(bool condition, const T &arg1)
Ensure that condition is true, otherwise throw an exception of the type exception_t.
Definition: enforce.hpp:37
Helper structure for the Matroska tags lookup table.
Definition: matroskavideo.hpp:39
Error class for exceptions, log message class.
ErrorCode
Complete list of all Exiv2 error codes.
Definition: error.hpp:162