assertion.hh 1.42 KB
 Thomas Moulard committed May 03, 2010 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ``````// Copyright (C) 2010 by Thomas Moulard, CNRS. // // This file is part of the hpp-util. // // This software is provided "as is" without warranty of any kind, // either expressed or implied, including but not limited to the // implied warranties of fitness for a particular purpose. // // See the COPYING file for more information. #ifndef HPP_UTIL_ASSERTION_HH # define HPP_UTIL_ASSERTION_HH # include # include # include // If debug mode is disabled and assertions are not already // disabled, disable them automatically. # if (defined HPP_DEBUG) && (!defined HPP_ENABLE_ASSERTIONS) # define HPP_ENABLE_ASSERTIONS # endif // (!defined HPP_DEBUG) && (!defined HPP_ENABLE_ASSERTIONS) namespace hpp { `````` Thomas Moulard committed May 10, 2010 26 `````` HPP_MAKE_EXCEPTION (HPP_UTIL_DLLAPI, AssertionError); `````` Thomas Moulard committed May 03, 2010 27 28 29 30 31 32 33 34 35 ``````} // end of namespace hpp. /// \brief Define HPP_ASSERT. /// /// Throw an ::hpp::AssertionError if macro argument evaluates to /// false. # ifdef HPP_ENABLE_ASSERTIONS # define HPP_ASSERT(CONDITION) \ do { \ `````` Diane Bury committed Apr 03, 2020 36 `````` bool _x = static_cast(CONDITION); \ `````` Thomas Moulard committed May 03, 2010 37 38 39 40 41 42 43 44 45 46 47 48 49 `````` if (!_x) \ HPP_THROW_EXCEPTION \ (::hpp::AssertionError, \ #CONDITION " evaluates to false"); \ } while (0) # else # define HPP_ASSERT(CONDITION) # endif // HPP_ENABLE_ASSERTIONS /// \brief Define macro for precondition checking. # define HPP_PRECONDITION(CONDITION) HPP_ASSERT (CONDITION) #endif //! HPP_UTIL_ASSERTION_HH``````