File indexing completed on 2024-12-08 11:06:11

0001 // clang-format off
0002 /*
0003  * KDiff3 - Text Diff And Merge Tool
0004  *
0005  * SPDX-FileCopyrightText: 2018-2020 Michael Reeves reeves.87@gmail.com
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 // clang-format on
0009 #ifndef TYPEUTILS_H
0010 #define TYPEUTILS_H
0011 
0012 #include <QtGlobal>
0013 
0014 #include <stdlib.h>
0015 #include <type_traits>
0016 #include <limits>
0017 
0018 #include <boost/safe_numerics/automatic.hpp>
0019 #include <boost/safe_numerics/safe_integer.hpp>
0020 #include <boost/safe_numerics/safe_integer_range.hpp>
0021 
0022 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
0023 using QtSizeType = qint32;
0024 #else
0025 using QtSizeType = qsizetype;
0026 #endif
0027 using FileOffset = quint64;
0028 using PtrDiffRef = size_t;
0029 
0030 template <typename T>
0031 using limits = std::numeric_limits<T>;
0032 
0033 using KDiff3_exception_policy = boost::safe_numerics::exception_policy<
0034     boost::safe_numerics::throw_exception, // arithmetic error
0035     boost::safe_numerics::trap_exception,  // implementation defined behavior
0036     boost::safe_numerics::trap_exception,  // undefined behavior
0037     boost::safe_numerics::trap_exception   // uninitialized value
0038 >;
0039 
0040 template <typename T, T MIN = limits<T>::min(), T MAX = limits<T>::max()>
0041 using SafeSignedRange =
0042     boost::safe_numerics::safe_signed_range<MIN, MAX>;
0043 
0044 template <typename T>
0045 using SafeInt = boost::safe_numerics::safe<T, boost::safe_numerics::automatic, KDiff3_exception_policy>;
0046 
0047 constexpr static qint32 maxNofRecentFiles = 10;
0048 constexpr static qint32 maxNofRecentCodecs = 5;
0049 
0050 static_assert(sizeof(FileOffset) >= sizeof(QtSizeType), "Size mis-match this configuration is not supported."); //Assumed in SourceData.
0051 
0052 #endif