Chemical Data Processing Library C++ API - Version 1.4.0
Check.hpp
Go to the documentation of this file.
1 /*
2  * Check.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_CHECK_HPP
28 #define CDPL_MATH_CHECK_HPP
29 
30 #include <algorithm>
31 
43 #ifndef CDPL_MATH_CHECK
44 # ifdef CDPL_MATH_CHECKS_DISABLE
45 # define CDPL_MATH_CHECK(expr, msg, e)
46 # else // !CDPL_MATH_CHECKS_DISABLE
47 # define CDPL_MATH_CHECK(expr, msg, e) \
48  if (!(expr)) { \
49  throw e(msg); \
50  }
51 # endif // CDPL_MATH_CHECKS_DISABLE
52 #endif // !CDPL_MATH_CHECK
53 
54 
55 namespace
56 {
57 
58  template <typename E, typename T>
59  T checkSizeEquality(const T& size1, const T& size2)
60  {
61  CDPL_MATH_CHECK(size1 == size2, "Size mismatch", E);
62  return std::min(size1, size2);
63  }
64 
65  template <typename E, typename T>
66  T checkMaxSize(const T& size, const T& max_size)
67  {
68  CDPL_MATH_CHECK(size <= max_size, "Max. size exceeded", E);
69  return std::min(size, max_size);
70  }
71 } // namespace
72 
84 #define CDPL_MATH_CHECK_SIZE_EQUALITY(size1, size2, e) checkSizeEquality<e>(size1, size2)
85 
96 #define CDPL_MATH_CHECK_MAX_SIZE(size, max_size, e) checkMaxSize<e>(size, max_size)
97 
98 #endif // CDPL_MATH_CHECK_HPP
#define CDPL_MATH_CHECK(expr, msg, e)
Throws the exception e with message msg when the boolean expression expr evaluates to false.
Definition: Check.hpp:47
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
constexpr unsigned int E
Specifies that the stereocenter has E configuration.
Definition: CIPDescriptor.hpp:96