File indexing completed on 2024-10-13 06:32:56

0001 /*
0002     SPDX-FileCopyrightText: 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 /** \file util.h
0008  *  \brief Internal file
0009  */
0010 
0011 #ifndef STEPCORE_UTIL_H
0012 #define STEPCORE_UTIL_H
0013 
0014 namespace StepCore {
0015 
0016 template<typename T> inline T square(T v) { return v*v; }
0017 
0018 /*
0019 template<class _Class, class _BaseIterator>
0020 class ClassFilterIterator
0021 {
0022 public:
0023     ClassFilterIterator(const _BaseIterator& it): _it(it);
0024 protected:
0025     _BaseIterator _it;
0026 };
0027 */
0028 
0029 } // namespace StepCore
0030 
0031 #ifdef __GNUC__
0032 #define STEPCORE_UNUSED __attribute__((unused))
0033 #else
0034 #define STEPCORE_UNUSED
0035 #endif
0036 
0037 #define STEPCORE_STRINGIFY(x) _STEPCORE_STRINGIFY(x)
0038 #define _STEPCORE_STRINGIFY(x) #x
0039 
0040 #ifdef NDEBUG
0041 #define STEPCORE_ASSERT_NOABORT(expr)
0042 #else // NDEBUG
0043 
0044 #ifdef _MSC_VER
0045 #define __PRETTY_FUNCTION__ __FUNCSIG__
0046 #endif
0047 
0048 #define STEPCORE_ASSERT_NOABORT(expr) \
0049     if( ! (expr) ) \
0050         StepCore::_step_assert_noabort_helper<int> \
0051             ( STEPCORE_STRINGIFY(expr), __LINE__, \
0052               __FILE__, __PRETTY_FUNCTION__ )
0053 
0054 namespace StepCore {
0055 template<typename unused>
0056 void _step_assert_noabort_helper( const char *expr, int line,
0057                                    const char *file, const char *function )
0058 {
0059 #ifdef STEPCORE_WITH_QT
0060     qCritical("*** StepCore: failed assertion on line %d of file %s\n"
0061                       "*** asserted expression: %s\n"
0062                       "*** in function: %s\n",
0063                       line, file, expr, function);
0064 #else
0065     fprintf(stderr, "*** StepCore: failed assertion on line %d of file %s\n"
0066                       "*** asserted expression: %s\n"
0067                       "*** in function: %s\n",
0068                       line, file, expr, function);
0069 #endif
0070 }
0071 } // namespace StepCore
0072 
0073 #endif // ! NDEBUG
0074 
0075 #endif
0076