Рефакторинг 4

This commit is contained in:
Andrei Astafev 2020-04-22 20:24:13 +03:00
parent 352bf756bd
commit d6143953f6
21 changed files with 322 additions and 276 deletions

View File

@ -44,7 +44,7 @@ add_subdirectory(src/myx/base)
add_subdirectory(src/myx/filesystem)
add_subdirectory(src/myx/qt)
add_subdirectory(src/myx/math)
add_subdirectory(src/myx/redis)
# add_subdirectory(src/myx/redis)
# Примеры
if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO)

View File

@ -3,12 +3,10 @@ set(TRGT filesystem)
# cmake-format: off
# Список файлов исходных текстов
if(NOT MYXLIB_HEADER_ONLY)
set(TRGT_cpp
${CMAKE_CURRENT_SOURCE_DIR}/current_executable.cpp
${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp
${CMAKE_CURRENT_SOURCE_DIR}/paths_mt.cpp)
endif()
# Список заголовочных файлов
set(TRGT_hpp

View File

@ -1,2 +1 @@
#include <myx/filesystem/current_executable.hpp>
#include <myx/filesystem/current_executable-inl.hpp>

View File

@ -1,2 +1 @@
#include <myx/filesystem/paths.hpp>
#include <myx/filesystem/paths-inl.hpp>

View File

@ -1,2 +1 @@
#include <myx/filesystem/paths_mt.hpp>
#include <myx/filesystem/paths_mt-inl.hpp>

View File

@ -3,7 +3,7 @@ set(TRGT math)
# cmake-format: off
# Список файлов исходных текстов
set(TRGT_sources
set(TRGT_cpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative.cpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative_and_abs.cpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps.cpp
@ -14,10 +14,15 @@ set(TRGT_sources
set(TRGT_hpp
${CMAKE_CURRENT_SOURCE_DIR}/all.hpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative.hpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative-inl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative_and_abs.hpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_relative_and_abs-inl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps.hpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps-inl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps_and_abs.hpp
${CMAKE_CURRENT_SOURCE_DIR}/almost_equal_ulps_and_abs-inl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/constants.hpp
${CMAKE_CURRENT_SOURCE_DIR}/constants-inl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/float_cmp_types.hpp
${CMAKE_CURRENT_SOURCE_DIR}/functions.hpp
${CMAKE_CURRENT_SOURCE_DIR}/radar.hpp
@ -27,13 +32,14 @@ set(TRGT_headers ${TRGT_hpp})
# cmake-format: on
add_library(${TRGT}-header-only INTERFACE)
target_sources(${TRGT}-header-only INTERFACE ${TRGT_headers})
target_include_directories(
${TRGT}-header-only SYSTEM INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
if(MYXLIB_BUILD_LIBRARIES)
add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_sources} ${TRGT_headers})
add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers})
common_target_properties(${TRGT})
# Создание цели для проверки утилитой clang-tidy

View File

@ -0,0 +1,44 @@
#ifndef MYXLIB_HEADER_ONLY
#include <myx/math/almost_equal_relative.hpp>
#endif
#include <cmath>
namespace myx {
namespace math {
bool almost_equal_relative( const float a, const float b,
const float maxRelDiff )
{
float diff = fabsf( a - b );
float aN = fabsf( a );
float bN = fabsf( b );
float largest = ( bN > aN ) ? bN : aN;
if ( diff <= largest * maxRelDiff )
{
return( true );
}
return( false );
}
bool almost_equal_relative( const double a, const double b,
const double maxRelDiff )
{
double diff = fabs( a - b );
double aN = fabs( a );
double bN = fabs( b );
double largest = ( bN > aN ) ? bN : aN;
if ( diff <= largest * maxRelDiff )
{
return( true );
}
return( false );
}
} // namespace math
} // namespace myx

View File

@ -1,42 +1 @@
#include <myx/math/almost_equal_relative.hpp>
#include <cmath>
namespace myx {
namespace math {
bool almost_equal_relative( const float a, const float b,
const float maxRelDiff )
{
float diff = fabsf( a - b );
float aN = fabsf( a );
float bN = fabsf( b );
float largest = ( bN > aN ) ? bN : aN;
if ( diff <= largest * maxRelDiff )
{
return( true );
}
return( false );
}
bool almost_equal_relative( const double a, const double b,
const double maxRelDiff )
{
double diff = fabs( a - b );
double aN = fabs( a );
double bN = fabs( b );
double largest = ( bN > aN ) ? bN : aN;
if ( diff <= largest * maxRelDiff )
{
return( true );
}
return( false );
}
} // namespace math
} // namespace myx
#include <myx/math/almost_equal_relative-inl.hpp>

View File

@ -1,6 +1,8 @@
#ifndef MYX_MATH_ALMOST_EQUAL_RELATIVE_HPP_
#define MYX_MATH_ALMOST_EQUAL_RELATIVE_HPP_
#include <myx/base/config.hpp>
#include <cfloat>
// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
@ -28,4 +30,8 @@ bool almost_equal_relative( double a, double b,
} // namespace myx
#ifdef MYXLIB_HEADER_ONLY
#include "almost_equal_relative-inl.hpp"
#endif
#endif // MYX_MATH_ALMOST_EQUAL_RELATIVE_HPP_

View File

@ -0,0 +1,58 @@
#ifndef MYXLIB_HEADER_ONLY
#include <myx/math/almost_equal_relative_and_abs.hpp>
#endif
#include <cmath>
namespace myx {
namespace math {
bool almost_equal_relative_and_abs( const float a, const float b,
const float maxAbsDiff, const float maxRelDiff )
{
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
float diff = fabsf( a - b );
if ( diff <= maxAbsDiff )
{
return( true );
}
float aN = fabsf( a );
float bN = fabsf( b );
float largest = ( bN > aN ) ? bN : aN;
if ( diff <= largest * maxRelDiff )
{
return( true );
}
return( false );
}
bool almost_equal_relative_and_abs( const double a, const double b,
const double maxAbsDiff, const double maxRelDiff )
{
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
double diff = fabs( a - b );
if ( diff <= maxAbsDiff )
{
return( true );
}
double aN = fabs( a );
double bN = fabs( b );
double largest = ( bN > aN ) ? bN : aN;
if ( diff <= largest * maxRelDiff )
{
return( true );
}
return( false );
}
} // namespace math
} // namespace myx

View File

@ -1,56 +1 @@
#include <myx/math/almost_equal_relative_and_abs.hpp>
#include <cmath>
namespace myx {
namespace math {
bool almost_equal_relative_and_abs( const float a, const float b,
const float maxAbsDiff, const float maxRelDiff )
{
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
float diff = fabsf( a - b );
if ( diff <= maxAbsDiff )
{
return( true );
}
float aN = fabsf( a );
float bN = fabsf( b );
float largest = ( bN > aN ) ? bN : aN;
if ( diff <= largest * maxRelDiff )
{
return( true );
}
return( false );
}
bool almost_equal_relative_and_abs( const double a, const double b,
const double maxAbsDiff, const double maxRelDiff )
{
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
double diff = fabs( a - b );
if ( diff <= maxAbsDiff )
{
return( true );
}
double aN = fabs( a );
double bN = fabs( b );
double largest = ( bN > aN ) ? bN : aN;
if ( diff <= largest * maxRelDiff )
{
return( true );
}
return( false );
}
} // namespace math
} // namespace myx
#include <myx/math/almost_equal_relative_and_abs-inl.hpp>

View File

@ -1,6 +1,8 @@
#ifndef MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_HPP_
#define MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_HPP_
#include <myx/base/config.hpp>
#include <cfloat>
namespace myx {
@ -28,4 +30,8 @@ bool almost_equal_relative_and_abs( double a, double b,
} // namespace myx
#ifdef MYXLIB_HEADER_ONLY
#include "almost_equal_relative_and_abs-inl.hpp"
#endif
#endif // MYX_MATH_ALMOST_EQUAL_RELATIVE_AND_ABS_HPP_

View File

@ -0,0 +1,86 @@
#ifndef MYXLIB_HEADER_ONLY
#include <myx/math/almost_equal_ulps.hpp>
#endif
#include <myx/math/float_cmp_types.hpp>
#include <cmath>
namespace myx {
namespace math {
bool almost_equal_ulps( const float a, const float b,
const int maxUlpsDiff )
{
FloatCmp uA( a );
FloatCmp uB( b );
// Если знаки разные, то числа не равны.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if ( uA.negative() != uB.negative() )
{
// Кроме случая, когда +0==-0
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if ( a == b ) // -V550
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
{
return( true );
}
return( false );
}
// Разница в младших битах.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
auto ulpsDiff = std::abs( uA.i - uB.i );
if ( ulpsDiff <= maxUlpsDiff )
{
return( true );
}
return( false );
} // almost_equal_ulps
bool almost_equal_ulps( const double a, const double b,
const int maxUlpsDiff )
{
DoubleCmp uA( a );
DoubleCmp uB( b );
// Если знаки разные, то числа не равны.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if ( uA.negative() != uB.negative() )
{
// Кроме случая, когда +0==-0
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if ( a == b ) // -V550
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
{
return( true );
}
return( false );
}
// Разница в младших битах.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
auto ulpsDiff = std::abs( uA.i - uB.i );
if ( ulpsDiff <= maxUlpsDiff )
{
return( true );
}
return( false );
} // almost_equal_ulps
} // namespace math
} // namespace myx

View File

@ -1,83 +1 @@
#include <myx/math/almost_equal_ulps.hpp>
#include <myx/math/float_cmp_types.hpp>
#include <cmath>
namespace myx {
namespace math {
bool almost_equal_ulps( const float a, const float b,
const int maxUlpsDiff )
{
FloatCmp uA( a );
FloatCmp uB( b );
// Если знаки разные, то числа не равны.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if ( uA.negative() != uB.negative() )
{
// Кроме случая, когда +0==-0
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if ( a == b ) // -V550
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
{
return( true );
}
return( false );
}
// Разница в младших битах.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
auto ulpsDiff = std::abs( uA.i - uB.i );
if ( ulpsDiff <= maxUlpsDiff )
{
return( true );
}
return( false );
} // almost_equal_ulps
bool almost_equal_ulps( const double a, const double b,
const int maxUlpsDiff )
{
DoubleCmp uA( a );
DoubleCmp uB( b );
// Если знаки разные, то числа не равны.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if ( uA.negative() != uB.negative() )
{
// Кроме случая, когда +0==-0
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#endif
if ( a == b ) // -V550
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
{
return( true );
}
return( false );
}
// Разница в младших битах.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
auto ulpsDiff = std::abs( uA.i - uB.i );
if ( ulpsDiff <= maxUlpsDiff )
{
return( true );
}
return( false );
} // almost_equal_ulps
} // namespace math
} // namespace myx
#include <myx/math/almost_equal_ulps-inl.hpp>

View File

@ -1,6 +1,7 @@
#ifndef MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
#define MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
#include <myx/base/config.hpp>
#include <myx/math/float_cmp_types.hpp>
#include <cmath>
@ -28,4 +29,8 @@ bool almost_equal_ulps( double a, double b,
} // namespace myx
#ifdef MYXLIB_HEADER_ONLY
#include "almost_equal_ulps-inl.hpp"
#endif
#endif // MYX_MATH_ALMOST_EQUAL_ULPS_HPP_

View File

@ -0,0 +1,80 @@
#ifndef MYXLIB_HEADER_ONLY
#include <myx/math/almost_equal_ulps_and_abs.hpp>
#endif
#include <myx/math/float_cmp_types.hpp>
#include <cmath>
namespace myx {
namespace math {
bool almost_equal_ulps_and_abs( const float a, const float b,
const float maxAbsDiff, const int maxUlpsDiff )
{
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
float absDiff = fabsf( a - b );
if ( absDiff <= maxAbsDiff )
{
return( true );
}
FloatCmp uA( a );
FloatCmp uB( b );
// Different signs means they do not match.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if ( uA.negative() != uB.negative() )
{
return( false );
}
// Find the difference in ULPs.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
int ulpsDiff = std::abs( uA.i - uB.i );
if ( ulpsDiff <= maxUlpsDiff )
{
return( true );
}
return( false );
} // almost_equal_ulps_and_abs
bool almost_equal_ulps_and_abs( const double a, const double b,
const double maxAbsDiff, const int maxUlpsDiff )
{
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
double absDiff = fabs( a - b );
if ( absDiff <= maxAbsDiff )
{
return( true );
}
DoubleCmp uA( a );
DoubleCmp uB( b );
// Different signs means they do not match.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if ( uA.negative() != uB.negative() )
{
return( false );
}
// Find the difference in ULPs.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
auto ulpsDiff = std::abs( uA.i - uB.i );
if ( ulpsDiff <= maxUlpsDiff )
{
return( true );
}
return( false );
} // almost_equal_ulps_and_abs
} // namespace math
} // namespace myx

View File

@ -1,77 +1 @@
#include <myx/math/almost_equal_ulps_and_abs.hpp>
#include <myx/math/float_cmp_types.hpp>
#include <cmath>
namespace myx {
namespace math {
bool almost_equal_ulps_and_abs( const float a, const float b,
const float maxAbsDiff, const int maxUlpsDiff )
{
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
float absDiff = fabsf( a - b );
if ( absDiff <= maxAbsDiff )
{
return( true );
}
FloatCmp uA( a );
FloatCmp uB( b );
// Different signs means they do not match.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if ( uA.negative() != uB.negative() )
{
return( false );
}
// Find the difference in ULPs.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
int ulpsDiff = std::abs( uA.i - uB.i );
if ( ulpsDiff <= maxUlpsDiff )
{
return( true );
}
return( false );
} // almost_equal_ulps_and_abs
bool almost_equal_ulps_and_abs( const double a, const double b,
const double maxAbsDiff, const int maxUlpsDiff )
{
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
double absDiff = fabs( a - b );
if ( absDiff <= maxAbsDiff )
{
return( true );
}
DoubleCmp uA( a );
DoubleCmp uB( b );
// Different signs means they do not match.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if ( uA.negative() != uB.negative() )
{
return( false );
}
// Find the difference in ULPs.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
auto ulpsDiff = std::abs( uA.i - uB.i );
if ( ulpsDiff <= maxUlpsDiff )
{
return( true );
}
return( false );
} // almost_equal_ulps_and_abs
} // namespace math
} // namespace myx
#include <myx/math/almost_equal_ulps_and_abs-inl.hpp>

View File

@ -1,6 +1,8 @@
#ifndef MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
#define MYX_MATH_ALMOST_EQUAL_ULPS_HPP_
#include <myx/base/config.hpp>
namespace myx {
namespace math {
@ -26,4 +28,8 @@ bool almost_equal_ulps_and_abs( double a, double b,
} // namespace myx
#ifdef MYXLIB_HEADER_ONLY
#include "almost_equal_ulps_and_abs-inl.hpp"
#endif
#endif // MYX_MATH_ALMOST_EQUAL_ULPS_HPP_

View File

@ -0,0 +1,11 @@
#ifndef MYXLIB_HEADER_ONLY
#include <myx/math/constants.hpp>
#endif
namespace myx {
namespace math {
} // namespace math
} // namespace myx

View File

@ -1,9 +1 @@
#include <myx/math/constants.hpp>
namespace myx {
namespace math {
} // namespace math
} // namespace myx
#include <myx/math/constants-inl.hpp>

View File

@ -1,6 +1,8 @@
#ifndef MYX_MATH_CONSTANTS_HPP_
#define MYX_MATH_CONSTANTS_HPP_
#include <myx/base/config.hpp>
#include <cmath>
#include <type_traits>
@ -8,11 +10,14 @@ namespace myx {
namespace math {
const auto ImpedanceOfFreeSpace = 376.7303136675757;
const auto ImpedanceOfFreeSpace = (M_PI * 119.9169832);
} // namespace math
} // namespace myx
#ifdef MYXLIB_HEADER_ONLY
#include "constants-inl.hpp"
#endif
#endif // MYX_MATH_CONSTANTS_HPP_