Chemical Data Processing Library C++ API - Version 1.1.1
CDPL
Math
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
32
#ifndef CDPL_MATH_CHECK
33
# ifdef CDPL_MATH_CHECKS_DISABLE
34
# define CDPL_MATH_CHECK(expr, msg, e)
35
# else // !CDPL_MATH_CHECKS_DISABLE
36
# define CDPL_MATH_CHECK(expr, msg, e) \
37
if (!(expr)) { \
38
throw e(msg); \
39
}
40
# endif // CDPL_MATH_CHECKS_DISABLE
41
#endif // !CDPL_MATH_CHECK
42
43
44
namespace
45
{
46
47
template
<
typename
E,
typename
T>
48
T
checkSizeEquality(
const
T
& size1,
const
T
& size2)
49
{
50
CDPL_MATH_CHECK
(size1 == size2,
"Size mismatch"
,
E
);
51
return
std::min(size1, size2);
52
}
53
54
template
<
typename
E,
typename
T>
55
T
checkMaxSize(
const
T
& size,
const
T
& max_size)
56
{
57
CDPL_MATH_CHECK
(size <= max_size,
"Max. size exceeded"
,
E
);
58
return
std::min(size, max_size);
59
}
60
}
// namespace
61
62
#define CDPL_MATH_CHECK_SIZE_EQUALITY(size1, size2, e) checkSizeEquality<e>(size1, size2)
63
64
#define CDPL_MATH_CHECK_MAX_SIZE(size, max_size, e) checkMaxSize<e>(size, max_size)
65
66
#endif // CDPL_MATH_CHECK_HPP
CDPL::Chem::CIPDescriptor::E
const unsigned int E
Specifies that the stereocenter has E configuration.
Definition:
CIPDescriptor.hpp:96
CDPL_MATH_CHECK
#define CDPL_MATH_CHECK(expr, msg, e)
Definition:
Check.hpp:36
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition:
AtomType.hpp:67
Generated by
1.8.20