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 
35 template <typename exception_t, typename T>
36 inline void enforce(bool condition, const T& arg1)
37 {
38  if (!condition) {
39  throw exception_t(arg1);
40  }
41 }
42 
47 inline void enforce(bool condition, Exiv2::ErrorCode err_code)
48 {
49  if (!condition) {
50  throw Exiv2::Error(err_code);
51  }
52 }
53 
58 template <typename T>
59 inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1)
60 {
61  if (!condition) {
62  throw Exiv2::Error(err_code, arg1);
63  }
64 }
65 
70 template <typename T, typename U>
71 inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1, const U& arg2)
72 {
73  if (!condition) {
74  throw Exiv2::Error(err_code, arg1, arg2);
75  }
76 }
77 
82 template <typename T, typename U, typename V>
83 inline void enforce(bool condition, Exiv2::ErrorCode err_code, const T& arg1, const U& arg2, const V& arg3)
84 {
85  if (!condition) {
86  throw Exiv2::Error(err_code, arg1, arg2, arg3);
87  }
88 }
Error class for exceptions, log message class.
ErrorCode
Complete list of all Exiv2 error codes.
Definition: error.hpp:191
BasicError< char > Error
Error class used for exceptions (std::string based)
Definition: error.hpp:324