From 87f4c854d859116337cd1dc4da820c9494e9e78e Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Wed, 6 May 2020 17:59:39 +0300 Subject: [PATCH 01/41] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/cmlib | 2 +- cmake/etc/uncrustify | 2 +- cmake/find | 2 +- examples/filesystem/01_minimal/minimal.cpp | 4 ++-- l10n/example-qt-translators_ru_RU.ts | 13 ------------- src/myx/base/enum_bitmask_operations.hpp | 5 +++-- src/myx/base/limits.hpp | 6 +++--- src/myx/filesystem/paths.cpp | 2 +- src/myx/filesystem/paths.hpp | 4 ++-- src/myx/filesystem/paths_mt.cpp | 8 ++++---- src/myx/filesystem/paths_mt.hpp | 4 ++-- 11 files changed, 20 insertions(+), 32 deletions(-) diff --git a/cmake/cmlib b/cmake/cmlib index 9df1889..23be253 160000 --- a/cmake/cmlib +++ b/cmake/cmlib @@ -1 +1 @@ -Subproject commit 9df188963e5980d305dd50d721978ccdd997a8c3 +Subproject commit 23be253a8db87d51c25a67ffc41c452e5b8f58d5 diff --git a/cmake/etc/uncrustify b/cmake/etc/uncrustify index 0cd764f..959608f 160000 --- a/cmake/etc/uncrustify +++ b/cmake/etc/uncrustify @@ -1 +1 @@ -Subproject commit 0cd764fc187ab3b66cb31a5549f13b3336858894 +Subproject commit 959608f6b5d8c6e4add9f9e7422109bc6b795a5f diff --git a/cmake/find b/cmake/find index d0bc6e7..00bbf68 160000 --- a/cmake/find +++ b/cmake/find @@ -1 +1 @@ -Subproject commit d0bc6e71e9c613eaaecca62eaf445d647f5216ed +Subproject commit 00bbf686cdb5bd32ba7105bec1234c85aee6f0aa diff --git a/examples/filesystem/01_minimal/minimal.cpp b/examples/filesystem/01_minimal/minimal.cpp index 5616bcc..1460a61 100644 --- a/examples/filesystem/01_minimal/minimal.cpp +++ b/examples/filesystem/01_minimal/minimal.cpp @@ -11,8 +11,8 @@ namespace MF = myx::filesystem; // Переменные для защиты экземпляра класса MF::PathsMT -std::atomic< MF::PathsMT* > MF::PathsMT::mInstance; -std::mutex MF::PathsMT::mMutex; +std::atomic< MF::PathsMT* > MF::PathsMT::sInstance; +std::mutex MF::PathsMT::sMutex; int main( int argc, char** argv ) diff --git a/l10n/example-qt-translators_ru_RU.ts b/l10n/example-qt-translators_ru_RU.ts index a8264a7..f62cf2e 100644 --- a/l10n/example-qt-translators_ru_RU.ts +++ b/l10n/example-qt-translators_ru_RU.ts @@ -1,17 +1,4 @@ - - QObject - - - Yes - Да - - - - Cancel - Отмена - - diff --git a/src/myx/base/enum_bitmask_operations.hpp b/src/myx/base/enum_bitmask_operations.hpp index 12a8d56..573bac1 100644 --- a/src/myx/base/enum_bitmask_operations.hpp +++ b/src/myx/base/enum_bitmask_operations.hpp @@ -12,7 +12,7 @@ namespace base { template< typename Enum > struct EnableBitMaskOperators { - static const bool k_Enable = false; + static const bool kEnable = false; }; template< typename Enum > @@ -47,11 +47,12 @@ operator |( Enum lhs, Enum rhs ) * ENABLE_BITMASK_OPERATORS(ns::Permissions) */ +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ENABLE_BITMASK_OPERATORS( x ) \ template<> \ struct myx::base::EnableBitMaskOperators< x > \ { \ - static const bool k_Enable = true; \ + static const bool kEnable = true; \ }; #endif // ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_ diff --git a/src/myx/base/limits.hpp b/src/myx/base/limits.hpp index 53c02d1..3f5d390 100644 --- a/src/myx/base/limits.hpp +++ b/src/myx/base/limits.hpp @@ -12,17 +12,17 @@ namespace base { /** * @brief Константа, представляющая значение, не являющееся числом, для типа float */ -constexpr float k_FloatNAN { std::numeric_limits< float >::quiet_NaN() }; +constexpr float kFloatNAN { std::numeric_limits< float >::quiet_NaN() }; /** * @brief Константа, представляющая значение, не являющееся числом, для типа double */ -constexpr double k_DoubleNAN { std::numeric_limits< double >::quiet_NaN() }; +constexpr double kDoubleNAN { std::numeric_limits< double >::quiet_NaN() }; /** * @brief Константа, представляющая значение, не являющееся числом, для типа long double */ -constexpr double k_LongDoubleNAN { std::numeric_limits< long double >::quiet_NaN() }; +constexpr double kLongDoubleNAN { std::numeric_limits< long double >::quiet_NaN() }; } // namespace base diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index dc5b611..8811210 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -21,7 +21,7 @@ namespace filesystem { MYXLIB_INLINE Paths::Paths() = default; -MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() +MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // V2008 { QRegExp binUnityRegexp( "/s*bin/unity$" ); QRegExp binRegexp( "/s*bin$" ); diff --git a/src/myx/filesystem/paths.hpp b/src/myx/filesystem/paths.hpp index 6cb93be..e542094 100644 --- a/src/myx/filesystem/paths.hpp +++ b/src/myx/filesystem/paths.hpp @@ -102,8 +102,8 @@ public: */ static Paths& instance() { - static Paths p; - return( p ); + static Paths sPaths; + return( sPaths ); } diff --git a/src/myx/filesystem/paths_mt.cpp b/src/myx/filesystem/paths_mt.cpp index b0c5e86..b1adf3c 100644 --- a/src/myx/filesystem/paths_mt.cpp +++ b/src/myx/filesystem/paths_mt.cpp @@ -23,15 +23,15 @@ MYXLIB_INLINE PathsMT::PathsMT() = default; MYXLIB_INLINE PathsMT& PathsMT::instance() { - volatile PathsMT* localInstance = mInstance.load( std::memory_order_acquire ); + volatile PathsMT* localInstance = sInstance.load( std::memory_order_acquire ); if ( localInstance == nullptr ) { - std::lock_guard< std::mutex > myLock( mMutex ); - localInstance = mInstance.load( std::memory_order_relaxed ); + std::lock_guard< std::mutex > myLock( sMutex ); + localInstance = sInstance.load( std::memory_order_relaxed ); if ( localInstance == nullptr ) // -V1036 { localInstance = new PathsMT(); - mInstance.store( const_cast< PathsMT* >( localInstance ), std::memory_order_release ); // NOLINT + sInstance.store( const_cast< PathsMT* >( localInstance ), std::memory_order_release ); // NOLINT } } return( const_cast< PathsMT& >( *localInstance ) ); // NOLINT diff --git a/src/myx/filesystem/paths_mt.hpp b/src/myx/filesystem/paths_mt.hpp index 3a5b7fd..3247c75 100644 --- a/src/myx/filesystem/paths_mt.hpp +++ b/src/myx/filesystem/paths_mt.hpp @@ -31,8 +31,8 @@ class PathsMT : public Paths PathsMT(); ~PathsMT() = default; - static std::atomic< PathsMT* > mInstance; - static std::mutex mMutex; + static std::atomic< PathsMT* > sInstance; + static std::mutex sMutex; public: From f845b2fda1d250bf5a1dddfad1f505a888a83236 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Wed, 6 May 2020 18:03:51 +0300 Subject: [PATCH 02/41] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B4=D1=83=D0=BF=D1=80=D0=B5=D0=B6=D0=B4?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/filesystem/paths.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index 8811210..797005e 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -21,7 +21,7 @@ namespace filesystem { MYXLIB_INLINE Paths::Paths() = default; -MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // V2008 +MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // -V2008 { QRegExp binUnityRegexp( "/s*bin/unity$" ); QRegExp binRegexp( "/s*bin$" ); From 09d1e12a44d29af97dac11ea96ced1dd3ce83ae2 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 14 May 2020 10:43:38 +0300 Subject: [PATCH 03/41] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=84=D0=B0=D0=B9=D0=BB=20=D1=81=20=D1=82=D0=B8?= =?UTF-8?q?=D0=BF=D0=B0=D0=BC=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B7=D1=80=D0=B0=D1=87=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B5=D0=BE=D0=B1=D1=80=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D1=80=D1=8F=D0=B4=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B1=D0=B0=D0=B9=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/etc/uncrustify | 2 +- src/myx/base/CMakeLists.txt | 1 + src/myx/base/endian_types.hpp | 216 ++++++++++++++++++++++++++++++++++ 3 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 src/myx/base/endian_types.hpp diff --git a/cmake/etc/uncrustify b/cmake/etc/uncrustify index 959608f..7324d80 160000 --- a/cmake/etc/uncrustify +++ b/cmake/etc/uncrustify @@ -1 +1 @@ -Subproject commit 959608f6b5d8c6e4add9f9e7422109bc6b795a5f +Subproject commit 7324d80f3dc97ee9a1da464e9ed7389e00fff880 diff --git a/src/myx/base/CMakeLists.txt b/src/myx/base/CMakeLists.txt index fa3adb8..5388d60 100644 --- a/src/myx/base/CMakeLists.txt +++ b/src/myx/base/CMakeLists.txt @@ -10,6 +10,7 @@ set(TRGT_cpp set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/config.hpp ${CMAKE_CURRENT_SOURCE_DIR}/limits.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/endian_types.hpp ${CMAKE_CURRENT_SOURCE_DIR}/enum_bitmask_operations.hpp) set(TRGT_headers ${TRGT_hpp}) diff --git a/src/myx/base/endian_types.hpp b/src/myx/base/endian_types.hpp new file mode 100644 index 0000000..42639d0 --- /dev/null +++ b/src/myx/base/endian_types.hpp @@ -0,0 +1,216 @@ +#ifndef MYX_BASE_ENDIAN_TYPES_HPP_ +#define MYX_BASE_ENDIAN_TYPES_HPP_ + +#pragma once + +#include +#include +#include + +#ifdef QT_CORE_LIB +#include +#endif + +// Both LittleEndianType and BigEndianType are manufactured primitives +// that are essentially immutable except for the assignment operators. +// All math logic happens outside of the class in the native format +// and an internal set/swap method is used to store the data. + +namespace myx { + +namespace base { + +template< typename T > +class EndianTypesBase +{ +protected: + #if _MSC_VER + #pragma warning ( push ) + #endif + static T swapBytes( const T& b ) + { + T n; + switch ( sizeof( T ) ) + { + case 8: // 64-bit + ( reinterpret_cast< uint8_t* >( &n ) )[0] = ( reinterpret_cast< const uint8_t* >( &b ) )[7]; + ( reinterpret_cast< uint8_t* >( &n ) )[1] = ( reinterpret_cast< const uint8_t* >( &b ) )[6]; + ( reinterpret_cast< uint8_t* >( &n ) )[2] = ( reinterpret_cast< const uint8_t* >( &b ) )[5]; + ( reinterpret_cast< uint8_t* >( &n ) )[3] = ( reinterpret_cast< const uint8_t* >( &b ) )[4]; + ( reinterpret_cast< uint8_t* >( &n ) )[4] = ( reinterpret_cast< const uint8_t* >( &b ) )[3]; + ( reinterpret_cast< uint8_t* >( &n ) )[5] = ( reinterpret_cast< const uint8_t* >( &b ) )[2]; + ( reinterpret_cast< uint8_t* >( &n ) )[6] = ( reinterpret_cast< const uint8_t* >( &b ) )[1]; + ( reinterpret_cast< uint8_t* >( &n ) )[7] = ( reinterpret_cast< const uint8_t* >( &b ) )[0]; + break; + case 4: // 32-bit + ( reinterpret_cast< uint8_t* >( &n ) )[0] = ( reinterpret_cast< const uint8_t* >( &b ) )[3]; + ( reinterpret_cast< uint8_t* >( &n ) )[1] = ( reinterpret_cast< const uint8_t* >( &b ) )[2]; + ( reinterpret_cast< uint8_t* >( &n ) )[2] = ( reinterpret_cast< const uint8_t* >( &b ) )[1]; + ( reinterpret_cast< uint8_t* >( &n ) )[3] = ( reinterpret_cast< const uint8_t* >( &b ) )[0]; + break; + case 2: // 16-bit + ( reinterpret_cast< uint8_t* >( &n ) )[0] = ( reinterpret_cast< const uint8_t* >( &b ) )[1]; + ( reinterpret_cast< uint8_t* >( &n ) )[1] = ( reinterpret_cast< const uint8_t* >( &b ) )[0]; + break; + default: + assert( 0 ); // Endian swap is only defined for 2, 4, and 8-byte types + break; + } // switch + + return( n ); + } // swapBytes + + + #if _MSC_VER + #pragma warning ( pop ) + #endif +}; // class EndianTypesBase + +template< typename T > +class LittleEndianType : public EndianTypesBase< T > +{ +protected: + T m_data; + + static T transform( const T& b ) + { + const uint16_t i = 1; + return( ( reinterpret_cast< const char& >( i ) == 1 ) ? b : EndianTypesBase< T >::swapBytes( b ) ); + } + + +public: + // Constructors + LittleEndianType() = default; + + // If we endian swap, it happens in two places: + // 1. Set an OE from a PE + // 2. Get a PE from an OE + // Storage in + explicit LittleEndianType( const T& b ) : + m_data( transform( b ) ) + {} + template < typename U > explicit LittleEndianType( U const& b ) : + m_data( transform( T( b ) ) ) + {} + // Storage out + template < typename U > explicit operator U() const { return( U( transform( m_data ) ) ); } + explicit operator T() const { return( transform( m_data ) ); } + + template < typename U > bool operator ==( U const& o ) { return( U( *this ) == o ); } + template < typename U > bool operator !=( U const& o ) { return( U( *this ) != o ); } + + // Arithmetic assignment operators + LittleEndianType& operator ++() /* prefix */ { *this = T( *this ) + T( 1 ); return( *this ); } + LittleEndianType operator ++( int ) /* suffix */ { LittleEndianType t( *this ); *this = T( *this ) + T( 1 ); return( t ); } + LittleEndianType& operator --() /* prefix */ { *this = T( *this ) - T( 1 ); return( *this ); } + LittleEndianType operator --( int ) /* suffix */ { LittleEndianType t( *this ); *this = T( *this ) - T( 1 ); return( t ); } + + // Compound assignment operators + LittleEndianType& operator +=( const T& b ) { *this = T( *this ) + b; return( *this ); } + LittleEndianType& operator -=( const T& b ) { *this = T( *this ) - b; return( *this ); } + LittleEndianType& operator *=( const T& b ) { *this = T( *this ) * b; return( *this ); } + LittleEndianType& operator /=( const T& b ) { *this = T( *this ) / b; return( *this ); } + LittleEndianType& operator %=( const T& b ) { *this = T( *this ) % b; return( *this ); } + LittleEndianType& operator &=( const T& b ) { *this = T( *this ) & b; return( *this ); } + LittleEndianType& operator |=( const T& b ) { *this = T( *this ) | b; return( *this ); } + LittleEndianType& operator ^=( const T& b ) { *this = T( *this ) ^ b; return( *this ); } + LittleEndianType& operator <<=( const T& b ) { *this = T( T( *this ) << b ); return( *this ); } + LittleEndianType& operator >>=( const T& b ) { *this = T( T( *this ) >> b ); return( *this ); } + friend std::ostream& operator <<( std::ostream& out, const LittleEndianType b ) { out << T( b ); return( out ); } + friend std::istream& operator >>( std::istream& in, LittleEndianType& b ) { T val; in >> val; b = val; return( in ); } + std::string toStdString() { return( std::to_string( transform( m_data ) ) ); } + #ifdef QT_CORE_LIB + friend QDebug& operator <<( QDebug& out, const BigEndianType b ) { out << T( b ); return( out ); } + QString toQString() { return( QString::number( transform( m_data ) ) ); } + #endif +}; // class LittleEndianType + + +template< typename T > +class BigEndianType : public EndianTypesBase< T > +{ +protected: + T m_data; + + static T transform( const T& b ) + { + const uint16_t i = 1; + return( ( reinterpret_cast< const char& >( i ) == 1 ) ? EndianTypesBase< T >::swapBytes( b ) : b ); + } + + +public: + // Constructors + BigEndianType() = default; + + // If we endian swap, it happens in two places: + // 1. Set an OE from a PE + // 2. Get a PE from an OE + // Storage in + explicit BigEndianType( const T& b ) : + m_data( transform( b ) ) + {} + template < typename U > explicit BigEndianType( U const& b ) : + m_data( transform( T( b ) ) ) + {} + // Storage out + template < typename U > explicit operator U() const { return( U( transform( m_data ) ) ); } + explicit operator T() const { return( transform( m_data ) ); } + + template < typename U > bool operator ==( U const& o ) { return( U( *this ) == o ); } + template < typename U > bool operator !=( U const& o ) { return( U( *this ) != o ); } + + // Arithmetic assignment operators + BigEndianType& operator ++() /* prefix */ { *this = T( *this ) + 1; return( *this ); } + BigEndianType operator ++( int ) /* suffix */ { BigEndianType t( *this ); *this = T( *this ) + 1; return( t ); } + BigEndianType& operator --() /* prefix */ { *this = T( *this ) - 1; return( *this ); } + BigEndianType operator --( int ) /* suffix */ { BigEndianType t( *this ); *this = T( *this ) - 1; return( t ); } + + // Compound assignment operators + BigEndianType& operator +=( const T& b ) { *this = T( *this ) + b; return( *this ); } + BigEndianType& operator -=( const T& b ) { *this = T( *this ) - b; return( *this ); } + BigEndianType& operator *=( const T& b ) { *this = T( *this ) * b; return( *this ); } + BigEndianType& operator /=( const T& b ) { *this = T( *this ) / b; return( *this ); } + BigEndianType& operator %=( const T& b ) { *this = T( *this ) % b; return( *this ); } + BigEndianType& operator &=( const T& b ) { *this = T( *this ) & b; return( *this ); } + BigEndianType& operator |=( const T& b ) { *this = T( *this ) | b; return( *this ); } + BigEndianType& operator ^=( const T& b ) { *this = T( *this ) ^ b; return( *this ); } + BigEndianType& operator <<=( const T& b ) { *this = T( T( *this ) << b ); return( *this ); } + BigEndianType& operator >>=( const T& b ) { *this = T( T( *this ) >> b ); return( *this ); } + friend std::ostream& operator <<( std::ostream& out, const BigEndianType b ) { out << T( b ); return( out ); } + friend std::istream& operator >>( std::istream& in, BigEndianType& b ) { T val; in >> val; b = val; return( in ); } + std::string toStdString() { return( std::to_string( transform( m_data ) ) ); } + #ifdef QT_CORE_LIB + friend QDebug& operator <<( QDebug& out, const BigEndianType b ) { out << T( b ); return( out ); } + QString toQString() { return( QString::number( transform( m_data ) ) ); } + #endif +}; // class BigEndianType + +} // namespace base + +} // namespace myx + +using leint16 = myx::base::LittleEndianType< int16_t >; +using leint32 = myx::base::LittleEndianType< int32_t >; +using leint64 = myx::base::LittleEndianType< int64_t >; + +using leuint16 = myx::base::LittleEndianType< uint16_t >; +using leuint32 = myx::base::LittleEndianType< uint32_t >; +using leuint64 = myx::base::LittleEndianType< uint64_t >; + +using lefloat = myx::base::LittleEndianType< float >; +using ledouble = myx::base::LittleEndianType< double >; + +using beint16 = myx::base::BigEndianType< int16_t >; +using beint32 = myx::base::BigEndianType< int32_t >; +using beint64 = myx::base::BigEndianType< int64_t >; + +using beuint16 = myx::base::BigEndianType< uint16_t >; +using beuint32 = myx::base::BigEndianType< uint32_t >; +using beuint64 = myx::base::BigEndianType< uint64_t >; + +using befloat = myx::base::BigEndianType< float >; +using bedouble = myx::base::BigEndianType< double >; + +#endif // MYX_BASE_ENDIAN_TYPES_HPP_ From d9881f92b3bd3444214ee481cab2d86a1d6714db Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 15 May 2020 11:13:26 +0300 Subject: [PATCH 04/41] =?UTF-8?q?=D0=97=D0=BD=D0=B0=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0?= =?UTF-8?q?=D1=8E=D1=82=D1=81=D1=8F=20=D0=BA=D0=B0=D0=BA=20const=20QString?= =?UTF-8?q?&?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/filesystem/01_minimal/minimal.cpp | 6 +- src/myx/filesystem/paths.cpp | 87 ++++++++++--------- src/myx/filesystem/paths.hpp | 99 +++++++++++----------- 3 files changed, 99 insertions(+), 93 deletions(-) diff --git a/examples/filesystem/01_minimal/minimal.cpp b/examples/filesystem/01_minimal/minimal.cpp index 1460a61..77f8180 100644 --- a/examples/filesystem/01_minimal/minimal.cpp +++ b/examples/filesystem/01_minimal/minimal.cpp @@ -25,12 +25,12 @@ int main( int argc, char** argv ) pathsMT.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) ); pathsMT.findConfigFile( QStringLiteral( "test" ) ); - qDebug() << pathsMT.systemLogDirectory().path(); - qDebug() << pathsMT.systemConfigDirectory().path(); + qDebug() << pathsMT.systemLogDirectory(); + qDebug() << pathsMT.systemConfigDirectory(); paths.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) ); paths.findConfigFile( QStringLiteral( "test" ) ); - qDebug() << paths.systemConstDataDirectory().path(); + qDebug() << paths.systemConstDataDirectory(); qDebug() << paths.configFileName(); return( 0 ); diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index 797005e..302a072 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -25,7 +25,7 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // -V2008 { QRegExp binUnityRegexp( "/s*bin/unity$" ); QRegExp binRegexp( "/s*bin$" ); - auto binaryDir = m_currentExecutable.m_canonicalFilePath.canonicalPath(); + auto binaryDir = m_executableDirectory; if ( binUnityRegexp.indexIn( binaryDir ) >= 0 ) { @@ -124,19 +124,19 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // -V2008 return ( HierarchyType::kUsr ); } - if ( binaryDir.startsWith( m_homeDirectory.canonicalPath() + "/.local/bin" ) || - binaryDir.startsWith( m_homeDirectory.canonicalPath() + "/bin" ) ) + if ( binaryDir.startsWith( m_homeDirectory + "/.local/bin" ) || + binaryDir.startsWith( m_homeDirectory + "/bin" ) ) { - QFileInfo etcDirInfo { m_userConfigDirectory.canonicalPath() }; + QFileInfo etcDirInfo { m_userConfigDirectory }; if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - QFileInfo constDataDirInfo { m_userConstDataDirectory.canonicalPath() }; + QFileInfo constDataDirInfo { m_userConstDataDirectory }; if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - QFileInfo varDataDirInfo { m_userVarDataDirectory.canonicalPath() }; + QFileInfo varDataDirInfo { m_userVarDataDirectory }; if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - QFileInfo logDirInfo { m_userLogDirectory.canonicalPath() }; + QFileInfo logDirInfo { m_userLogDirectory }; if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } m_systemConfigDirectory = etcDirInfo.canonicalFilePath(); @@ -172,7 +172,12 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // -V2008 MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& configFileExtension ) { - m_projectName = projectDir.isEmpty() ? m_currentExecutable.m_canonicalFilePath.fileName() + CurrentExecutable exe; + m_executableName = exe.m_canonicalFilePath.fileName(); + m_executableFilePath = exe.m_canonicalFilePath.absoluteFilePath(); + m_executableDirectory = exe.m_canonicalFilePath.absolutePath(); + + m_projectName = projectDir.isEmpty() ? m_executableName : projectDir; m_configFileExtension = configFileExtension.isEmpty() ? QStringLiteral( "conf" ) : configFileExtension; @@ -184,14 +189,14 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config auto configHome = QString::fromLocal8Bit( qgetenv( "XDG_CONFIG_HOME" ) ); if ( configHome.isEmpty() ) { - configHome = m_homeDirectory.canonicalPath() + "/.config"; + configHome = m_homeDirectory + "/.config"; } m_userConfigDirectory = configHome + "/" + m_projectName; auto dataHome = QString::fromLocal8Bit( qgetenv( "XDG_DATA_HOME" ) ); if ( dataHome.isEmpty() ) { - dataHome = m_homeDirectory.canonicalPath() + "/.local/share"; + dataHome = m_homeDirectory + "/.local/share"; } dataHome += "/" + m_projectName; m_userConstDataDirectory = dataHome + "/data"; @@ -202,13 +207,13 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config if ( m_hierarchyType == HierarchyType::kFlat ) { - m_systemConstDataDirectory = m_currentExecutable.m_canonicalFilePath.canonicalPath(); - m_systemVarDataDirectory = m_currentExecutable.m_canonicalFilePath.canonicalPath(); - m_systemConfigDirectory = m_currentExecutable.m_canonicalFilePath.canonicalPath(); - m_systemLogDirectory = m_currentExecutable.m_canonicalFilePath.canonicalPath(); + m_systemConstDataDirectory = m_executableDirectory; + m_systemVarDataDirectory = m_executableDirectory; + m_systemConfigDirectory = m_executableDirectory; + m_systemLogDirectory = m_executableDirectory; } - m_configFilePath = m_systemConfigDirectory.canonicalPath() + "/" + m_configFileName; + m_configFilePath = m_systemConfigDirectory + "/" + m_configFileName; return( true ); } // Paths::updatePaths @@ -218,10 +223,10 @@ MYXLIB_INLINE bool Paths::makeDefaultDirectories() { bool status = true; - if ( !m_userConfigDirectory.mkpath( m_userConfigDirectory.absolutePath() ) ) { status = false; } - if ( !m_userVarDataDirectory.mkpath( m_userVarDataDirectory.absolutePath() ) ) { status = false; } - if ( !m_userConstDataDirectory.mkpath( m_userConstDataDirectory.absolutePath() ) ) { status = false; } - if ( !m_userLogDirectory.mkpath( m_userLogDirectory.absolutePath() ) ) { status = false; } +// FIXME if ( !m_userConfigDirectory.mkpath( m_userConfigDirectory ) ) { status = false; } +// if ( !m_userVarDataDirectory.mkpath( m_userVarDataDirectory ) ) { status = false; } +// if ( !m_userConstDataDirectory.mkpath( m_userConstDataDirectory ) ) { status = false; } +// if ( !m_userLogDirectory.mkpath( m_userLogDirectory ) ) { status = false; } return( status ); } @@ -244,32 +249,26 @@ MYXLIB_INLINE QString Paths::findConfigFile( const QString& defaultConfigFile ) if ( QFileInfo( m_configFilePath ).isReadable() ) { - return( m_configFilePath.absoluteFilePath() ); + return( m_configFilePath ); } return( QString() ); } // Paths::findConfigFile -MYXLIB_INLINE QDir Paths::executableFileDirectory() const -{ - return( m_currentExecutable.m_canonicalFilePath.dir() ); -} - - -MYXLIB_INLINE const QDir& Paths::userConfigDirectory() const +MYXLIB_INLINE const QString& Paths::userConfigDirectory() const { return( m_userConfigDirectory ); } -MYXLIB_INLINE const QDir& Paths::systemConfigDirectory() const +MYXLIB_INLINE const QString& Paths::systemConfigDirectory() const { return( m_systemConfigDirectory ); } -MYXLIB_INLINE const QFileInfo& Paths::configFilePath() const +MYXLIB_INLINE const QString& Paths::configFilePath() const { return( m_configFilePath ); } @@ -287,49 +286,49 @@ MYXLIB_INLINE const QString& Paths::configFileExtension() const } -MYXLIB_INLINE const QDir& Paths::userVarDataDirectory() const +MYXLIB_INLINE const QString& Paths::userVarDataDirectory() const { return( m_userVarDataDirectory ); } -MYXLIB_INLINE const QDir& Paths::systemVarDataDirectory() const +MYXLIB_INLINE const QString& Paths::systemVarDataDirectory() const { return( m_systemVarDataDirectory ); } -MYXLIB_INLINE const QDir& Paths::userConstDataDirectory() const +MYXLIB_INLINE const QString& Paths::userConstDataDirectory() const { return( m_userConstDataDirectory ); } -MYXLIB_INLINE const QDir& Paths::systemConstDataDirectory() const +MYXLIB_INLINE const QString& Paths::systemConstDataDirectory() const { return( m_systemConstDataDirectory ); } -MYXLIB_INLINE const QDir& Paths::userLogDirectory() const +MYXLIB_INLINE const QString& Paths::userLogDirectory() const { return( m_userLogDirectory ); } -MYXLIB_INLINE const QDir& Paths::systemLogDirectory() const +MYXLIB_INLINE const QString& Paths::systemLogDirectory() const { return( m_systemLogDirectory ); } -MYXLIB_INLINE const QDir& Paths::tempDirectory() const +MYXLIB_INLINE const QString& Paths::tempDirectory() const { return( m_tempDirectory ); } -MYXLIB_INLINE const QDir& Paths::homeDirectory() const +MYXLIB_INLINE const QString& Paths::homeDirectory() const { return( m_homeDirectory ); } @@ -341,15 +340,21 @@ MYXLIB_INLINE const QString& Paths::projectName() const } -MYXLIB_INLINE QString Paths::executableFileName() const +MYXLIB_INLINE const QString& Paths::executableName() const { - return( m_currentExecutable.m_canonicalFilePath.fileName() ); + return( m_executableName ); } -MYXLIB_INLINE const QFileInfo& Paths::executableFilePath() const +MYXLIB_INLINE const QString& Paths::executableFilePath() const { - return( m_currentExecutable.m_canonicalFilePath ); + return( m_executableFilePath ); +} + + +MYXLIB_INLINE const QString& Paths::executableDirectory() const +{ + return( m_executableDirectory ); } } // namespace filesystem diff --git a/src/myx/filesystem/paths.hpp b/src/myx/filesystem/paths.hpp index e542094..04ffce5 100644 --- a/src/myx/filesystem/paths.hpp +++ b/src/myx/filesystem/paths.hpp @@ -46,39 +46,40 @@ class Paths /// @brief Тип расположения файлов по каталогам HierarchyType m_hierarchyType { HierarchyType::kFlat }; - /// @brief Параметры текущего исполняемого файла - CurrentExecutable m_currentExecutable; - /// @brief Имя проекта, которое используется при формировании имён файлов и каталогов QString m_projectName; + QString m_executableName; + QString m_executableFilePath; + QString m_executableDirectory; + /// @brief Путь к каталогу с временными файлами - QDir m_tempDirectory; + QString m_tempDirectory; /// @brief Путь к домашнему каталогу текущего пользователя - QDir m_homeDirectory; + QString m_homeDirectory; /// @brief Путь к пользовательскому каталогу с изменяемыми файлами - QDir m_userVarDataDirectory; + QString m_userVarDataDirectory; /// @brief Путь к системному каталогу с изменяемыми файлами - QDir m_systemVarDataDirectory; + QString m_systemVarDataDirectory; /// @brief Путь к пользовательскому каталогу с неизменяемыми файлами - QDir m_userConstDataDirectory; + QString m_userConstDataDirectory; /// @brief Путь к системному каталогу с неизменяемыми файлами - QDir m_systemConstDataDirectory; + QString m_systemConstDataDirectory; /// @brief Путь к пользовательскому каталогу с журналами работы - QDir m_userLogDirectory; + QString m_userLogDirectory; /// @brief Путь к системному каталогу с журналами работы - QDir m_systemLogDirectory; + QString m_systemLogDirectory; /// @brief Путь к пользовательскому каталогу с файлами настройки - QDir m_userConfigDirectory; + QString m_userConfigDirectory; /// @brief Путь к системному каталогу с файлами настройки - QDir m_systemConfigDirectory; + QString m_systemConfigDirectory; /// @brief Полный путь к файлу настройки - QFileInfo m_configFilePath; + QString m_configFilePath; /// @brief Имя файла настройки QString m_configFileName; /// @brief Расширение для файла настройки @@ -130,27 +131,22 @@ public: /** * @brief Полный путь к базовому каталогу */ - const QDir& prefixDirectory() const; + const QString& prefixDirectory() const; + + /** + * @brief Имя исполняемого файла + */ + const QString& executableName() const; + + /** + * @brief Полный путь к исполняемому файлу + */ + const QString& executableFilePath() const; /** * @brief Полный путь к каталогу с исполняемым файлом */ - QDir executableFileDirectory() const; - - /** - * @brief Полный путь к пользовательскому каталогу с файлами настройки - */ - const QDir& userConfigDirectory() const; - - /** - * @brief Полный путь к системному каталогу с файлами настройки - */ - const QDir& systemConfigDirectory() const; - - /** - * @brief Полный путь к файлу настройки - */ - const QFileInfo& configFilePath() const; + const QString& executableDirectory() const; /** * @brief Имя файла настройки @@ -162,60 +158,65 @@ public: */ const QString& configFileExtension() const; + /** + * @brief Полный путь к файлу настройки + */ + const QString& configFilePath() const; + + /** + * @brief Полный путь к пользовательскому каталогу с файлами настройки + */ + const QString& userConfigDirectory() const; + + /** + * @brief Полный путь к системному каталогу с файлами настройки + */ + const QString& systemConfigDirectory() const; + /** * @brief Полный путь к пользовательскому каталогу с изменяемыми файлами */ - const QDir& userVarDataDirectory() const; + const QString& userVarDataDirectory() const; /** * @brief Полный путь к системному каталогу с изменяемыми файлами */ - const QDir& systemVarDataDirectory() const; + const QString& systemVarDataDirectory() const; /** * @brief Полный путь к пользовательскому каталогу с неизменяемыми файлами */ - const QDir& userConstDataDirectory() const; + const QString& userConstDataDirectory() const; /** * @brief Полный путь к системному каталогу с неизменяемыми файлами */ - const QDir& systemConstDataDirectory() const; + const QString& systemConstDataDirectory() const; /** * @brief Полный путь к пользовательскому каталогу с журналами работы */ - const QDir& userLogDirectory() const; + const QString& userLogDirectory() const; /** * @brief Полный путь к системному каталогу с журналами работы */ - const QDir& systemLogDirectory() const; + const QString& systemLogDirectory() const; /** * @brief Полный путь к каталогу с временными файлами */ - const QDir& tempDirectory() const; + const QString& tempDirectory() const; /** * @brief Полный путь к домашнему каталогу текущего пользователя */ - const QDir& homeDirectory() const; + const QString& homeDirectory() const; /** * @brief Имя подкаталога для проекта */ const QString& projectName() const; - - /** - * @brief Имя исполняемого файла - */ - QString executableFileName() const; - - /** - * @brief Полный путь к исполняемому файлу - */ - const QFileInfo& executableFilePath() const; }; // class Paths } // namespace filesystem From c503edfe49b06ad7f16537586df67d833b0d9620 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 15 May 2020 13:17:50 +0300 Subject: [PATCH 05/41] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D1=8B=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D1=84=D0=BE=D1=80=D0=BC=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=BC=D1=91?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/filesystem/paths.cpp | 203 ++++++++++++++++------------------- src/myx/filesystem/paths.hpp | 4 + 2 files changed, 94 insertions(+), 113 deletions(-) diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index 302a072..bfa6832 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -21,105 +21,109 @@ namespace filesystem { MYXLIB_INLINE Paths::Paths() = default; -MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // -V2008 + +MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultEtcDirectory, + const QString& defaultConstDataDirectory, + const QString& defaultVarDataDirectory, + const QString& defaultLogDirectory ) +{ + QFileInfo etcDirInfo { defaultEtcDirectory }; + if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) + { + m_systemConfigDirectory = defaultEtcDirectory; + } + else + { + m_systemConfigDirectory = m_userConfigDirectory; + } + + QFileInfo constDataDirInfo { defaultConstDataDirectory }; + if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) + { + m_systemConstDataDirectory = defaultConstDataDirectory; + } + else + { + m_systemConstDataDirectory = m_userConstDataDirectory; + } + + QFileInfo varDataDirInfo { defaultVarDataDirectory }; + if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) + { + m_systemVarDataDirectory = defaultVarDataDirectory; + } + else + { + m_systemVarDataDirectory = m_userVarDataDirectory; + } + + QFileInfo logDirInfo { defaultLogDirectory }; + if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) + { + m_systemLogDirectory = defaultLogDirectory; + } + else + { + m_systemLogDirectory = m_userLogDirectory; + } +} // Paths::setupSystemDirectories + + +Paths::HierarchyType Paths::getHierarchyType() { QRegExp binUnityRegexp( "/s*bin/unity$" ); - QRegExp binRegexp( "/s*bin$" ); auto binaryDir = m_executableDirectory; if ( binUnityRegexp.indexIn( binaryDir ) >= 0 ) { binaryDir.remove( binUnityRegexp ); - - QFileInfo etcDirInfo { binaryDir + "/etc" }; - if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo constDataDirInfo { binaryDir + "/files/data" }; - if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo varDataDirInfo { binaryDir + "/files/lib" }; - if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - QFileInfo logDirInfo { binaryDir + "/files/log" }; - if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - m_systemConfigDirectory = etcDirInfo.canonicalFilePath(); - m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath(); - m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath(); - m_systemLogDirectory = logDirInfo.canonicalFilePath(); + setupSystemDirectories( binaryDir + "/etc", + binaryDir + "/files/data", + binaryDir + "/files/lib", + binaryDir + "/files/log" ); return ( HierarchyType::kDevelopment ); } + QRegExp binRegexp( "/s*bin$" ); if ( binRegexp.indexIn( binaryDir ) == -1 ) { + m_systemConstDataDirectory = m_executableDirectory; + m_systemVarDataDirectory = m_executableDirectory; + m_systemConfigDirectory = m_executableDirectory; + m_systemLogDirectory = m_executableDirectory; + return ( HierarchyType::kFlat ); } QRegExp optRegexp( "^/opt(/|/.+/)" + m_projectName + "/" ); - if ( optRegexp.indexIn( binaryDir ) >= 0 ) { binaryDir.remove( binRegexp ); - QFileInfo etcDirInfo { binaryDir + "/etc" }; - if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo constDataDirInfo { binaryDir + "/files/data" }; - if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo varDataDirInfo { binaryDir + "/files/lib" }; - if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - QFileInfo logDirInfo { binaryDir + "/files/log" }; - if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - m_systemConfigDirectory = etcDirInfo.canonicalFilePath(); - m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath(); - m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath(); - m_systemLogDirectory = logDirInfo.canonicalFilePath(); + setupSystemDirectories( binaryDir + "/etc", + binaryDir + "/files/data", + binaryDir + "/files/lib", + binaryDir + "/files/log" ); return ( HierarchyType::kOpt ); } if ( binaryDir.startsWith( QStringLiteral( "/usr/local" ) ) ) { - QFileInfo etcDirInfo { "/usr/local/etc/" + m_projectName }; - if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo constDataDirInfo { "/usr/local/share/" + m_projectName }; - if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo varDataDirInfo { "/var/lib/" + m_projectName }; - if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - QFileInfo logDirInfo { "/var/log/" + m_projectName }; - if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - m_systemConfigDirectory = etcDirInfo.canonicalFilePath(); - m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath(); - m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath(); - m_systemLogDirectory = logDirInfo.canonicalFilePath(); + setupSystemDirectories( "/usr/local/etc/" + m_projectName, + "/usr/local/share/" + m_projectName, + "/var/lib/" + m_projectName, + "/var/log/" + m_projectName ); return ( HierarchyType::kUsr ); } + if ( binaryDir.startsWith( QStringLiteral( "/usr" ) ) ) { - QFileInfo etcDirInfo { "/etc/" + m_projectName }; - if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo constDataDirInfo { "/usr/share/" + m_projectName }; - if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo varDataDirInfo { "/var/lib/" + m_projectName }; - if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - QFileInfo logDirInfo { "/var/log/" + m_projectName }; - if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - m_systemConfigDirectory = etcDirInfo.canonicalFilePath(); - m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath(); - m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath(); - m_systemLogDirectory = logDirInfo.canonicalFilePath(); + setupSystemDirectories( "/etc/" + m_projectName, + "/usr/share/" + m_projectName, + "/var/lib/" + m_projectName, + "/var/log/" + m_projectName ); return ( HierarchyType::kUsr ); } @@ -127,44 +131,19 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // -V2008 if ( binaryDir.startsWith( m_homeDirectory + "/.local/bin" ) || binaryDir.startsWith( m_homeDirectory + "/bin" ) ) { - QFileInfo etcDirInfo { m_userConfigDirectory }; - if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo constDataDirInfo { m_userConstDataDirectory }; - if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo varDataDirInfo { m_userVarDataDirectory }; - if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - QFileInfo logDirInfo { m_userLogDirectory }; - if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - m_systemConfigDirectory = etcDirInfo.canonicalFilePath(); - m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath(); - m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath(); - m_systemLogDirectory = logDirInfo.canonicalFilePath(); + m_systemConfigDirectory = m_userConfigDirectory; + m_systemConstDataDirectory = m_userConstDataDirectory; + m_systemVarDataDirectory = m_userVarDataDirectory; + m_systemLogDirectory = m_userLogDirectory; return( HierarchyType::kHome ); } binaryDir.remove( binRegexp ); - - QFileInfo etcDirInfo { binaryDir + "/etc" }; - if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo constDataDirInfo { binaryDir + "/files/data" }; - if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); } - - QFileInfo varDataDirInfo { binaryDir + "/files/lib" }; - if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - QFileInfo logDirInfo { binaryDir + "/files/log" }; - if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); } - - m_systemConfigDirectory = etcDirInfo.canonicalFilePath(); - m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath(); - m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath(); - m_systemLogDirectory = logDirInfo.canonicalFilePath(); + setupSystemDirectories( binaryDir + "/etc", + binaryDir + "/files/data", + binaryDir + "/files/lib", + binaryDir + "/files/log" ); return ( HierarchyType::kDevelopment ); } // Paths::getHierarchyType @@ -205,14 +184,6 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config m_hierarchyType = getHierarchyType(); - if ( m_hierarchyType == HierarchyType::kFlat ) - { - m_systemConstDataDirectory = m_executableDirectory; - m_systemVarDataDirectory = m_executableDirectory; - m_systemConfigDirectory = m_executableDirectory; - m_systemLogDirectory = m_executableDirectory; - } - m_configFilePath = m_systemConfigDirectory + "/" + m_configFileName; return( true ); @@ -222,11 +193,17 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config MYXLIB_INLINE bool Paths::makeDefaultDirectories() { bool status = true; + QDir dir; + + if (dir.mkpath( m_userConfigDirectory )) { status = false; }; + if (dir.mkpath( m_userVarDataDirectory )) { status = false; }; + if (dir.mkpath( m_userConstDataDirectory )) { status = false; }; + if (dir.mkpath( m_userLogDirectory )) { status = false; }; + if (dir.mkpath( m_systemConfigDirectory )) { status = false; }; + if (dir.mkpath( m_systemVarDataDirectory )) { status = false; }; + if (dir.mkpath( m_systemConstDataDirectory )) { status = false; }; + if (dir.mkpath( m_systemLogDirectory )) { status = false; }; -// FIXME if ( !m_userConfigDirectory.mkpath( m_userConfigDirectory ) ) { status = false; } -// if ( !m_userVarDataDirectory.mkpath( m_userVarDataDirectory ) ) { status = false; } -// if ( !m_userConstDataDirectory.mkpath( m_userConstDataDirectory ) ) { status = false; } -// if ( !m_userLogDirectory.mkpath( m_userLogDirectory ) ) { status = false; } return( status ); } diff --git a/src/myx/filesystem/paths.hpp b/src/myx/filesystem/paths.hpp index 04ffce5..b3767aa 100644 --- a/src/myx/filesystem/paths.hpp +++ b/src/myx/filesystem/paths.hpp @@ -85,6 +85,10 @@ class Paths /// @brief Расширение для файла настройки QString m_configFileExtension; + void setupSystemDirectories( const QString& defaultEtcDirectory, + const QString& defaultConstDataDirectory, + const QString& defaultVarDataDirectory, + const QString& defaultLogDirectory ); HierarchyType getHierarchyType(); protected: From dfacad2da1cc02aa323e47f0154697342352739f Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 15 May 2020 15:54:31 +0300 Subject: [PATCH 06/41] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B9=20=D0=BF=D0=BE=D0=B8?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/filesystem/01_minimal/minimal.cpp | 20 +++++++++++++++--- src/myx/filesystem/paths.cpp | 24 +++++++++++----------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/examples/filesystem/01_minimal/minimal.cpp b/examples/filesystem/01_minimal/minimal.cpp index 77f8180..711ba72 100644 --- a/examples/filesystem/01_minimal/minimal.cpp +++ b/examples/filesystem/01_minimal/minimal.cpp @@ -29,9 +29,23 @@ int main( int argc, char** argv ) qDebug() << pathsMT.systemConfigDirectory(); paths.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) ); - paths.findConfigFile( QStringLiteral( "test" ) ); - qDebug() << paths.systemConstDataDirectory(); - qDebug() << paths.configFileName(); + + qDebug() << "executableName : " << paths.executableName(); + qDebug() << "executableFilePath : " << paths.executableFilePath(); + qDebug() << "executableDirectory : " << paths.executableDirectory(); + + qDebug() << "configFileName : " << paths.configFileName(); + qDebug() << "configFilePath : " << paths.configFilePath(); + + qDebug() << "systemConfigDirectory : " << paths.systemConfigDirectory(); + qDebug() << "systemConstDataDirectory : " << paths.systemConstDataDirectory(); + qDebug() << "systemVarDataDirectory : " << paths.systemVarDataDirectory(); + qDebug() << "systemLogDirectory : " << paths.systemLogDirectory(); + + qDebug() << "userConfigDirectory : " << paths.userConfigDirectory(); + qDebug() << "userConstDataDirectory : " << paths.userConstDataDirectory(); + qDebug() << "userVarDataDirectory : " << paths.userVarDataDirectory(); + qDebug() << "userLogDirectory : " << paths.userLogDirectory(); return( 0 ); } diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index bfa6832..3df7656 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -28,7 +28,7 @@ MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultEtcDirec const QString& defaultLogDirectory ) { QFileInfo etcDirInfo { defaultEtcDirectory }; - if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) + if ( etcDirInfo.isDir() && etcDirInfo.isReadable() ) { m_systemConfigDirectory = defaultEtcDirectory; } @@ -38,7 +38,7 @@ MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultEtcDirec } QFileInfo constDataDirInfo { defaultConstDataDirectory }; - if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) + if ( constDataDirInfo.isDir() && constDataDirInfo.isReadable() ) { m_systemConstDataDirectory = defaultConstDataDirectory; } @@ -48,7 +48,7 @@ MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultEtcDirec } QFileInfo varDataDirInfo { defaultVarDataDirectory }; - if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) + if ( varDataDirInfo.isDir() && varDataDirInfo.isWritable() ) { m_systemVarDataDirectory = defaultVarDataDirectory; } @@ -58,7 +58,7 @@ MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultEtcDirec } QFileInfo logDirInfo { defaultLogDirectory }; - if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) + if ( logDirInfo.isDir() && logDirInfo.isWritable() ) { m_systemLogDirectory = defaultLogDirectory; } @@ -195,14 +195,14 @@ MYXLIB_INLINE bool Paths::makeDefaultDirectories() bool status = true; QDir dir; - if (dir.mkpath( m_userConfigDirectory )) { status = false; }; - if (dir.mkpath( m_userVarDataDirectory )) { status = false; }; - if (dir.mkpath( m_userConstDataDirectory )) { status = false; }; - if (dir.mkpath( m_userLogDirectory )) { status = false; }; - if (dir.mkpath( m_systemConfigDirectory )) { status = false; }; - if (dir.mkpath( m_systemVarDataDirectory )) { status = false; }; - if (dir.mkpath( m_systemConstDataDirectory )) { status = false; }; - if (dir.mkpath( m_systemLogDirectory )) { status = false; }; + if ( dir.mkpath( m_userConfigDirectory ) ) { status = false; } + if ( dir.mkpath( m_userVarDataDirectory ) ) { status = false; } + if ( dir.mkpath( m_userConstDataDirectory ) ) { status = false; } + if ( dir.mkpath( m_userLogDirectory ) ) { status = false; } + if ( dir.mkpath( m_systemConfigDirectory ) ) { status = false; } + if ( dir.mkpath( m_systemVarDataDirectory ) ) { status = false; } + if ( dir.mkpath( m_systemConstDataDirectory ) ) { status = false; } + if ( dir.mkpath( m_systemLogDirectory ) ) { status = false; } return( status ); } From ab09914434475bfdfe22518dc964cf086062bbbb Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 15 May 2020 15:55:11 +0300 Subject: [PATCH 07/41] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=B8=D0=BC=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/base/endian_types.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/myx/base/endian_types.hpp b/src/myx/base/endian_types.hpp index 42639d0..7397033 100644 --- a/src/myx/base/endian_types.hpp +++ b/src/myx/base/endian_types.hpp @@ -121,7 +121,7 @@ public: friend std::istream& operator >>( std::istream& in, LittleEndianType& b ) { T val; in >> val; b = val; return( in ); } std::string toStdString() { return( std::to_string( transform( m_data ) ) ); } #ifdef QT_CORE_LIB - friend QDebug& operator <<( QDebug& out, const BigEndianType b ) { out << T( b ); return( out ); } + friend QDebug& operator <<( QDebug& out, const LittleEndianType b ) { out << T( b ); return( out ); } QString toQString() { return( QString::number( transform( m_data ) ) ); } #endif }; // class LittleEndianType From dfaa03647fae4752506dee90a4a4c4c5f27704d1 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 15 May 2020 17:38:16 +0300 Subject: [PATCH 08/41] =?UTF-8?q?=D0=92=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=B5=D0=B9?= =?UTF-8?q?=D1=88=D0=B5=D0=B3=D0=BE=20span=20=D0=B8=D0=B7=20boost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/base/span.hpp | 215 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 src/myx/base/span.hpp diff --git a/src/myx/base/span.hpp b/src/myx/base/span.hpp new file mode 100644 index 0000000..55a1454 --- /dev/null +++ b/src/myx/base/span.hpp @@ -0,0 +1,215 @@ +// +// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/beast +// + +#ifndef BOOST_BEAST_CORE_SPAN_HPP +#define BOOST_BEAST_CORE_SPAN_HPP + +#include +#include +#include +#include +#include +#include + +namespace boost { +namespace beast { + +/** A range of bytes expressed as a ContiguousContainer + + This class implements a non-owning reference to a storage + area of a certain size and having an underlying integral + type with size of 1. + + @tparam T The type pointed to by span iterators +*/ +template +class span +{ + T* data_ = nullptr; + std::size_t size_ = 0; + +public: + /// The type of value, including cv qualifiers + using element_type = T; + + /// The type of value of each span element + using value_type = typename std::remove_const::type; + + /// The type of integer used to index the span + using index_type = std::ptrdiff_t; + + /// A pointer to a span element + using pointer = T*; + + /// A reference to a span element + using reference = T&; + + /// The iterator used by the container + using iterator = pointer; + + /// The const pointer used by the container + using const_pointer = T const*; + + /// The const reference used by the container + using const_reference = T const&; + + /// The const iterator used by the container + using const_iterator = const_pointer; + + /// Constructor + span() = default; + + /// Constructor + span(span const&) = default; + + /// Assignment + span& operator=(span const&) = default; + + /** Constructor + + @param data A pointer to the beginning of the range of elements + + @param size The number of elements pointed to by `data` + */ + span(T* data, std::size_t size) + : data_(data), size_(size) + { + } + + /** Constructor + + @param container The container to construct from + */ + template::value>::type +#endif + > + explicit + span(ContiguousContainer&& container) + : data_(container.data()) + , size_(container.size()) + { + } + +#if ! BOOST_BEAST_DOXYGEN + template + explicit + span(std::basic_string& s) + : data_(&s[0]) + , size_(s.size()) + { + } + + template + explicit + span(std::basic_string const& s) + : data_(s.data()) + , size_(s.size()) + { + } +#endif + + /** Assignment + + @param container The container to assign from + */ + template +#if BOOST_BEAST_DOXYGEN + span& +#else + typename std::enable_if::value, + span&>::type +#endif + operator=(ContiguousContainer&& container) + { + data_ = container.data(); + size_ = container.size(); + return *this; + } + +#if ! BOOST_BEAST_DOXYGEN + template + span& + operator=(std::basic_string< + CharT, Traits, Allocator>& s) + { + data_ = &s[0]; + size_ = s.size(); + return *this; + } + + template + span& + operator=(std::basic_string< + CharT, Traits, Allocator> const& s) + { + data_ = s.data(); + size_ = s.size(); + return *this; + } +#endif + + /// Returns `true` if the span is empty + bool + empty() const + { + return size_ == 0; + } + + /// Returns a pointer to the beginning of the span + T* + data() const + { + return data_; + } + + /// Returns the number of elements in the span + std::size_t + size() const + { + return size_; + } + + /// Returns an iterator to the beginning of the span + const_iterator + begin() const + { + return data_; + } + + /// Returns an iterator to the beginning of the span + const_iterator + cbegin() const + { + return data_; + } + + /// Returns an iterator to one past the end of the span + const_iterator + end() const + { + return data_ + size_; + } + + /// Returns an iterator to one past the end of the span + const_iterator + cend() const + { + return data_ + size_; + } +}; + +} // beast +} // boost + +#endif From 24cb2afb8ee5b55726a5d66b2f56c709ac10cbf5 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 15 May 2020 19:03:14 +0300 Subject: [PATCH 09/41] =?UTF-8?q?endian=5Ftypes=20=D0=B8=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D1=82=20span?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/base/CMakeLists.txt | 1 + src/myx/base/endian_types.hpp | 45 +---- src/myx/base/span.hpp | 340 ++++++++++++++++++---------------- 3 files changed, 195 insertions(+), 191 deletions(-) diff --git a/src/myx/base/CMakeLists.txt b/src/myx/base/CMakeLists.txt index 5388d60..fa6b9bd 100644 --- a/src/myx/base/CMakeLists.txt +++ b/src/myx/base/CMakeLists.txt @@ -10,6 +10,7 @@ set(TRGT_cpp set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/config.hpp ${CMAKE_CURRENT_SOURCE_DIR}/limits.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/span.hpp ${CMAKE_CURRENT_SOURCE_DIR}/endian_types.hpp ${CMAKE_CURRENT_SOURCE_DIR}/enum_bitmask_operations.hpp) diff --git a/src/myx/base/endian_types.hpp b/src/myx/base/endian_types.hpp index 7397033..9573522 100644 --- a/src/myx/base/endian_types.hpp +++ b/src/myx/base/endian_types.hpp @@ -3,6 +3,8 @@ #pragma once +#include "span.hpp" + #include #include #include @@ -11,10 +13,7 @@ #include #endif -// Both LittleEndianType and BigEndianType are manufactured primitives -// that are essentially immutable except for the assignment operators. -// All math logic happens outside of the class in the native format -// and an internal set/swap method is used to store the data. +// Основа здесь: https://github.com/tatewake/endian-template/ namespace myx { @@ -24,44 +23,20 @@ template< typename T > class EndianTypesBase { protected: - #if _MSC_VER + #if defined ( _MSC_VER ) #pragma warning ( push ) #endif static T swapBytes( const T& b ) { T n; - switch ( sizeof( T ) ) - { - case 8: // 64-bit - ( reinterpret_cast< uint8_t* >( &n ) )[0] = ( reinterpret_cast< const uint8_t* >( &b ) )[7]; - ( reinterpret_cast< uint8_t* >( &n ) )[1] = ( reinterpret_cast< const uint8_t* >( &b ) )[6]; - ( reinterpret_cast< uint8_t* >( &n ) )[2] = ( reinterpret_cast< const uint8_t* >( &b ) )[5]; - ( reinterpret_cast< uint8_t* >( &n ) )[3] = ( reinterpret_cast< const uint8_t* >( &b ) )[4]; - ( reinterpret_cast< uint8_t* >( &n ) )[4] = ( reinterpret_cast< const uint8_t* >( &b ) )[3]; - ( reinterpret_cast< uint8_t* >( &n ) )[5] = ( reinterpret_cast< const uint8_t* >( &b ) )[2]; - ( reinterpret_cast< uint8_t* >( &n ) )[6] = ( reinterpret_cast< const uint8_t* >( &b ) )[1]; - ( reinterpret_cast< uint8_t* >( &n ) )[7] = ( reinterpret_cast< const uint8_t* >( &b ) )[0]; - break; - case 4: // 32-bit - ( reinterpret_cast< uint8_t* >( &n ) )[0] = ( reinterpret_cast< const uint8_t* >( &b ) )[3]; - ( reinterpret_cast< uint8_t* >( &n ) )[1] = ( reinterpret_cast< const uint8_t* >( &b ) )[2]; - ( reinterpret_cast< uint8_t* >( &n ) )[2] = ( reinterpret_cast< const uint8_t* >( &b ) )[1]; - ( reinterpret_cast< uint8_t* >( &n ) )[3] = ( reinterpret_cast< const uint8_t* >( &b ) )[0]; - break; - case 2: // 16-bit - ( reinterpret_cast< uint8_t* >( &n ) )[0] = ( reinterpret_cast< const uint8_t* >( &b ) )[1]; - ( reinterpret_cast< uint8_t* >( &n ) )[1] = ( reinterpret_cast< const uint8_t* >( &b ) )[0]; - break; - default: - assert( 0 ); // Endian swap is only defined for 2, 4, and 8-byte types - break; - } // switch - + myx::base::span< uint8_t > sn( reinterpret_cast< uint8_t* >( &n ), sizeof( T ) ); + myx::base::span< const uint8_t > sb( reinterpret_cast< const uint8_t* >( &b ), sizeof( T ) ); + std::reverse_copy( sb.begin(), sb.end(), sn.begin() ); return( n ); } // swapBytes - #if _MSC_VER + #if defined( _MSC_VER ) #pragma warning ( pop ) #endif }; // class EndianTypesBase @@ -87,7 +62,7 @@ public: // 1. Set an OE from a PE // 2. Get a PE from an OE // Storage in - explicit LittleEndianType( const T& b ) : + LittleEndianType( const T& b ) : m_data( transform( b ) ) {} template < typename U > explicit LittleEndianType( U const& b ) : @@ -148,7 +123,7 @@ public: // 1. Set an OE from a PE // 2. Get a PE from an OE // Storage in - explicit BigEndianType( const T& b ) : + BigEndianType( const T& b ) : m_data( transform( b ) ) {} template < typename U > explicit BigEndianType( U const& b ) : diff --git a/src/myx/base/span.hpp b/src/myx/base/span.hpp index 55a1454..30e626f 100644 --- a/src/myx/base/span.hpp +++ b/src/myx/base/span.hpp @@ -7,18 +7,41 @@ // Official repository: https://github.com/boostorg/beast // -#ifndef BOOST_BEAST_CORE_SPAN_HPP -#define BOOST_BEAST_CORE_SPAN_HPP +#ifndef MYX_BASE_SPAN_HPP_ +#define MYX_BASE_SPAN_HPP_ -#include -#include #include #include #include #include -namespace boost { -namespace beast { +namespace myx { + +namespace base { + +template< typename ... Ts > struct make_void { typedef void type;}; +template< typename ... Ts > using void_t = typename make_void< Ts... >::type; + +template< class T, class E, class = void > +struct is_contiguous_container : std::false_type {}; + +template< class T, class E > +struct is_contiguous_container< T, E, void_t< + decltype( + std::declval< std::size_t& >() = std::declval< T const& >().size(), + std::declval< E*& >() = std::declval< T& >().data() ), + typename std::enable_if< + std::is_same< + typename std::remove_cv< E >::type, + typename std::remove_cv< + typename std::remove_pointer< + decltype( std::declval< T& >().data() ) + >::type + >::type + >::value + >::type > > : std::true_type +{}; + /** A range of bytes expressed as a ContiguousContainer @@ -28,188 +51,193 @@ namespace beast { @tparam T The type pointed to by span iterators */ -template +template< class T > class span { - T* data_ = nullptr; - std::size_t size_ = 0; + T* data_ = nullptr; + std::size_t size_ = 0; public: - /// The type of value, including cv qualifiers - using element_type = T; + /// The type of value, including cv qualifiers + using element_type = T; - /// The type of value of each span element - using value_type = typename std::remove_const::type; + /// The type of value of each span element + using value_type = typename std::remove_const< T >::type; - /// The type of integer used to index the span - using index_type = std::ptrdiff_t; + /// The type of integer used to index the span + using index_type = std::ptrdiff_t; - /// A pointer to a span element - using pointer = T*; + /// A pointer to a span element + using pointer = T*; - /// A reference to a span element - using reference = T&; + /// A reference to a span element + using reference = T&; - /// The iterator used by the container - using iterator = pointer; + /// The iterator used by the container + using iterator = pointer; - /// The const pointer used by the container - using const_pointer = T const*; + /// The const pointer used by the container + using const_pointer = T const*; - /// The const reference used by the container - using const_reference = T const&; + /// The const reference used by the container + using const_reference = T const&; - /// The const iterator used by the container - using const_iterator = const_pointer; + /// The const iterator used by the container + using const_iterator = const_pointer; - /// Constructor - span() = default; + /// Constructor + span() = default; - /// Constructor - span(span const&) = default; + /// Constructor + span( span const& ) = default; - /// Assignment - span& operator=(span const&) = default; + /// Assignment + span& operator=( span const& ) = default; - /** Constructor + /** Constructor - @param data A pointer to the beginning of the range of elements + @param data A pointer to the beginning of the range of elements - @param size The number of elements pointed to by `data` - */ - span(T* data, std::size_t size) - : data_(data), size_(size) - { - } + @param size The number of elements pointed to by `data` + */ + span( T* data, std::size_t size ) : + data_( data ), + size_( size ) + { + } - /** Constructor - @param container The container to construct from - */ - template::value>::type -#endif - > - explicit - span(ContiguousContainer&& container) - : data_(container.data()) - , size_(container.size()) - { - } + /** Constructor -#if ! BOOST_BEAST_DOXYGEN - template - explicit - span(std::basic_string& s) - : data_(&s[0]) - , size_(s.size()) - { - } + @param container The container to construct from + */ + template< class ContiguousContainer, + class = typename std::enable_if< + is_contiguous_container< + ContiguousContainer, T >::value >::type + > + explicit + span( ContiguousContainer&& container ) : + data_( container.data() ), + size_( container.size() ) + { + } - template - explicit - span(std::basic_string const& s) - : data_(s.data()) - , size_(s.size()) - { - } -#endif - /** Assignment + template< class CharT, class Traits, class Allocator > + explicit + span( std::basic_string< CharT, Traits, Allocator >& s ) : + data_( &s[0] ), + size_( s.size() ) + { + } - @param container The container to assign from - */ - template -#if BOOST_BEAST_DOXYGEN - span& -#else - typename std::enable_if::value, - span&>::type -#endif - operator=(ContiguousContainer&& container) - { - data_ = container.data(); - size_ = container.size(); - return *this; - } -#if ! BOOST_BEAST_DOXYGEN - template - span& - operator=(std::basic_string< - CharT, Traits, Allocator>& s) - { - data_ = &s[0]; - size_ = s.size(); - return *this; - } + template< class CharT, class Traits, class Allocator > + explicit + span( std::basic_string< CharT, Traits, Allocator > const& s ) : + data_( s.data() ), + size_( s.size() ) + { + } - template - span& - operator=(std::basic_string< - CharT, Traits, Allocator> const& s) - { - data_ = s.data(); - size_ = s.size(); - return *this; - } -#endif - /// Returns `true` if the span is empty - bool - empty() const - { - return size_ == 0; - } + /** Assignment - /// Returns a pointer to the beginning of the span - T* - data() const - { - return data_; - } + @param container The container to assign from + */ + template< class ContiguousContainer > + typename std::enable_if< is_contiguous_container< + ContiguousContainer, T >::value, + span& >::type + operator=( ContiguousContainer&& container ) + { + data_ = container.data(); + size_ = container.size(); + return( *this ); + } - /// Returns the number of elements in the span - std::size_t - size() const - { - return size_; - } - /// Returns an iterator to the beginning of the span - const_iterator - begin() const - { - return data_; - } + template< class CharT, class Traits, class Allocator > + span& + operator=( std::basic_string< + CharT, Traits, Allocator >& s ) + { + data_ = &s[0]; + size_ = s.size(); + return( *this ); + } - /// Returns an iterator to the beginning of the span - const_iterator - cbegin() const - { - return data_; - } - /// Returns an iterator to one past the end of the span - const_iterator - end() const - { - return data_ + size_; - } + template< class CharT, class Traits, class Allocator > + span& + operator=( std::basic_string< + CharT, Traits, Allocator > const& s ) + { + data_ = s.data(); + size_ = s.size(); + return( *this ); + } - /// Returns an iterator to one past the end of the span - const_iterator - cend() const - { - return data_ + size_; - } -}; -} // beast -} // boost + /// Returns `true` if the span is empty + bool + empty() const + { + return( size_ == 0 ); + } -#endif + + /// Returns a pointer to the beginning of the span + T* + data() const + { + return( data_ ); + } + + + /// Returns the number of elements in the span + std::size_t + size() const + { + return( size_ ); + } + + + /// Returns an iterator to the beginning of the span + iterator + begin() const + { + return( data_ ); + } + + + /// Returns an iterator to the beginning of the span + const_iterator + cbegin() const + { + return( data_ ); + } + + + /// Returns an iterator to one past the end of the span + iterator + end() const + { + return( data_ + size_ ); + } + + + /// Returns an iterator to one past the end of the span + const_iterator + cend() const + { + return( data_ + size_ ); + } +}; // class span + +} // namespace base + +} // namespace myx + +#endif // ifndef MYX_BASE_SPAN_HPP_ From 27b3f4182aed57e54c99da4522624ad621b4c44e Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 15 May 2020 20:12:52 +0300 Subject: [PATCH 10/41] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=BC=D0=B5=D1=80=20en?= =?UTF-8?q?dian?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + examples/base/01_endian/CMakeLists.txt | 77 ++++++++++++++++++++++++++ examples/base/01_endian/endian.cpp | 25 +++++++++ examples/base/CMakeLists.txt | 1 + src/myx/base/span.hpp | 46 +++++++-------- 5 files changed, 127 insertions(+), 23 deletions(-) create mode 100644 examples/base/01_endian/CMakeLists.txt create mode 100644 examples/base/01_endian/endian.cpp create mode 100644 examples/base/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index ec249c9..a9afefa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ add_subdirectory(src/myx/qt) # Примеры if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO) + add_subdirectory(examples/base) add_subdirectory(examples/filesystem) add_subdirectory(examples/qt) endif() diff --git a/examples/base/01_endian/CMakeLists.txt b/examples/base/01_endian/CMakeLists.txt new file mode 100644 index 0000000..199646f --- /dev/null +++ b/examples/base/01_endian/CMakeLists.txt @@ -0,0 +1,77 @@ +# Название основной цели в текущем каталоге +set(TRGT example-endian-minimal) + +# Список файлов исходных текстов +set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/endian.cpp) + +if(MYXLIB_BUILD_EXAMPLES) + # Путь поиска библиотек внутри проекта + link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) + + # Цель для создания исполняемого файла + add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc}) + common_target_properties(${TRGT}) + + # Создание цели для проверки утилитой clang-tidy + add_clang_tidy_check(${TRGT} ${TRGT_cpp}) + + # Создание цели для проверки утилитой clang-analyze + add_clang_analyze_check(${TRGT} ${TRGT_cpp}) + + # Создание цели для проверки утилитой clazy + add_clazy_check(${TRGT} ${TRGT_cpp}) + + # Создание цели для проверки утилитой pvs-studio + add_pvs_check(${TRGT}) + + # Создание цели для автоматического форматирования кода + add_format_sources(${TRGT} ${TRGT_cpp}) + + # Qt5 + target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src) + target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) + + target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) + add_dependencies(${TRGT} base) + + target_link_libraries(${TRGT} base_static) + target_link_libraries(${TRGT} Qt5::Core) + target_link_libraries(${TRGT} Threads::Threads) + + # Имя выходного файла для цели + set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME endian-minimal) + + add_sanitizers(${TRGT}) + + cotire(${TRGT}) + + add_dependencies(${TRGT} create_auxilary_symlinks) + + # Правила для установки + install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + +if(MYXLIB_BUILD_EXAMPLES_HO) + # Цель для создания исполняемого файла + add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_qrc}) + common_target_properties(${TRGT}-ho) + + target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) + target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) + + add_dependencies(${TRGT}-ho base-header-only) + + target_link_libraries(${TRGT}-ho Qt5::Core) + target_link_libraries(${TRGT}-ho Threads::Threads) + + # Имя выходного файла для цели + set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME endian-minimal-ho) + + add_sanitizers(${TRGT}-ho) + cotire(${TRGT}-ho) + + add_dependencies(${TRGT}-ho create_auxilary_symlinks) + + # Правила для установки + install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/base/01_endian/endian.cpp b/examples/base/01_endian/endian.cpp new file mode 100644 index 0000000..5b86e63 --- /dev/null +++ b/examples/base/01_endian/endian.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include + +#define CMLIB_PROJECT_NAME "myxlib" + +namespace MB = myx::base; + + +int main( int argc, char** argv ) +{ + (void)argc; + (void)argv; + + beint64 bi = 1; + int64_t bii = reinterpret_cast< int64_t* >( &bi )[0]; + qDebug() << hex << bi << bii; + + leint64 li = 1; + int64_t lii = reinterpret_cast< int64_t* >( &li )[0]; + qDebug() << hex << li << lii; + + return( 0 ); +} // main diff --git a/examples/base/CMakeLists.txt b/examples/base/CMakeLists.txt new file mode 100644 index 0000000..01da3ee --- /dev/null +++ b/examples/base/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(01_endian) diff --git a/src/myx/base/span.hpp b/src/myx/base/span.hpp index 30e626f..5b32926 100644 --- a/src/myx/base/span.hpp +++ b/src/myx/base/span.hpp @@ -54,8 +54,8 @@ struct is_contiguous_container< T, E, void_t< template< class T > class span { - T* data_ = nullptr; - std::size_t size_ = 0; + T* m_data = nullptr; + std::size_t m_size = 0; public: /// The type of value, including cv qualifiers @@ -101,8 +101,8 @@ public: @param size The number of elements pointed to by `data` */ span( T* data, std::size_t size ) : - data_( data ), - size_( size ) + m_data( data ), + m_size( size ) { } @@ -118,8 +118,8 @@ public: > explicit span( ContiguousContainer&& container ) : - data_( container.data() ), - size_( container.size() ) + m_data( container.data() ), + m_size( container.size() ) { } @@ -127,8 +127,8 @@ public: template< class CharT, class Traits, class Allocator > explicit span( std::basic_string< CharT, Traits, Allocator >& s ) : - data_( &s[0] ), - size_( s.size() ) + m_data( &s[0] ), + m_size( s.size() ) { } @@ -136,8 +136,8 @@ public: template< class CharT, class Traits, class Allocator > explicit span( std::basic_string< CharT, Traits, Allocator > const& s ) : - data_( s.data() ), - size_( s.size() ) + m_data( s.data() ), + m_size( s.size() ) { } @@ -152,8 +152,8 @@ public: span& >::type operator=( ContiguousContainer&& container ) { - data_ = container.data(); - size_ = container.size(); + m_data = container.data(); + m_size = container.size(); return( *this ); } @@ -163,8 +163,8 @@ public: operator=( std::basic_string< CharT, Traits, Allocator >& s ) { - data_ = &s[0]; - size_ = s.size(); + m_data = &s[0]; + m_size = s.size(); return( *this ); } @@ -174,8 +174,8 @@ public: operator=( std::basic_string< CharT, Traits, Allocator > const& s ) { - data_ = s.data(); - size_ = s.size(); + m_data = s.data(); + m_size = s.size(); return( *this ); } @@ -184,7 +184,7 @@ public: bool empty() const { - return( size_ == 0 ); + return( m_size == 0 ); } @@ -192,7 +192,7 @@ public: T* data() const { - return( data_ ); + return( m_data ); } @@ -200,7 +200,7 @@ public: std::size_t size() const { - return( size_ ); + return( m_size ); } @@ -208,7 +208,7 @@ public: iterator begin() const { - return( data_ ); + return( m_data ); } @@ -216,7 +216,7 @@ public: const_iterator cbegin() const { - return( data_ ); + return( m_data ); } @@ -224,7 +224,7 @@ public: iterator end() const { - return( data_ + size_ ); + return( m_data + m_size ); } @@ -232,7 +232,7 @@ public: const_iterator cend() const { - return( data_ + size_ ); + return( m_data + m_size ); } }; // class span From e0c9e2f551b47d49caea79629aeea10be96b0e8b Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 15 May 2020 20:14:21 +0300 Subject: [PATCH 11/41] =?UTF-8?q?=D0=A7=D0=B8=D1=81=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/filesystem/01_minimal/minimal.cpp | 2 +- src/myx/base/endian_types.hpp | 9 +++++---- src/myx/base/span.hpp | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/filesystem/01_minimal/minimal.cpp b/examples/filesystem/01_minimal/minimal.cpp index 711ba72..a1e16f8 100644 --- a/examples/filesystem/01_minimal/minimal.cpp +++ b/examples/filesystem/01_minimal/minimal.cpp @@ -48,4 +48,4 @@ int main( int argc, char** argv ) qDebug() << "userLogDirectory : " << paths.userLogDirectory(); return( 0 ); -} +} // main diff --git a/src/myx/base/endian_types.hpp b/src/myx/base/endian_types.hpp index 9573522..bc61749 100644 --- a/src/myx/base/endian_types.hpp +++ b/src/myx/base/endian_types.hpp @@ -3,7 +3,7 @@ #pragma once -#include "span.hpp" +#include #include #include @@ -62,6 +62,7 @@ public: // 1. Set an OE from a PE // 2. Get a PE from an OE // Storage in + // NOLINTNEXTLINE LittleEndianType( const T& b ) : m_data( transform( b ) ) {} @@ -96,12 +97,11 @@ public: friend std::istream& operator >>( std::istream& in, LittleEndianType& b ) { T val; in >> val; b = val; return( in ); } std::string toStdString() { return( std::to_string( transform( m_data ) ) ); } #ifdef QT_CORE_LIB - friend QDebug& operator <<( QDebug& out, const LittleEndianType b ) { out << T( b ); return( out ); } + friend QDebug& operator <<( QDebug& out, const LittleEndianType< T > b ) { out << T( b ); return( out ); } QString toQString() { return( QString::number( transform( m_data ) ) ); } #endif }; // class LittleEndianType - template< typename T > class BigEndianType : public EndianTypesBase< T > { @@ -123,6 +123,7 @@ public: // 1. Set an OE from a PE // 2. Get a PE from an OE // Storage in + // NOLINTNEXTLINE BigEndianType( const T& b ) : m_data( transform( b ) ) {} @@ -157,7 +158,7 @@ public: friend std::istream& operator >>( std::istream& in, BigEndianType& b ) { T val; in >> val; b = val; return( in ); } std::string toStdString() { return( std::to_string( transform( m_data ) ) ); } #ifdef QT_CORE_LIB - friend QDebug& operator <<( QDebug& out, const BigEndianType b ) { out << T( b ); return( out ); } + friend QDebug& operator <<( QDebug& out, const BigEndianType< T > b ) { out << T( b ); return( out ); } QString toQString() { return( QString::number( transform( m_data ) ) ); } #endif }; // class BigEndianType diff --git a/src/myx/base/span.hpp b/src/myx/base/span.hpp index 5b32926..7533e52 100644 --- a/src/myx/base/span.hpp +++ b/src/myx/base/span.hpp @@ -19,11 +19,11 @@ namespace myx { namespace base { -template< typename ... Ts > struct make_void { typedef void type;}; -template< typename ... Ts > using void_t = typename make_void< Ts... >::type; +template< typename ... Ts > struct make_void { typedef void type;}; // NOLINT +template< typename ... Ts > using void_t = typename make_void< Ts... >::type; // NOLINT template< class T, class E, class = void > -struct is_contiguous_container : std::false_type {}; +struct is_contiguous_container : std::false_type {}; // NOLINT template< class T, class E > struct is_contiguous_container< T, E, void_t< @@ -52,7 +52,7 @@ struct is_contiguous_container< T, E, void_t< @tparam T The type pointed to by span iterators */ template< class T > -class span +class span // NOLINT { T* m_data = nullptr; std::size_t m_size = 0; From dbf287e2e9c919e77786037b6275a578784e9db5 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 15 May 2020 20:24:44 +0300 Subject: [PATCH 12/41] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/filesystem/paths.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index 3df7656..812cef7 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -69,7 +69,7 @@ MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultEtcDirec } // Paths::setupSystemDirectories -Paths::HierarchyType Paths::getHierarchyType() +MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() { QRegExp binUnityRegexp( "/s*bin/unity$" ); auto binaryDir = m_executableDirectory; From d96ee1ee570282d2dabd71236fa69c777341518f Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sun, 17 May 2020 10:57:25 +0300 Subject: [PATCH 13/41] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B0=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 4 +- .gitlab-ci/scheduled.yml | 79 ---------------------------------------- 2 files changed, 3 insertions(+), 80 deletions(-) delete mode 100644 .gitlab-ci/scheduled.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 04b4bc6..ddbd00e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,7 @@ include: - - local: .gitlab-ci/scheduled.yml + - project: 'f1x1t/gitlab-ci' + ref: master + file: 'scheduled.yml' smolensk15-nightly: extends: .scheduled-smolensk15 diff --git a/.gitlab-ci/scheduled.yml b/.gitlab-ci/scheduled.yml deleted file mode 100644 index 02d6f70..0000000 --- a/.gitlab-ci/scheduled.yml +++ /dev/null @@ -1,79 +0,0 @@ -variables: - GIT_SUBMODULE_STRATEGY: recursive - GET_SOURCES_ATTEMPTS: 10 - -.scheduled-test: - only: - refs: - - schedules - cache: - paths: ['*.status'] - before_script: - - > - if [ -f "${CI_JOB_NAME}.status" ]; then - if [ "$(cat ${CI_JOB_NAME}.status)" == "${CI_COMMIT_SHA}" ]; then - echo "=== Commit ${CI_COMMIT_SHORT_SHA} already tested with job ${CI_JOB_NAME} ===" - exit 0 - fi - fi - - > - if [ -n "${APT_UPDATE_CMD}" ]; then - ${APT_UPDATE_CMD} - fi - - > - if [ -n "${APT_INSTALL_CMD}" ]; then - ${APT_INSTALL_CMD} - fi - script: - - > - if [ -f "${CI_JOB_NAME}.status" ]; then - if [ "$(cat ${CI_JOB_NAME}.status)" == "${CI_COMMIT_SHA}" ]; then - echo "=== Commit ${CI_COMMIT_SHORT_SHA} already tested with job ${CI_JOB_NAME} ===" - exit 0 - fi - fi - - rm -f ${CI_JOB_NAME}.status - - mkdir build - - cd build - - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=_output -DCPACK_PACKAGING_INSTALL_PREFIX=/opt/rtis -DMYXLIB_BUILD_EXAMPLES_HO=ON -DMYXLIB_BUILD_LIBRARIES=ON -DMYXLIB_BUILD_EXAMPLES=ON .. - - ninja - - > - if [ -z "${CI_SHARED_ENVIRONMENT+x}" ]; then - ninja install - ninja package - ninja package_source - ninja deb - fi - - echo "${CI_COMMIT_SHA}" > "../${CI_JOB_NAME}.status" - artifacts: - paths: - - build/*.xz - - build/*.deb - when: on_success - expire_in: 10 days - - -.scheduled-smolensk15: - extends: .scheduled-test - image: smolensk15-dev - tags: ['docker'] - -.scheduled-orel212: - extends: .scheduled-test - image: orel212-dev - tags: ['docker'] - -.scheduled-bionic: - extends: .scheduled-test - image: bionic-dev - tags: ['docker'] - -.scheduled-focal: - extends: .scheduled-test - image: focal-dev - tags: ['docker'] - -.scheduled-elbrus: - extends: .scheduled-test - tags: ['elbrus'] - From 395ffb080a5a917d45ee9ea403267efdad4b918e Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Mon, 25 May 2020 17:24:27 +0300 Subject: [PATCH 14/41] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/base/enum_bitmask_operations.hpp | 45 +++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/myx/base/enum_bitmask_operations.hpp b/src/myx/base/enum_bitmask_operations.hpp index 573bac1..e7cf829 100644 --- a/src/myx/base/enum_bitmask_operations.hpp +++ b/src/myx/base/enum_bitmask_operations.hpp @@ -16,14 +16,49 @@ struct EnableBitMaskOperators }; template< typename Enum > -typename std::enable_if< EnableBitMaskOperators< Enum >::k_Enable, Enum >::type +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type +operator ~( Enum e ) +{ + using Underlying = typename std::underlying_type< Enum >::type; + return( static_cast< Enum >( ~static_cast< Underlying >( e ) ) ); +} + + +template< typename Enum > +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type operator |( Enum lhs, Enum rhs ) { using Underlying = typename std::underlying_type< Enum >::type; - return( static_cast< Enum >( - static_cast< Underlying >( lhs ) | - static_cast< Underlying >( rhs ) - ) ); + return( static_cast< Enum >( static_cast< Underlying >( lhs ) | static_cast< Underlying >( rhs ) ) ); +} + + +template< typename Enum > +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, typename std::add_lvalue_reference< Enum >::type >::type +operator |=( Enum& lhs, Enum rhs ) +{ + using Underlying = typename std::underlying_type< Enum >::type; + lhs = static_cast< Enum >( static_cast< Underlying >( lhs ) | static_cast< Underlying >( rhs ) ); + return( lhs ); +} + + +template< typename Enum > +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type +operator &( Enum lhs, Enum rhs ) +{ + using Underlying = typename std::underlying_type< Enum >::type; + return( static_cast< Enum >( static_cast< Underlying >( lhs ) & static_cast< Underlying >( rhs ) ) ); +} + + +template< typename Enum > +typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, typename std::add_lvalue_reference< Enum >::type >::type +operator &=( Enum& lhs, Enum rhs ) +{ + using Underlying = typename std::underlying_type< Enum >::type; + lhs = static_cast< Enum >( static_cast< Underlying >( lhs ) & static_cast< Underlying >( rhs ) ); + return( lhs ); } } // namespace base From b86cf01973ffc8c764dc422b278956539bb581d4 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Wed, 3 Jun 2020 12:20:59 +0300 Subject: [PATCH 15/41] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D1=91=D0=BD=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 198 ++++++++++++++++++++- examples/filesystem/01_minimal/minimal.cpp | 15 +- src/myx/filesystem/CMakeLists.txt | 10 +- src/myx/filesystem/current_executable.cpp | 41 ----- src/myx/filesystem/current_executable.hpp | 51 ------ src/myx/filesystem/paths.cpp | 46 +++-- src/myx/filesystem/paths.hpp | 7 +- src/myx/filesystem/paths_mt.cpp | 44 ----- src/myx/filesystem/paths_mt.hpp | 59 ------ 9 files changed, 240 insertions(+), 231 deletions(-) delete mode 100644 src/myx/filesystem/current_executable.cpp delete mode 100644 src/myx/filesystem/current_executable.hpp delete mode 100644 src/myx/filesystem/paths_mt.cpp delete mode 100644 src/myx/filesystem/paths_mt.hpp diff --git a/.gitignore b/.gitignore index d1e6e2a..817c82c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,200 @@ -CMakeLists.txt.user* +# Каталог для результатов сборки проекта _build + +# Каталог для тестирования установки _output -.cmake/ -*.autosave + +# Файлы настроек, редактируемые во время отладки, +# за исключением шаблонных файлов +files/etc/*.conf +!files/etc/*.example.conf + +# Каталоги, в которые разрешена запись данных во время работы программы files/lib/* files/log/* + +### +### Общие настройки для C, C++, Fortran, Qt, CMake, Ninja, LaTeX и редакторов +### + +### +### Временные файлы текстовых редакторов +### +*.bak +*.gho +*.tmp +*.dotdropbak + +### +### LyX +### +*.lyx~ +*.lyx# + +### +### Vim +### +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + + +### +### C++ +### + +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.so.* +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + + +### +### CMake +### +CMakeLists.txt.user* +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + + +### +### Ninja +### +.ninja_deps +.ninja_log + + +### +### GCC coverage testing tool files +### +*.gcno +*.gcda +*.gcov + + +### +### Qt +### +object_script.*.Release +object_script.*.Debug +*_plugin_import.cpp +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +moc_*.h +qrc_*.cpp +ui_*.h +*.qmlc +*.jsc +Makefile* +*build-* +*.qm +*.prl + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator local machine specific files for imported projects +*creator.user* + +*_qmlcache.qrc + + +### +### Latex +### +*.acn +*.acr +*.alg +*.aux +*.bbl +*.blg +*.dvi +*.fdb_latexmk +*.glg +*.glo +*.gls +*.idx +*.ilg +*.ind +*.ist +*.lof +*.log +*.lot +*.maf +*.mtc +*.mtc0 +*.nav +*.nlo +*.out +*.pdfsync +*.ps +*.snm +*.synctex.gz +*.toc +*.vrb +*.xdy +*.tdo + diff --git a/examples/filesystem/01_minimal/minimal.cpp b/examples/filesystem/01_minimal/minimal.cpp index a1e16f8..739a6db 100644 --- a/examples/filesystem/01_minimal/minimal.cpp +++ b/examples/filesystem/01_minimal/minimal.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include @@ -10,26 +9,18 @@ namespace MF = myx::filesystem; -// Переменные для защиты экземпляра класса MF::PathsMT -std::atomic< MF::PathsMT* > MF::PathsMT::sInstance; -std::mutex MF::PathsMT::sMutex; - int main( int argc, char** argv ) { (void)argc; (void)argv; QCoreApplication::setApplicationName( QStringLiteral( CMLIB_PROJECT_NAME ) ); - MF::PathsMT& pathsMT = MF::PathsMT::instance(); - MF::Paths& paths = MF::Paths::instance(); - - pathsMT.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) ); - pathsMT.findConfigFile( QStringLiteral( "test" ) ); - qDebug() << pathsMT.systemLogDirectory(); - qDebug() << pathsMT.systemConfigDirectory(); + MF::Paths& paths = MF::Paths::instance(); paths.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) ); + qDebug() << "prefixDirectory : " << paths.prefixDirectory(); + qDebug() << "executableName : " << paths.executableName(); qDebug() << "executableFilePath : " << paths.executableFilePath(); qDebug() << "executableDirectory : " << paths.executableDirectory(); diff --git a/src/myx/filesystem/CMakeLists.txt b/src/myx/filesystem/CMakeLists.txt index 283eb5e..be1f89a 100644 --- a/src/myx/filesystem/CMakeLists.txt +++ b/src/myx/filesystem/CMakeLists.txt @@ -3,16 +3,10 @@ set(TRGT filesystem) # cmake-format: off # Список файлов исходных текстов -set(TRGT_cpp - ${CMAKE_CURRENT_SOURCE_DIR}/current_executable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/paths_mt.cpp) +set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp) # Список заголовочных файлов -set(TRGT_hpp - ${CMAKE_CURRENT_SOURCE_DIR}/current_executable.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/paths.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/paths_mt.hpp) +set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.hpp) set(TRGT_headers ${TRGT_hpp}) # cmake-format: on diff --git a/src/myx/filesystem/current_executable.cpp b/src/myx/filesystem/current_executable.cpp deleted file mode 100644 index 95c8ae8..0000000 --- a/src/myx/filesystem/current_executable.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MYX_BASE_CURRENT_EXECUTABLE_CPP_ -#define MYX_BASE_CURRENT_EXECUTABLE_CPP_ - -#ifndef MYXLIB_HEADER_ONLY -#include -#else -#pragma once -#endif - -#include - -#include - -#include -#include - -namespace myx { - -namespace filesystem { - -#if !defined ( __linux__ ) -error "Class CurrentExecutable is supported only in Linux" -#endif - -MYXLIB_INLINE CurrentExecutable::CurrentExecutable() : - m_procFilePath( QStringLiteral( "/proc/self/exe" ) ) -{ - m_canonicalFilePath = m_procFilePath.canonicalFilePath(); -} - - -MYXLIB_INLINE const QFileInfo& CurrentExecutable::canonicalFilePath() const -{ - return( m_canonicalFilePath ); -} - -} // namespace filesystem - -} // namespace myx - -#endif // MYX_BASE_CURRENT_EXECUTABLE_CPP_ diff --git a/src/myx/filesystem/current_executable.hpp b/src/myx/filesystem/current_executable.hpp deleted file mode 100644 index f0c027c..0000000 --- a/src/myx/filesystem/current_executable.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/** - * @file current_executable.hpp - * @brief Параметры исполняемого файла - */ - -#ifndef MYX_FILESYSTEM_CURRENT_EXECUTABLE_HPP_ -#define MYX_FILESYSTEM_CURRENT_EXECUTABLE_HPP_ - -#pragma once - -#include - -#include -#include -#include - - -namespace myx { - -namespace filesystem { - -class CurrentExecutable -{ - /// @brief Путь к символической ссылке, указывающей на текущий исполняемый файл - QFileInfo m_procFilePath; - - /// @brief Канонический путь к текущему исполняемому файлу - QFileInfo m_canonicalFilePath; - - friend class Paths; -public: - /** - * @brief Конструктор, собирающий информацию о текущем исполняемом файле. - */ - CurrentExecutable(); - - /** - * @brief Канонический путь к текущему исполняемому файлу - */ - const QFileInfo& canonicalFilePath() const; -}; // class CurrentExecutable - -} // namespace filesystem - -} // namespace myx - -#ifdef MYXLIB_HEADER_ONLY -#include "current_executable.cpp" -#endif - -#endif // MYX_FILESYSTEM_CURRENT_EXECUTABLE_HPP_ diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index 812cef7..deec05c 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -8,7 +8,6 @@ #endif #include -#include #include @@ -22,11 +21,22 @@ namespace filesystem { MYXLIB_INLINE Paths::Paths() = default; -MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultEtcDirectory, +MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultPrefixDirectory, + const QString& defaultEtcDirectory, const QString& defaultConstDataDirectory, const QString& defaultVarDataDirectory, const QString& defaultLogDirectory ) { + QFileInfo prefixDirInfo { defaultPrefixDirectory }; + if ( prefixDirInfo.isDir() && prefixDirInfo.isReadable() ) + { + m_prefixDirectory = defaultPrefixDirectory; + } + else + { + m_prefixDirectory = "."; + } + QFileInfo etcDirInfo { defaultEtcDirectory }; if ( etcDirInfo.isDir() && etcDirInfo.isReadable() ) { @@ -77,7 +87,8 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() if ( binUnityRegexp.indexIn( binaryDir ) >= 0 ) { binaryDir.remove( binUnityRegexp ); - setupSystemDirectories( binaryDir + "/etc", + setupSystemDirectories( binaryDir, + binaryDir + "/etc", binaryDir + "/files/data", binaryDir + "/files/lib", binaryDir + "/files/log" ); @@ -88,6 +99,7 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() QRegExp binRegexp( "/s*bin$" ); if ( binRegexp.indexIn( binaryDir ) == -1 ) { + m_prefixDirectory = m_executableDirectory; m_systemConstDataDirectory = m_executableDirectory; m_systemVarDataDirectory = m_executableDirectory; m_systemConfigDirectory = m_executableDirectory; @@ -100,7 +112,8 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() if ( optRegexp.indexIn( binaryDir ) >= 0 ) { binaryDir.remove( binRegexp ); - setupSystemDirectories( binaryDir + "/etc", + setupSystemDirectories( binaryDir, + binaryDir + "/etc", binaryDir + "/files/data", binaryDir + "/files/lib", binaryDir + "/files/log" ); @@ -110,7 +123,8 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() if ( binaryDir.startsWith( QStringLiteral( "/usr/local" ) ) ) { - setupSystemDirectories( "/usr/local/etc/" + m_projectName, + setupSystemDirectories( "/usr/local", + "/usr/local/etc/" + m_projectName, "/usr/local/share/" + m_projectName, "/var/lib/" + m_projectName, "/var/log/" + m_projectName ); @@ -120,7 +134,8 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() if ( binaryDir.startsWith( QStringLiteral( "/usr" ) ) ) { - setupSystemDirectories( "/etc/" + m_projectName, + setupSystemDirectories( "/usr", + "/etc/" + m_projectName, "/usr/share/" + m_projectName, "/var/lib/" + m_projectName, "/var/log/" + m_projectName ); @@ -131,6 +146,7 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() if ( binaryDir.startsWith( m_homeDirectory + "/.local/bin" ) || binaryDir.startsWith( m_homeDirectory + "/bin" ) ) { + m_prefixDirectory = m_homeDirectory; m_systemConfigDirectory = m_userConfigDirectory; m_systemConstDataDirectory = m_userConstDataDirectory; m_systemVarDataDirectory = m_userVarDataDirectory; @@ -140,7 +156,8 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() } binaryDir.remove( binRegexp ); - setupSystemDirectories( binaryDir + "/etc", + setupSystemDirectories( binaryDir, + binaryDir + "/etc", binaryDir + "/files/data", binaryDir + "/files/lib", binaryDir + "/files/log" ); @@ -151,10 +168,11 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& configFileExtension ) { - CurrentExecutable exe; - m_executableName = exe.m_canonicalFilePath.fileName(); - m_executableFilePath = exe.m_canonicalFilePath.absoluteFilePath(); - m_executableDirectory = exe.m_canonicalFilePath.absolutePath(); + QFileInfo procSelfExe( QStringLiteral( "/proc/self/exe" ) ); + QFileInfo currentExecutable = procSelfExe.canonicalFilePath(); + m_executableName = currentExecutable.fileName(); + m_executableFilePath = currentExecutable.absoluteFilePath(); + m_executableDirectory = currentExecutable.absolutePath(); m_projectName = projectDir.isEmpty() ? m_executableName : projectDir; @@ -334,6 +352,12 @@ MYXLIB_INLINE const QString& Paths::executableDirectory() const return( m_executableDirectory ); } + +MYXLIB_INLINE const QString& Paths::prefixDirectory() const +{ + return( m_prefixDirectory ); +} + } // namespace filesystem } // namespace myx diff --git a/src/myx/filesystem/paths.hpp b/src/myx/filesystem/paths.hpp index b3767aa..802d020 100644 --- a/src/myx/filesystem/paths.hpp +++ b/src/myx/filesystem/paths.hpp @@ -9,7 +9,6 @@ #pragma once #include -#include #include #include @@ -53,6 +52,9 @@ class Paths QString m_executableFilePath; QString m_executableDirectory; + /// @brief Общий префикс для файлов проекта + QString m_prefixDirectory; + /// @brief Путь к каталогу с временными файлами QString m_tempDirectory; /// @brief Путь к домашнему каталогу текущего пользователя @@ -85,7 +87,8 @@ class Paths /// @brief Расширение для файла настройки QString m_configFileExtension; - void setupSystemDirectories( const QString& defaultEtcDirectory, + void setupSystemDirectories( const QString& defaultPrefixDirectory, + const QString& defaultEtcDirectory, const QString& defaultConstDataDirectory, const QString& defaultVarDataDirectory, const QString& defaultLogDirectory ); diff --git a/src/myx/filesystem/paths_mt.cpp b/src/myx/filesystem/paths_mt.cpp deleted file mode 100644 index b1adf3c..0000000 --- a/src/myx/filesystem/paths_mt.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef MYX_BASE_PATHS_MT_CPP_ -#define MYX_BASE_PATHS_MT_CPP_ - -#ifndef MYXLIB_HEADER_ONLY -#include -#else -#pragma once -#endif - -#include -#include - -#include - -#include -#include - -namespace myx { - -namespace filesystem { - -MYXLIB_INLINE PathsMT::PathsMT() = default; - -MYXLIB_INLINE PathsMT& PathsMT::instance() -{ - volatile PathsMT* localInstance = sInstance.load( std::memory_order_acquire ); - if ( localInstance == nullptr ) - { - std::lock_guard< std::mutex > myLock( sMutex ); - localInstance = sInstance.load( std::memory_order_relaxed ); - if ( localInstance == nullptr ) // -V1036 - { - localInstance = new PathsMT(); - sInstance.store( const_cast< PathsMT* >( localInstance ), std::memory_order_release ); // NOLINT - } - } - return( const_cast< PathsMT& >( *localInstance ) ); // NOLINT -} - -} // namespace filesystem - -} // namespace myx - -#endif // MYX_BASE_PATHS_MT_CPP_ diff --git a/src/myx/filesystem/paths_mt.hpp b/src/myx/filesystem/paths_mt.hpp deleted file mode 100644 index 3247c75..0000000 --- a/src/myx/filesystem/paths_mt.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @file paths.hpp - * @brief Стандартные пути к каталогам и файлам - */ - -#ifndef MYX_FILESYSTEM_PATHS_MT_HPP_ -#define MYX_FILESYSTEM_PATHS_MT_HPP_ - -#pragma once - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -namespace myx { - -namespace filesystem { - -/// @brief Потокобезопасная версия класса myx::filesystem::Paths -class PathsMT : public Paths -{ - PathsMT(); - ~PathsMT() = default; - - static std::atomic< PathsMT* > sInstance; - static std::mutex sMutex; - - -public: - PathsMT( const PathsMT& ) = delete; - PathsMT& operator=( const PathsMT& ) = delete; - PathsMT( PathsMT&& ) = delete; - PathsMT& operator=( PathsMT&& ) = delete; - - /** - * @brief getInstance - * @return Уникальный экземпляр класса PathsMT - */ - static PathsMT& instance(); -}; // class PathsMT - -} // namespace filesystem - -} // namespace myx - -#ifdef MYXLIB_HEADER_ONLY -#include "paths_mt.cpp" -#endif - -#endif // MYX_FILESYSTEM_PATHS_MT_HPP_ From 57118ea2bb5798ba3657cc13e26e1ac123d13638 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Mon, 15 Jun 2020 15:56:47 +0300 Subject: [PATCH 16/41] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/cmlib | 2 +- cmake/etc/uncrustify | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/cmlib b/cmake/cmlib index 23be253..a6bb734 160000 --- a/cmake/cmlib +++ b/cmake/cmlib @@ -1 +1 @@ -Subproject commit 23be253a8db87d51c25a67ffc41c452e5b8f58d5 +Subproject commit a6bb734f49ab221add4314946127af0832e63dbc diff --git a/cmake/etc/uncrustify b/cmake/etc/uncrustify index 7324d80..7424dcf 160000 --- a/cmake/etc/uncrustify +++ b/cmake/etc/uncrustify @@ -1 +1 @@ -Subproject commit 7324d80f3dc97ee9a1da464e9ed7389e00fff880 +Subproject commit 7424dcf8eb3e2cc0a6c21936b4f6c97db472d406 From 5f3831c9350c76b36e210382bcd2ae9152d8bc00 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Wed, 24 Jun 2020 09:44:19 +0300 Subject: [PATCH 17/41] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0?= =?UTF-8?q?=D1=89=D0=B0=D0=B5=D0=BC=D0=BE=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/filesystem/paths.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index deec05c..3aded82 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -129,7 +129,7 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() "/var/lib/" + m_projectName, "/var/log/" + m_projectName ); - return ( HierarchyType::kUsr ); + return ( HierarchyType::kUsrLocal ); } if ( binaryDir.startsWith( QStringLiteral( "/usr" ) ) ) From 05570031177fbc3c077f9ba9fb6c2a5e036c8ff5 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 25 Jun 2020 04:22:30 +0300 Subject: [PATCH 18/41] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=D0=B0?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=A1=D0=B8=D1=80=D0=B5=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/filesystem/paths.cpp | 11 +++++++++++ src/myx/filesystem/paths.hpp | 10 ++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index 3aded82..d007d7f 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -121,6 +121,17 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() return ( HierarchyType::kOpt ); } + if ( binaryDir.startsWith( QStringLiteral( "/usr/local/rtis" ) ) ) + { + setupSystemDirectories( "/usr/local/rtis", + "/usr/local/rtis/etc/" + m_projectName, + "/usr/local/rtis/share/" + m_projectName, + "/usr/local/rtis/lib/" + m_projectName, + "/usr/local/rtis/log/" + m_projectName ); + + return ( HierarchyType::kUsrLocalRtis ); + } + if ( binaryDir.startsWith( QStringLiteral( "/usr/local" ) ) ) { setupSystemDirectories( "/usr/local", diff --git a/src/myx/filesystem/paths.hpp b/src/myx/filesystem/paths.hpp index 802d020..17effe8 100644 --- a/src/myx/filesystem/paths.hpp +++ b/src/myx/filesystem/paths.hpp @@ -33,13 +33,15 @@ class Paths /// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /opt kOpt = 0x02, /// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr - kUsr = 0x04, + kUsr = 0x03, /// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local - kUsrLocal = 0x08, + kUsrLocal = 0x04, + /// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local/rtis (используется для работ в проекте Сирена) + kUsrLocalRtis = 0x05, /// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /home - kHome = 0x10, + kHome = 0x06, /// @brief Исполняемый файл и сопутствующие каталоги находятся в каталоге программного проекта - kDevelopment = 0x20 + kDevelopment = 0x07 }; /// @brief Тип расположения файлов по каталогам From 44cd25464f2c565fb7e16bf04961da9278e57f31 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sat, 27 Jun 2020 06:36:31 +0300 Subject: [PATCH 19/41] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/cmlib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/cmlib b/cmake/cmlib index a6bb734..186d67c 160000 --- a/cmake/cmlib +++ b/cmake/cmlib @@ -1 +1 @@ -Subproject commit a6bb734f49ab221add4314946127af0832e63dbc +Subproject commit 186d67c4bbc2fa91ecfd837d753631610aff0b1d From ca83f98484a7496ee7df420786aabe1fe744c4df Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sat, 27 Jun 2020 10:04:56 +0300 Subject: [PATCH 20/41] PosixSignalWatcher --- .../qt/02_posix-signal-watcher/CMakeLists.txt | 83 +++++++++++ .../posix_signal_watcher.cpp | 21 +++ examples/qt/CMakeLists.txt | 1 + src/myx/qt/CMakeLists.txt | 26 +++- src/myx/qt/posix_signal_watcher.cpp | 136 ++++++++++++++++++ src/myx/qt/posix_signal_watcher.hpp | 55 +++++++ src/myx/qt/posix_signal_watcher_p.hpp | 62 ++++++++ 7 files changed, 378 insertions(+), 6 deletions(-) create mode 100644 examples/qt/02_posix-signal-watcher/CMakeLists.txt create mode 100644 examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp create mode 100644 src/myx/qt/posix_signal_watcher.cpp create mode 100644 src/myx/qt/posix_signal_watcher.hpp create mode 100644 src/myx/qt/posix_signal_watcher_p.hpp diff --git a/examples/qt/02_posix-signal-watcher/CMakeLists.txt b/examples/qt/02_posix-signal-watcher/CMakeLists.txt new file mode 100644 index 0000000..88d72d2 --- /dev/null +++ b/examples/qt/02_posix-signal-watcher/CMakeLists.txt @@ -0,0 +1,83 @@ +# Название основной цели в текущем каталоге +set(TRGT example-qt-posix-signal-watcher) + +# Список файлов исходных текстов +set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher.cpp) + +if(MYXLIB_BUILD_EXAMPLES) + # Путь поиска библиотек внутри проекта + link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) + + # Цель для создания исполняемого файла + add_executable(${TRGT} ${TRGT_cpp}) + common_target_properties(${TRGT}) + + # Создание цели для проверки утилитой clang-tidy + add_clang_tidy_check(${TRGT} ${TRGT_cpp}) + + # Создание цели для проверки утилитой clang-analyze + add_clang_analyze_check(${TRGT} ${TRGT_cpp}) + + # Создание цели для проверки утилитой clazy + add_clazy_check(${TRGT} ${TRGT_cpp}) + + # Создание цели для проверки утилитой pvs-studio + add_pvs_check(${TRGT}) + + # Создание цели для автоматического форматирования кода + add_format_sources(${TRGT} ${TRGT_cpp}) + + # Qt5 + target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src) + target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) + + target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) + add_dependencies(${TRGT} base qt) + + target_link_libraries(${TRGT} base_static qt_static) + + target_link_libraries(${TRGT} Qt5::Core) + target_link_libraries(${TRGT} Threads::Threads) + + # Имя выходного файла для цели + set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME qt-posix-signal-watcher) + + add_sanitizers(${TRGT}) + + cotire(${TRGT}) + + add_dependencies(${TRGT} create_auxilary_symlinks) + + # Правила для установки + install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() + +if(MYXLIB_BUILD_EXAMPLES_HO) + set(TRGT_moc_hpp + ${CMAKE_SOURCE_DIR}/src/myx/qt/posix_signal_watcher.hpp + ${CMAKE_SOURCE_DIR}/src/myx/qt/posix_signal_watcher_p.hpp) + qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_hpp}) + + # Цель для создания исполняемого файла + add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_moc_cpp}) + common_target_properties(${TRGT}-ho) + + target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) + target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) + + add_dependencies(${TRGT}-ho base-header-only qt-header-only) + + target_link_libraries(${TRGT}-ho Qt5::Core) + target_link_libraries(${TRGT}-ho Threads::Threads) + + # Имя выходного файла для цели + set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME qt-posix-signal-watcher-ho) + + add_sanitizers(${TRGT}-ho) + cotire(${TRGT}-ho) + + add_dependencies(${TRGT}-ho create_auxilary_symlinks) + + # Правила для установки + install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endif() diff --git a/examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp b/examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp new file mode 100644 index 0000000..9fb9ef6 --- /dev/null +++ b/examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp @@ -0,0 +1,21 @@ +#include + +#include +#include + +namespace MQ = myx::qt; + +int main( int argc, char* argv[] ) +{ + QCoreApplication app( argc, argv ); + qDebug() << "Hello from process" << QCoreApplication::applicationPid(); + + MQ::PosixSignalWatcher sigwatch; + sigwatch.watchForSignal( SIGINT ); + sigwatch.watchForSignal( SIGTERM ); + QObject::connect( &sigwatch, &MQ::PosixSignalWatcher::posixSignal, &app, &QCoreApplication::quit ); + + int exitcode = app.exec(); + qDebug() << "Goodbye"; + return( exitcode ); +} diff --git a/examples/qt/CMakeLists.txt b/examples/qt/CMakeLists.txt index ff85cdb..b222784 100644 --- a/examples/qt/CMakeLists.txt +++ b/examples/qt/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(01_translators) +add_subdirectory(02_posix-signal-watcher) diff --git a/src/myx/qt/CMakeLists.txt b/src/myx/qt/CMakeLists.txt index e501637..2582397 100644 --- a/src/myx/qt/CMakeLists.txt +++ b/src/myx/qt/CMakeLists.txt @@ -4,23 +4,36 @@ set(TRGT qt) # cmake-format: off # Список файлов исходных текстов set(TRGT_cpp - ${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp) + ${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp + ) + +set(TRGT_moc_hpp + ${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher.hpp + ) + +set(TRGT_moc_private_hpp + ${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher_p.hpp + ) -# Список заголовочных файлов (используется для установки) set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/backports.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/translators.hpp) + ${CMAKE_CURRENT_SOURCE_DIR}/translators.hpp + ) -set(TRGT_headers ${TRGT_hpp}) +set(TRGT_headers ${TRGT_moc_hpp} ${TRGT_hpp}) # cmake-format: on +qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_private_hpp} ${TRGT_moc_hpp}) + add_library(${TRGT}-header-only INTERFACE) target_include_directories( ${TRGT}-header-only SYSTEM INTERFACE "$" + "$" "$") if(MYXLIB_BUILD_LIBRARIES) - add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) + add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_moc_cpp} ${TRGT_moc_private_hpp} ${TRGT_headers}) common_target_properties(${TRGT}) # Создание цели для проверки утилитой clang-tidy @@ -36,11 +49,12 @@ if(MYXLIB_BUILD_LIBRARIES) add_pvs_check(${TRGT}) # Создание цели для автоматического форматирования кода - add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers} ${TRGT_moc_private_hpp}) target_compile_definitions(${TRGT} PUBLIC MYXLIB_BUILD_LIBRARIES) target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) + target_include_directories(${TRGT} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) cotire(${TRGT}) install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp new file mode 100644 index 0000000..5688572 --- /dev/null +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -0,0 +1,136 @@ +#ifndef MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ +#define MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ + +#include + +#ifndef MYXLIB_HEADER_ONLY +#include +#include +#else +#pragma once +#endif + + +namespace myx { + +namespace qt { + +int PosixSignalWatcherPrivate::m_sockpair[2] = {0, 0}; + +PosixSignalWatcherPrivate::~PosixSignalWatcherPrivate() = default; + +PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : + q_ptr( q ) +{ + #if MYX_QT_HAS_POSIX_SIGNALS + // Create socket pair + if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, m_sockpair ) ) + { + qDebug() << "PosixSignalWatcher: socketpair: " << ::strerror( errno ); + return; + } + #endif + + // Create a notifier for the read end of the pair + m_notifier.reset( new QSocketNotifier( m_sockpair[1], QSocketNotifier::Read ) ); + + + // Called when the signal handler has written to the socket pair. + // Emits the Posix signal as a Qt signal. + connect( m_notifier.get(), &QSocketNotifier::activated, q, [this]( int sockfd ) { + Q_Q( PosixSignalWatcher ); + + int signal = 0; + (void)::read( sockfd, &signal, sizeof( signal ) ); + qDebug() << "Caught signal: " << ::strsignal( signal ); + Q_EMIT q->posixSignal( signal ); + } ); + + + m_notifier->setEnabled( true ); +} + + +/*! + * Registers a handler for the given Posix \a signal. The handler will write to + * a socket pair, the other end of which is connected to a QSocketNotifier. + * This provides a way to break out of the asynchronous context from which the + * signal handler is called and back into the Qt event loop. + */ +void PosixSignalWatcherPrivate::watchForSignal( int signal ) +{ + if ( m_watchedSignals.contains( signal ) ) + { + qDebug() << "Already watching for signal " << signal; + return; + } + + #if MYX_QT_HAS_POSIX_SIGNALS + // Register a sigaction which will write to the socket pair + struct sigaction sigact; + sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; + sigact.sa_flags = 0; + sigemptyset( &sigact.sa_mask ); + sigact.sa_flags |= SA_RESTART; + if ( ::sigaction( signal, &sigact, nullptr ) ) + { + qDebug() << "PosixSignalWatcher: sigaction: " << ::strerror( errno ); + return; + } + #endif + + m_watchedSignals.append( signal ); +} // PosixSignalWatcherPrivate::watchForSignal + + +/*! + * Called when a Posix \a signal is received. Write to the socket to wake up the + * QSocketNotifier. + */ +MYXLIB_INLINE void PosixSignalWatcherPrivate::signalHandler( int signal ) +{ + (void)::write( m_sockpair[0], &signal, sizeof( signal ) ); +} + + +/*! + * Create a new PosixSignalWatcher as a child of the given \a parent. + */ +MYXLIB_INLINE PosixSignalWatcher::PosixSignalWatcher( QObject* parent ) : + QObject( parent ), + d_ptr ( new PosixSignalWatcherPrivate( this ) ) +{ +} + + +MYXLIB_INLINE PosixSignalWatcher::~PosixSignalWatcher() = default; + +/*! + * Register a signal handler for the given \a signal. + * + * After calling this method you can \c connect() to the POSIXSignal() Qt signal + * to be notified when the Posix signal is received. + */ +MYXLIB_INLINE void PosixSignalWatcher::watchForSignal( int signal ) +{ + Q_D( PosixSignalWatcher ); + d->watchForSignal( signal ); +} + + +/*! + * \fn void PosixSignalWatcher::posixSignal(int signal) + * Emitted when the given Posix \a signal is received. + * + * watchForSignal() must be called for each Posix signal that you want to receive + * via the POSIXSignal() Qt signal. If a watcher is watching multiple signals, + * POSIXSignal() will be emitted whenever *any* of the watched Posix signals are + * received, and the \a signal argument can be inspected to find out which one + * was actually received. + */ + +} // namespace qt + +} // namespace myx + +#endif // ifndef MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ diff --git a/src/myx/qt/posix_signal_watcher.hpp b/src/myx/qt/posix_signal_watcher.hpp new file mode 100644 index 0000000..511bca5 --- /dev/null +++ b/src/myx/qt/posix_signal_watcher.hpp @@ -0,0 +1,55 @@ +#ifndef MYX_QT_POSIX_SIGNAL_WATCHER_HPP_ +#define MYX_QT_POSIX_SIGNAL_WATCHER_HPP_ + +#pragma once + +#include + +#include + +#include + +namespace myx { + +namespace qt { + +class PosixSignalWatcherPrivate; + +#if defined( Q_OS_WIN ) +const int SIGINT = 2; +const int SIGTERM = 15; +#endif + + +/*! + * \brief The PosixSignalWatcher class converts Posix signals to Qt signals. + * + * To watch for a given signal, e.g. \c SIGINT, call \c watchForSignal(SIGINT) + * and \c connect() your handler to posixSignal(). + */ +class PosixSignalWatcher : public QObject +{ + Q_OBJECT + +public: + explicit PosixSignalWatcher( QObject* parent = nullptr ); + ~PosixSignalWatcher(); + + void watchForSignal( int signal ); + Q_SIGNAL void posixSignal( int signal ); + +private: + PosixSignalWatcherPrivate* const d_ptr = nullptr; + Q_DECLARE_PRIVATE( PosixSignalWatcher ) +}; // class PosixSignalWatcher + +} // namespace qt + +} // namespace myx + +#ifdef MYXLIB_HEADER_ONLY +#include "posix_signal_watcher_p.hpp" +#include "posix_signal_watcher.cpp" +#endif + +#endif // ifndef MYX_QT_POSIX_SIGNAL_WATCHER_HPP_ diff --git a/src/myx/qt/posix_signal_watcher_p.hpp b/src/myx/qt/posix_signal_watcher_p.hpp new file mode 100644 index 0000000..067f94c --- /dev/null +++ b/src/myx/qt/posix_signal_watcher_p.hpp @@ -0,0 +1,62 @@ +#ifndef MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_ +#define MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_ + +#include + +#include + +#include +#include +#include +#include + +#include + +#ifdef Q_OS_WIN +#define MYX_QT_HAS_POSIX_SIGNALS 0 +#else +#define MYX_QT_HAS_POSIX_SIGNALS 1 +#endif + +#if MYX_QT_HAS_POSIX_SIGNALS +#include +#include +#include +#include +#endif + +namespace myx { + +namespace qt { + +/*! + * \brief The PosixSignalWatcherPrivate class implements the back-end signal + * handling for the PosixSignalWatcher. + * + * \see http://qt-project.org/doc/qt-5.0/qtdoc/POSIX-signals.html + */ +class PosixSignalWatcherPrivate : public QObject +{ + Q_OBJECT + +public: + PosixSignalWatcherPrivate( PosixSignalWatcher* q ); + ~PosixSignalWatcherPrivate(); + + void watchForSignal( int signal ); + static void signalHandler( int signal ); + +private: + PosixSignalWatcher* const q_ptr = nullptr; + Q_DECLARE_PUBLIC( PosixSignalWatcher ) + + static int m_sockpair[2]; + std::unique_ptr< QSocketNotifier > m_notifier; + QList< int > m_watchedSignals; +}; // class PosixSignalWatcherPrivate + +} // namespace qt + +} // namespace myx + +#endif // ifndef MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_ From a4d00ed80b939acdc41ba4818edb85cec2bb925f Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sun, 28 Jun 2020 09:52:03 +0300 Subject: [PATCH 21/41] =?UTF-8?q?=D0=91=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D0=B0=20=D1=82=D1=80=D0=B5=D0=B1=D1=83=D0=B5?= =?UTF-8?q?=D1=82=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B8=20=D0=B2=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=20(=D0=B8=D0=B7-=D0=B7=D0=B0=20moc)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 10 ++-- examples/base/01_endian/CMakeLists.txt | 27 +--------- examples/base/01_endian/endian.cpp | 2 - .../{01_minimal => 01_paths}/CMakeLists.txt | 29 +--------- .../minimal.cpp => 01_paths/paths.cpp} | 0 examples/filesystem/CMakeLists.txt | 2 +- examples/qt/01_translators/CMakeLists.txt | 26 --------- .../qt/02_posix-signal-watcher/CMakeLists.txt | 30 ----------- src/myx/base/CMakeLists.txt | 42 ++++++--------- src/myx/base/config.cpp | 9 ---- src/myx/base/config.hpp | 12 ----- src/myx/base/endian_types.hpp | 8 +-- src/myx/filesystem/CMakeLists.txt | 50 +++++++---------- src/myx/filesystem/paths.cpp | 7 +-- src/myx/filesystem/paths.hpp | 4 -- src/myx/qt/CMakeLists.txt | 53 ++++++++----------- src/myx/qt/posix_signal_watcher.cpp | 21 +++----- src/myx/qt/posix_signal_watcher.hpp | 7 +-- src/myx/qt/posix_signal_watcher_p.hpp | 7 +-- src/myx/qt/translators.cpp | 5 -- src/myx/qt/translators.hpp | 4 -- 21 files changed, 84 insertions(+), 271 deletions(-) rename examples/filesystem/{01_minimal => 01_paths}/CMakeLists.txt (65%) rename examples/filesystem/{01_minimal/minimal.cpp => 01_paths/paths.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9afefa..ee9cf59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,11 +23,7 @@ endif() include(CMLibCommon) -option(MYXLIB_BUILD_LIBRARIES "Build libraries" OFF) -if(MYXLIB_BUILD_LIBRARIES) - option(MYXLIB_BUILD_EXAMPLES "Build examples" OFF) -endif() -option(MYXLIB_BUILD_EXAMPLES_HO "Build examples using header only version" OFF) +option(MYXLIB_BUILD_EXAMPLES "Build examples" OFF) # Поиск библиотек с помощью pkgconfig find_package(PkgConfig REQUIRED) @@ -45,10 +41,12 @@ add_subdirectory(src/myx/filesystem) add_subdirectory(src/myx/qt) # Примеры -if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO) +if(MYXLIB_BUILD_EXAMPLES) add_subdirectory(examples/base) add_subdirectory(examples/filesystem) add_subdirectory(examples/qt) + add_custom_target(examples example-base-endian example-filesystem-paths example-qt-tranlators + example-qt-posix-signal-watcher) endif() # Документация diff --git a/examples/base/01_endian/CMakeLists.txt b/examples/base/01_endian/CMakeLists.txt index 199646f..cc3a06e 100644 --- a/examples/base/01_endian/CMakeLists.txt +++ b/examples/base/01_endian/CMakeLists.txt @@ -1,5 +1,5 @@ # Название основной цели в текущем каталоге -set(TRGT example-endian-minimal) +set(TRGT example-base-endian) # Список файлов исходных текстов set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/endian.cpp) @@ -50,28 +50,3 @@ if(MYXLIB_BUILD_EXAMPLES) # Правила для установки install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - -if(MYXLIB_BUILD_EXAMPLES_HO) - # Цель для создания исполняемого файла - add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_qrc}) - common_target_properties(${TRGT}-ho) - - target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - - add_dependencies(${TRGT}-ho base-header-only) - - target_link_libraries(${TRGT}-ho Qt5::Core) - target_link_libraries(${TRGT}-ho Threads::Threads) - - # Имя выходного файла для цели - set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME endian-minimal-ho) - - add_sanitizers(${TRGT}-ho) - cotire(${TRGT}-ho) - - add_dependencies(${TRGT}-ho create_auxilary_symlinks) - - # Правила для установки - install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() diff --git a/examples/base/01_endian/endian.cpp b/examples/base/01_endian/endian.cpp index 5b86e63..a4cc260 100644 --- a/examples/base/01_endian/endian.cpp +++ b/examples/base/01_endian/endian.cpp @@ -5,8 +5,6 @@ #define CMLIB_PROJECT_NAME "myxlib" -namespace MB = myx::base; - int main( int argc, char** argv ) { diff --git a/examples/filesystem/01_minimal/CMakeLists.txt b/examples/filesystem/01_paths/CMakeLists.txt similarity index 65% rename from examples/filesystem/01_minimal/CMakeLists.txt rename to examples/filesystem/01_paths/CMakeLists.txt index f4d533a..2062f33 100644 --- a/examples/filesystem/01_minimal/CMakeLists.txt +++ b/examples/filesystem/01_paths/CMakeLists.txt @@ -1,8 +1,8 @@ # Название основной цели в текущем каталоге -set(TRGT example-filesystem-minimal) +set(TRGT example-filesystem-paths) # Список файлов исходных текстов -set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/minimal.cpp) +set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp) if(MYXLIB_BUILD_EXAMPLES) # Путь поиска библиотек внутри проекта @@ -50,28 +50,3 @@ if(MYXLIB_BUILD_EXAMPLES) # Правила для установки install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - -if(MYXLIB_BUILD_EXAMPLES_HO) - # Цель для создания исполняемого файла - add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_qrc}) - common_target_properties(${TRGT}-ho) - - target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - - add_dependencies(${TRGT}-ho base-header-only filesystem-header-only) - - target_link_libraries(${TRGT}-ho Qt5::Core) - target_link_libraries(${TRGT}-ho Threads::Threads) - - # Имя выходного файла для цели - set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME filesystem-minimal-ho) - - add_sanitizers(${TRGT}-ho) - cotire(${TRGT}-ho) - - add_dependencies(${TRGT}-ho create_auxilary_symlinks) - - # Правила для установки - install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() diff --git a/examples/filesystem/01_minimal/minimal.cpp b/examples/filesystem/01_paths/paths.cpp similarity index 100% rename from examples/filesystem/01_minimal/minimal.cpp rename to examples/filesystem/01_paths/paths.cpp diff --git a/examples/filesystem/CMakeLists.txt b/examples/filesystem/CMakeLists.txt index 5e9d165..1254222 100644 --- a/examples/filesystem/CMakeLists.txt +++ b/examples/filesystem/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(01_minimal) +add_subdirectory(01_paths) diff --git a/examples/qt/01_translators/CMakeLists.txt b/examples/qt/01_translators/CMakeLists.txt index 59af417..c02441f 100644 --- a/examples/qt/01_translators/CMakeLists.txt +++ b/examples/qt/01_translators/CMakeLists.txt @@ -11,7 +11,6 @@ qt5_translation( LANGUAGES ru_RU) if(MYXLIB_BUILD_EXAMPLES) - # Путь поиска библиотек внутри проекта link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) @@ -58,28 +57,3 @@ if(MYXLIB_BUILD_EXAMPLES) # Правила для установки install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - -if(MYXLIB_BUILD_EXAMPLES_HO) - # Цель для создания исполняемого файла - add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_qrc}) - common_target_properties(${TRGT}-ho) - - target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - - add_dependencies(${TRGT}-ho base-header-only qt-header-only) - - target_link_libraries(${TRGT}-ho Qt5::Core) - target_link_libraries(${TRGT}-ho Threads::Threads) - - # Имя выходного файла для цели - set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME qt-translators-ho) - - add_sanitizers(${TRGT}-ho) - cotire(${TRGT}-ho) - - add_dependencies(${TRGT}-ho create_auxilary_symlinks) - - # Правила для установки - install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() diff --git a/examples/qt/02_posix-signal-watcher/CMakeLists.txt b/examples/qt/02_posix-signal-watcher/CMakeLists.txt index 88d72d2..1caeae2 100644 --- a/examples/qt/02_posix-signal-watcher/CMakeLists.txt +++ b/examples/qt/02_posix-signal-watcher/CMakeLists.txt @@ -51,33 +51,3 @@ if(MYXLIB_BUILD_EXAMPLES) # Правила для установки install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - -if(MYXLIB_BUILD_EXAMPLES_HO) - set(TRGT_moc_hpp - ${CMAKE_SOURCE_DIR}/src/myx/qt/posix_signal_watcher.hpp - ${CMAKE_SOURCE_DIR}/src/myx/qt/posix_signal_watcher_p.hpp) - qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_hpp}) - - # Цель для создания исполняемого файла - add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_moc_cpp}) - common_target_properties(${TRGT}-ho) - - target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - - add_dependencies(${TRGT}-ho base-header-only qt-header-only) - - target_link_libraries(${TRGT}-ho Qt5::Core) - target_link_libraries(${TRGT}-ho Threads::Threads) - - # Имя выходного файла для цели - set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME qt-posix-signal-watcher-ho) - - add_sanitizers(${TRGT}-ho) - cotire(${TRGT}-ho) - - add_dependencies(${TRGT}-ho create_auxilary_symlinks) - - # Правила для установки - install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() diff --git a/src/myx/base/CMakeLists.txt b/src/myx/base/CMakeLists.txt index fa6b9bd..42627d7 100644 --- a/src/myx/base/CMakeLists.txt +++ b/src/myx/base/CMakeLists.txt @@ -17,39 +17,29 @@ set(TRGT_hpp set(TRGT_headers ${TRGT_hpp}) # cmake-format: on -add_library(${TRGT}-header-only INTERFACE) -target_include_directories( - ${TRGT}-header-only SYSTEM INTERFACE "$" - "$") +add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) +common_target_properties(${TRGT}) -if(MYXLIB_BUILD_LIBRARIES) - add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) - common_target_properties(${TRGT}) +# Создание цели для проверки утилитой clang-tidy +add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clang-tidy - add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой clang-analyze +add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clang-analyze - add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой clazy +add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clazy - add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой pvs-studio +add_pvs_check(${TRGT}) - # Создание цели для проверки утилитой pvs-studio - add_pvs_check(${TRGT}) +# Создание цели для автоматического форматирования кода +add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для автоматического форматирования кода - add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_compile_definitions(${TRGT} PUBLIC MYXLIB_BUILD_LIBRARIES) - target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - - install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - if(BUILD_SHARED_LIBS) - install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() -else() - install(FILES ${TRGT_cpp} COMPONENT base-dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) +install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +if(BUILD_SHARED_LIBS) + install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES}) diff --git a/src/myx/base/config.cpp b/src/myx/base/config.cpp index c35efbf..3e8bcfb 100644 --- a/src/myx/base/config.cpp +++ b/src/myx/base/config.cpp @@ -1,10 +1 @@ -#ifndef MYX_BASE_CONFIG_CPP_ -#define MYX_BASE_CONFIG_CPP_ - -#ifndef MYXLIB_HEADER_ONLY #include -#else -#pragma once -#endif - -#endif // MYX_BASE_CONFIG_CPP_ diff --git a/src/myx/base/config.hpp b/src/myx/base/config.hpp index 0473bfe..c179cdf 100644 --- a/src/myx/base/config.hpp +++ b/src/myx/base/config.hpp @@ -3,9 +3,6 @@ #pragma once -#ifdef MYXLIB_BUILD_LIBRARIES -#undef MYXLIB_HEADER_ONLY - #if defined( _WIN32 ) && defined( MYXLIB_SHARED_LIB ) #ifdef myxlib_EXPORTS #define MYXLIB_API __declspec( dllexport ) @@ -16,14 +13,5 @@ #define MYXLIB_API #endif #define MYXLIB_INLINE -#else -#define MYXLIB_HEADER_ONLY -#define MYXLIB_API -#define MYXLIB_INLINE inline -#endif // ifdef MYXLIB_BUILD_LIBRARIES - -#ifdef MYXLIB_HEADER_ONLY -#include "config.cpp" -#endif #endif // MYX_BASE_CONFIG_HPP_ diff --git a/src/myx/base/endian_types.hpp b/src/myx/base/endian_types.hpp index bc61749..063779b 100644 --- a/src/myx/base/endian_types.hpp +++ b/src/myx/base/endian_types.hpp @@ -49,8 +49,8 @@ protected: static T transform( const T& b ) { - const uint16_t i = 1; - return( ( reinterpret_cast< const char& >( i ) == 1 ) ? b : EndianTypesBase< T >::swapBytes( b ) ); + const uint16_t k_i = 1; + return( ( reinterpret_cast< const char& >( k_i ) == 1 ) ? b : EndianTypesBase< T >::swapBytes( b ) ); } @@ -110,8 +110,8 @@ protected: static T transform( const T& b ) { - const uint16_t i = 1; - return( ( reinterpret_cast< const char& >( i ) == 1 ) ? EndianTypesBase< T >::swapBytes( b ) : b ); + const uint16_t k_i = 1; + return( ( reinterpret_cast< const char& >( k_i ) == 1 ) ? EndianTypesBase< T >::swapBytes( b ) : b ); } diff --git a/src/myx/filesystem/CMakeLists.txt b/src/myx/filesystem/CMakeLists.txt index be1f89a..0ec1240 100644 --- a/src/myx/filesystem/CMakeLists.txt +++ b/src/myx/filesystem/CMakeLists.txt @@ -11,46 +11,36 @@ set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.hpp) set(TRGT_headers ${TRGT_hpp}) # cmake-format: on -add_library(${TRGT}-header-only INTERFACE) -target_include_directories( - ${TRGT}-header-only SYSTEM INTERFACE "$" - "$") +add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) +common_target_properties(${TRGT}) -if(MYXLIB_BUILD_LIBRARIES) +# Создание цели для проверки утилитой clang-tidy +add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) - common_target_properties(${TRGT}) +# Создание цели для проверки утилитой clang-analyze +add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clang-tidy - add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой clazy +add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clang-analyze - add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой pvs-studio +add_pvs_check(${TRGT}) - # Создание цели для проверки утилитой clazy - add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для автоматического форматирования кода +add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой pvs-studio - add_pvs_check(${TRGT}) +target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) +target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) +cotire(${TRGT}) - # Создание цели для автоматического форматирования кода - add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - - target_compile_definitions(${TRGT} PUBLIC MYXLIB_BUILD_LIBRARIES) - target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - cotire(${TRGT}) - - install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - if(BUILD_SHARED_LIBS) - install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() -else() - install(FILES ${TRGT_cpp} COMPONENT base-dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) +install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +if(BUILD_SHARED_LIBS) + install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES}) -install(FILES ${TRGT_headers} COMPONENT base-dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) +install(FILES ${TRGT_headers} COMPONENT base-dev + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) # Цель, используемая только для установки заголовочных файлов без компиляции проекта add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index d007d7f..ee76954 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -1,13 +1,8 @@ #ifndef MYX_BASE_PATHS_CPP_ #define MYX_BASE_PATHS_CPP_ -#ifndef MYXLIB_HEADER_ONLY -#include -#else -#pragma once -#endif - #include +#include #include diff --git a/src/myx/filesystem/paths.hpp b/src/myx/filesystem/paths.hpp index 17effe8..c565e5a 100644 --- a/src/myx/filesystem/paths.hpp +++ b/src/myx/filesystem/paths.hpp @@ -232,8 +232,4 @@ public: } // namespace myx -#ifdef MYXLIB_HEADER_ONLY -#include "paths.cpp" -#endif - #endif // MYX_FILESYSTEM_PATHS_HPP_ diff --git a/src/myx/qt/CMakeLists.txt b/src/myx/qt/CMakeLists.txt index 2582397..f2d1861 100644 --- a/src/myx/qt/CMakeLists.txt +++ b/src/myx/qt/CMakeLists.txt @@ -26,47 +26,38 @@ set(TRGT_headers ${TRGT_moc_hpp} ${TRGT_hpp}) qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_private_hpp} ${TRGT_moc_hpp}) -add_library(${TRGT}-header-only INTERFACE) -target_include_directories( - ${TRGT}-header-only SYSTEM INTERFACE "$" - "$" - "$") +add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_moc_cpp} + ${TRGT_moc_private_hpp} ${TRGT_headers}) +common_target_properties(${TRGT}) -if(MYXLIB_BUILD_LIBRARIES) - add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_moc_cpp} ${TRGT_moc_private_hpp} ${TRGT_headers}) - common_target_properties(${TRGT}) +# Создание цели для проверки утилитой clang-tidy +add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clang-tidy - add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой clang-analyze +add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clang-analyze - add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой clazy +add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clazy - add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой pvs-studio +add_pvs_check(${TRGT}) - # Создание цели для проверки утилитой pvs-studio - add_pvs_check(${TRGT}) +# Создание цели для автоматического форматирования кода +add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers} ${TRGT_moc_private_hpp}) - # Создание цели для автоматического форматирования кода - add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers} ${TRGT_moc_private_hpp}) +target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) +target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) +target_include_directories(${TRGT} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +cotire(${TRGT}) - target_compile_definitions(${TRGT} PUBLIC MYXLIB_BUILD_LIBRARIES) - target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TRGT} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) - cotire(${TRGT}) - - install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - if(BUILD_SHARED_LIBS) - install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() -else() - install(FILES ${TRGT_cpp} COMPONENT base-dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) +install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +if(BUILD_SHARED_LIBS) + install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES}) -install(FILES ${TRGT_headers} COMPONENT base-dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) +install(FILES ${TRGT_headers} COMPONENT base-dev + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) # Цель, используемая только для установки заголовочных файлов без компиляции проекта add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp index 5688572..2ff13f8 100644 --- a/src/myx/qt/posix_signal_watcher.cpp +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -3,19 +3,14 @@ #include -#ifndef MYXLIB_HEADER_ONLY -#include #include -#else -#pragma once -#endif - +#include namespace myx { namespace qt { -int PosixSignalWatcherPrivate::m_sockpair[2] = {0, 0}; +std::array< int, 2 > PosixSignalWatcherPrivate::mSockpair = { 0, 0 }; PosixSignalWatcherPrivate::~PosixSignalWatcherPrivate() = default; @@ -24,7 +19,7 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : { #if MYX_QT_HAS_POSIX_SIGNALS // Create socket pair - if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, m_sockpair ) ) + if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, mSockpair.data() ) != 0 ) { qDebug() << "PosixSignalWatcher: socketpair: " << ::strerror( errno ); return; @@ -32,7 +27,7 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : #endif // Create a notifier for the read end of the pair - m_notifier.reset( new QSocketNotifier( m_sockpair[1], QSocketNotifier::Read ) ); + m_notifier.reset( new QSocketNotifier( mSockpair[1], QSocketNotifier::Read ) ); // Called when the signal handler has written to the socket pair. @@ -57,7 +52,7 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : * This provides a way to break out of the asynchronous context from which the * signal handler is called and back into the Qt event loop. */ -void PosixSignalWatcherPrivate::watchForSignal( int signal ) +MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) { if ( m_watchedSignals.contains( signal ) ) { @@ -67,12 +62,12 @@ void PosixSignalWatcherPrivate::watchForSignal( int signal ) #if MYX_QT_HAS_POSIX_SIGNALS // Register a sigaction which will write to the socket pair - struct sigaction sigact; + struct sigaction sigact {}; sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; sigact.sa_flags = 0; sigemptyset( &sigact.sa_mask ); sigact.sa_flags |= SA_RESTART; - if ( ::sigaction( signal, &sigact, nullptr ) ) + if ( ::sigaction( signal, &sigact, nullptr ) != 0 ) { qDebug() << "PosixSignalWatcher: sigaction: " << ::strerror( errno ); return; @@ -89,7 +84,7 @@ void PosixSignalWatcherPrivate::watchForSignal( int signal ) */ MYXLIB_INLINE void PosixSignalWatcherPrivate::signalHandler( int signal ) { - (void)::write( m_sockpair[0], &signal, sizeof( signal ) ); + (void)::write( mSockpair[0], &signal, sizeof( signal ) ); } diff --git a/src/myx/qt/posix_signal_watcher.hpp b/src/myx/qt/posix_signal_watcher.hpp index 511bca5..b4aaf6b 100644 --- a/src/myx/qt/posix_signal_watcher.hpp +++ b/src/myx/qt/posix_signal_watcher.hpp @@ -33,7 +33,7 @@ class PosixSignalWatcher : public QObject public: explicit PosixSignalWatcher( QObject* parent = nullptr ); - ~PosixSignalWatcher(); + ~PosixSignalWatcher() override; void watchForSignal( int signal ); Q_SIGNAL void posixSignal( int signal ); @@ -47,9 +47,4 @@ private: } // namespace myx -#ifdef MYXLIB_HEADER_ONLY -#include "posix_signal_watcher_p.hpp" -#include "posix_signal_watcher.cpp" -#endif - #endif // ifndef MYX_QT_POSIX_SIGNAL_WATCHER_HPP_ diff --git a/src/myx/qt/posix_signal_watcher_p.hpp b/src/myx/qt/posix_signal_watcher_p.hpp index 067f94c..9564737 100644 --- a/src/myx/qt/posix_signal_watcher_p.hpp +++ b/src/myx/qt/posix_signal_watcher_p.hpp @@ -1,8 +1,9 @@ #ifndef MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_ #define MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_ -#include +#pragma once +#include #include #include @@ -47,10 +48,10 @@ public: static void signalHandler( int signal ); private: - PosixSignalWatcher* const q_ptr = nullptr; Q_DECLARE_PUBLIC( PosixSignalWatcher ) - static int m_sockpair[2]; + PosixSignalWatcher* const q_ptr = nullptr; + static std::array< int, 2 > mSockpair; std::unique_ptr< QSocketNotifier > m_notifier; QList< int > m_watchedSignals; }; // class PosixSignalWatcherPrivate diff --git a/src/myx/qt/translators.cpp b/src/myx/qt/translators.cpp index 67e97ef..86b4b9c 100644 --- a/src/myx/qt/translators.cpp +++ b/src/myx/qt/translators.cpp @@ -2,12 +2,7 @@ #define MYX_QT_TRANSLATORS_CPP_ #include - -#ifndef MYXLIB_HEADER_ONLY #include -#else -#pragma once -#endif #include #include diff --git a/src/myx/qt/translators.hpp b/src/myx/qt/translators.hpp index a1515c5..ae24a51 100644 --- a/src/myx/qt/translators.hpp +++ b/src/myx/qt/translators.hpp @@ -20,8 +20,4 @@ void append_translators( QTranslatorsList& translators, const QString& appName ) } // namespace myx -#ifdef MYXLIB_HEADER_ONLY -#include "translators.cpp" -#endif - #endif // ifndef MYX_QT_TRANSLATORS_HPP_ From 3cb5cbd6c1e9f0102ab76a2e7c35af73bd9db903 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Mon, 29 Jun 2020 22:24:15 +0300 Subject: [PATCH 22/41] =?UTF-8?q?=D0=98=D0=BD=D0=B8=D1=86=D0=B8=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/qt/posix_signal_watcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp index 2ff13f8..1a26d4b 100644 --- a/src/myx/qt/posix_signal_watcher.cpp +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -10,7 +10,7 @@ namespace myx { namespace qt { -std::array< int, 2 > PosixSignalWatcherPrivate::mSockpair = { 0, 0 }; +std::array< int, 2 > PosixSignalWatcherPrivate::mSockpair { { 0, 0 } }; PosixSignalWatcherPrivate::~PosixSignalWatcherPrivate() = default; From cf52aba9a314df363bada7b04448bc3934adb692 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Mon, 29 Jun 2020 22:26:51 +0300 Subject: [PATCH 23/41] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D0=BE=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D1=87=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/qt/posix_signal_watcher_p.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/myx/qt/posix_signal_watcher_p.hpp b/src/myx/qt/posix_signal_watcher_p.hpp index 9564737..2375397 100644 --- a/src/myx/qt/posix_signal_watcher_p.hpp +++ b/src/myx/qt/posix_signal_watcher_p.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #ifdef Q_OS_WIN From 6358fe0820f8c0c5c89dbefcef0df04b2acc22d6 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Tue, 30 Jun 2020 20:04:26 +0300 Subject: [PATCH 24/41] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82?= =?UTF-8?q?=D1=83=D1=80=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 9 ++- cmake/etc/Variables.cmake | 2 +- .../{base => core}/01_endian/CMakeLists.txt | 5 +- examples/{base => core}/01_endian/endian.cpp | 9 +-- examples/{base => core}/CMakeLists.txt | 0 examples/filesystem/01_paths/CMakeLists.txt | 4 +- examples/filesystem/01_paths/paths.cpp | 3 +- examples/qt/01_translators/CMakeLists.txt | 4 +- .../qt/02_posix-signal-watcher/CMakeLists.txt | 4 +- .../posix_signal_watcher.cpp | 2 +- src/myx/backports/compiler/CMakeLists.txt | 42 +++++++++++ src/myx/backports/compiler/gcc.hpp | 29 ++++++++ src/myx/backports/cpp/CMakeLists.txt | 43 +++++++++++ src/myx/backports/cpp/helpers.hpp | 36 ++++++++++ src/myx/{base => backports/cpp}/span.hpp | 71 +++++++++---------- src/myx/backports/qt/CMakeLists.txt | 42 +++++++++++ .../backports.hpp => backports/qt/common.hpp} | 13 ++-- src/myx/base/config.cpp | 1 - src/myx/{base => core}/CMakeLists.txt | 19 ++--- src/myx/{base => core}/config.hpp | 6 +- src/myx/{base => core}/config_flags.hpp.in | 0 src/myx/{base => core}/endian_types.hpp | 50 ++++++------- .../enum_bitmask_operations.hpp | 12 ++-- src/myx/{base => core}/limits.hpp | 10 +-- src/myx/filesystem/paths.cpp | 8 +-- src/myx/filesystem/paths.hpp | 2 +- src/myx/qt/CMakeLists.txt | 1 - src/myx/qt/posix_signal_watcher.cpp | 10 ++- src/myx/qt/posix_signal_watcher.hpp | 5 +- src/myx/qt/posix_signal_watcher_p.hpp | 2 +- src/myx/qt/translators.cpp | 2 +- src/myx/qt/translators.hpp | 4 +- 32 files changed, 315 insertions(+), 135 deletions(-) rename examples/{base => core}/01_endian/CMakeLists.txt (94%) rename examples/{base => core}/01_endian/endian.cpp (53%) rename examples/{base => core}/CMakeLists.txt (100%) create mode 100644 src/myx/backports/compiler/CMakeLists.txt create mode 100644 src/myx/backports/compiler/gcc.hpp create mode 100644 src/myx/backports/cpp/CMakeLists.txt create mode 100644 src/myx/backports/cpp/helpers.hpp rename src/myx/{base => backports/cpp}/span.hpp (78%) create mode 100644 src/myx/backports/qt/CMakeLists.txt rename src/myx/{qt/backports.hpp => backports/qt/common.hpp} (65%) delete mode 100644 src/myx/base/config.cpp rename src/myx/{base => core}/CMakeLists.txt (72%) rename src/myx/{base => core}/config.hpp (73%) rename src/myx/{base => core}/config_flags.hpp.in (100%) rename src/myx/{base => core}/endian_types.hpp (81%) rename src/myx/{base => core}/enum_bitmask_operations.hpp (91%) rename src/myx/{base => core}/limits.hpp (85%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee9cf59..561029e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,16 +36,19 @@ find_package(Threads REQUIRED) find_package(Qt5 COMPONENTS Core Network REQUIRED) # Библиотеки -add_subdirectory(src/myx/base) +add_subdirectory(src/myx/backports/compiler) +add_subdirectory(src/myx/backports/cpp) +add_subdirectory(src/myx/backports/qt) +add_subdirectory(src/myx/core) add_subdirectory(src/myx/filesystem) add_subdirectory(src/myx/qt) # Примеры if(MYXLIB_BUILD_EXAMPLES) - add_subdirectory(examples/base) + add_subdirectory(examples/core) add_subdirectory(examples/filesystem) add_subdirectory(examples/qt) - add_custom_target(examples example-base-endian example-filesystem-paths example-qt-tranlators + add_custom_target(examples example-core-endian example-filesystem-paths example-qt-tranlators example-qt-posix-signal-watcher) endif() diff --git a/cmake/etc/Variables.cmake b/cmake/etc/Variables.cmake index 5445292..0338080 100644 --- a/cmake/etc/Variables.cmake +++ b/cmake/etc/Variables.cmake @@ -9,4 +9,4 @@ set(CPACK_COMPONENTS_ALL examples) set(CPACK_PACKAGE_CONTACT "Andrei Astafev ") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Mixed functions") -set(CMLIB_GENERATED_HEADERS_PATH ${CMAKE_BINARY_DIR}/include/myx/base) +set(CMLIB_GENERATED_HEADERS_PATH ${CMAKE_BINARY_DIR}/include/myx/core) diff --git a/examples/base/01_endian/CMakeLists.txt b/examples/core/01_endian/CMakeLists.txt similarity index 94% rename from examples/base/01_endian/CMakeLists.txt rename to examples/core/01_endian/CMakeLists.txt index cc3a06e..41309ad 100644 --- a/examples/base/01_endian/CMakeLists.txt +++ b/examples/core/01_endian/CMakeLists.txt @@ -1,5 +1,5 @@ # Название основной цели в текущем каталоге -set(TRGT example-base-endian) +set(TRGT example-core-endian) # Список файлов исходных текстов set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/endian.cpp) @@ -32,9 +32,8 @@ if(MYXLIB_BUILD_EXAMPLES) target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - add_dependencies(${TRGT} base) + add_dependencies(${TRGT} core) - target_link_libraries(${TRGT} base_static) target_link_libraries(${TRGT} Qt5::Core) target_link_libraries(${TRGT} Threads::Threads) diff --git a/examples/base/01_endian/endian.cpp b/examples/core/01_endian/endian.cpp similarity index 53% rename from examples/base/01_endian/endian.cpp rename to examples/core/01_endian/endian.cpp index a4cc260..f147381 100644 --- a/examples/base/01_endian/endian.cpp +++ b/examples/core/01_endian/endian.cpp @@ -1,8 +1,9 @@ -#include -#include +#include +#include #include +//NOLINTNEXTLINE #define CMLIB_PROJECT_NAME "myxlib" @@ -12,11 +13,11 @@ int main( int argc, char** argv ) (void)argv; beint64 bi = 1; - int64_t bii = reinterpret_cast< int64_t* >( &bi )[0]; + int64_t bii = reinterpret_cast< int64_t* >( &bi )[0]; //NOLINT qDebug() << hex << bi << bii; leint64 li = 1; - int64_t lii = reinterpret_cast< int64_t* >( &li )[0]; + int64_t lii = reinterpret_cast< int64_t* >( &li )[0]; //NOLINT qDebug() << hex << li << lii; return( 0 ); diff --git a/examples/base/CMakeLists.txt b/examples/core/CMakeLists.txt similarity index 100% rename from examples/base/CMakeLists.txt rename to examples/core/CMakeLists.txt diff --git a/examples/filesystem/01_paths/CMakeLists.txt b/examples/filesystem/01_paths/CMakeLists.txt index 2062f33..bc6c3a6 100644 --- a/examples/filesystem/01_paths/CMakeLists.txt +++ b/examples/filesystem/01_paths/CMakeLists.txt @@ -32,9 +32,9 @@ if(MYXLIB_BUILD_EXAMPLES) target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - add_dependencies(${TRGT} base filesystem) + add_dependencies(${TRGT} core filesystem) - target_link_libraries(${TRGT} base_static filesystem_static) + target_link_libraries(${TRGT} filesystem_static) target_link_libraries(${TRGT} Qt5::Core) target_link_libraries(${TRGT} Threads::Threads) diff --git a/examples/filesystem/01_paths/paths.cpp b/examples/filesystem/01_paths/paths.cpp index 739a6db..c41888f 100644 --- a/examples/filesystem/01_paths/paths.cpp +++ b/examples/filesystem/01_paths/paths.cpp @@ -1,10 +1,11 @@ -#include +#include #include #include #include +//NOLINTNEXTLINE #define CMLIB_PROJECT_NAME "myxlib" namespace MF = myx::filesystem; diff --git a/examples/qt/01_translators/CMakeLists.txt b/examples/qt/01_translators/CMakeLists.txt index c02441f..a90e559 100644 --- a/examples/qt/01_translators/CMakeLists.txt +++ b/examples/qt/01_translators/CMakeLists.txt @@ -38,9 +38,9 @@ if(MYXLIB_BUILD_EXAMPLES) target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - add_dependencies(${TRGT} base qt) + add_dependencies(${TRGT} core qt) - target_link_libraries(${TRGT} base_static qt_static) + target_link_libraries(${TRGT} qt_static) target_link_libraries(${TRGT} Qt5::Core) target_link_libraries(${TRGT} Threads::Threads) diff --git a/examples/qt/02_posix-signal-watcher/CMakeLists.txt b/examples/qt/02_posix-signal-watcher/CMakeLists.txt index 1caeae2..204cec2 100644 --- a/examples/qt/02_posix-signal-watcher/CMakeLists.txt +++ b/examples/qt/02_posix-signal-watcher/CMakeLists.txt @@ -32,9 +32,9 @@ if(MYXLIB_BUILD_EXAMPLES) target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - add_dependencies(${TRGT} base qt) + add_dependencies(${TRGT} core qt) - target_link_libraries(${TRGT} base_static qt_static) + target_link_libraries(${TRGT} qt_static) target_link_libraries(${TRGT} Qt5::Core) target_link_libraries(${TRGT} Threads::Threads) diff --git a/examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp b/examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp index 9fb9ef6..ccc1ca4 100644 --- a/examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp +++ b/examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp @@ -15,7 +15,7 @@ int main( int argc, char* argv[] ) sigwatch.watchForSignal( SIGTERM ); QObject::connect( &sigwatch, &MQ::PosixSignalWatcher::posixSignal, &app, &QCoreApplication::quit ); - int exitcode = app.exec(); + int exitcode = QCoreApplication::exec(); qDebug() << "Goodbye"; return( exitcode ); } diff --git a/src/myx/backports/compiler/CMakeLists.txt b/src/myx/backports/compiler/CMakeLists.txt new file mode 100644 index 0000000..d8d482d --- /dev/null +++ b/src/myx/backports/compiler/CMakeLists.txt @@ -0,0 +1,42 @@ +# Название основной цели и имя библиотеки в текущем каталоге +set(TRGT backports-compiler) + +# cmake-format: off +# Список файлов исходных текстов +set(TRGT_cpp) + +# Список заголовочных файлов +set(TRGT_hpp + ${CMAKE_CURRENT_SOURCE_DIR}/gcc.hpp + ) + +set(TRGT_headers ${TRGT_hpp}) +# cmake-format: on + +add_library(${TRGT} INTERFACE) +target_sources(${TRGT} INTERFACE ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой clang-tidy +add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой clang-analyze +add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой clazy +add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой pvs-studio +add_pvs_check(${TRGT}) + +# Создание цели для автоматического форматирования кода +add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src) + +generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES}) +install(FILES ${TRGT_headers} COMPONENT base-dev + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/backports/compiler) + +# Цель, используемая только для установки заголовочных файлов без компиляции проекта +add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P + "${CMAKE_BINARY_DIR}/cmake_install.cmake") diff --git a/src/myx/backports/compiler/gcc.hpp b/src/myx/backports/compiler/gcc.hpp new file mode 100644 index 0000000..67a614b --- /dev/null +++ b/src/myx/backports/compiler/gcc.hpp @@ -0,0 +1,29 @@ +#ifndef MYX_BACKPORTS_COMPILER_GCC_HPP_ +#define MYX_BACKPORTS_COMPILER_GCC_HPP_ + +#pragma once + +#ifdef __GNUC__ +// NOLINTNEXTLINE +#define GCC_VERSION ( __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ ) +#if GCC_VERSION <= 40702 + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wkeyword-macro" +#endif + +// NOLINTNEXTLINE +#define override + +// NOLINTNEXTLINE +#define constexpr const + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +#endif // if GCC_VERSION <= 40702 +#endif // ifdef __GNUC__ + +#endif // ifndef MYX_BACKPORTS_COMPILER_GCC_HPP_ diff --git a/src/myx/backports/cpp/CMakeLists.txt b/src/myx/backports/cpp/CMakeLists.txt new file mode 100644 index 0000000..2c81cda --- /dev/null +++ b/src/myx/backports/cpp/CMakeLists.txt @@ -0,0 +1,43 @@ +# Название основной цели и имя библиотеки в текущем каталоге +set(TRGT backports-cpp) + +# cmake-format: off +# Список файлов исходных текстов +set(TRGT_cpp) + +# Список заголовочных файлов +set(TRGT_hpp + ${CMAKE_CURRENT_SOURCE_DIR}/helpers.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/span.hpp + ) + +set(TRGT_headers ${TRGT_hpp}) +# cmake-format: on + +add_library(${TRGT} INTERFACE) +target_sources(${TRGT} INTERFACE ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой clang-tidy +add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой clang-analyze +add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой clazy +add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой pvs-studio +add_pvs_check(${TRGT}) + +# Создание цели для автоматического форматирования кода +add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src) + +generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES}) +install(FILES ${TRGT_headers} COMPONENT base-dev + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/backports/cpp) + +# Цель, используемая только для установки заголовочных файлов без компиляции проекта +add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P + "${CMAKE_BINARY_DIR}/cmake_install.cmake") diff --git a/src/myx/backports/cpp/helpers.hpp b/src/myx/backports/cpp/helpers.hpp new file mode 100644 index 0000000..ff984b2 --- /dev/null +++ b/src/myx/backports/cpp/helpers.hpp @@ -0,0 +1,36 @@ +#ifndef MYX_BACKPORTS_CPP_HELPERS_HPP_ +#define MYX_BACKPORTS_CPP_HELPERS_HPP_ + +#pragma once + +#if ( __cplusplus >= 201103L ) +#include +#endif + +#if ( __cplusplus >= 201103L ) && ( __cplusplus < 201402L ) + +namespace std +{ + +template< class T > +using underlying_type_t = typename std::underlying_type< T >::type; + +} // namespace std + +#endif + +#if ( __cplusplus >= 201103L ) && ( __cplusplus < 201702L ) + +namespace std +{ + +#if defined( __STRICT_ANSI__ ) +template< typename ... Ts > struct make_void { typedef void type; }; +template< typename ... Ts > using void_t = typename make_void< Ts... >::type; +#endif + +} // namespace std + +#endif + +#endif // ifndef MYX_BACKPORTS_CPP_HELPERS_HPP_ diff --git a/src/myx/base/span.hpp b/src/myx/backports/cpp/span.hpp similarity index 78% rename from src/myx/base/span.hpp rename to src/myx/backports/cpp/span.hpp index 7533e52..6cf6339 100644 --- a/src/myx/base/span.hpp +++ b/src/myx/backports/cpp/span.hpp @@ -7,23 +7,24 @@ // Official repository: https://github.com/boostorg/beast // -#ifndef MYX_BASE_SPAN_HPP_ -#define MYX_BASE_SPAN_HPP_ +#ifndef MYX_BACKPORTS_CPP_SPAN_HPP_ +#define MYX_BACKPORTS_CPP_SPAN_HPP_ + +#pragma once + +#if ( __cplusplus >= 201103L ) && ( __cplusplus < 201703L ) + +#include #include #include #include #include -namespace myx { - -namespace base { - -template< typename ... Ts > struct make_void { typedef void type;}; // NOLINT -template< typename ... Ts > using void_t = typename make_void< Ts... >::type; // NOLINT +namespace std { template< class T, class E, class = void > -struct is_contiguous_container : std::false_type {}; // NOLINT +struct is_contiguous_container : std::false_type {}; // NOLINT template< class T, class E > struct is_contiguous_container< T, E, void_t< @@ -52,38 +53,38 @@ struct is_contiguous_container< T, E, void_t< @tparam T The type pointed to by span iterators */ template< class T > -class span // NOLINT +class span // NOLINT { T* m_data = nullptr; std::size_t m_size = 0; public: /// The type of value, including cv qualifiers - using element_type = T; + using ElementType = T; /// The type of value of each span element - using value_type = typename std::remove_const< T >::type; + using ValueType = typename std::remove_const< T >::type; /// The type of integer used to index the span - using index_type = std::ptrdiff_t; + using IndexType = std::ptrdiff_t; /// A pointer to a span element - using pointer = T*; + using Pointer = T*; /// A reference to a span element - using reference = T&; + using Reference = T&; /// The iterator used by the container - using iterator = pointer; + using Iterator = Pointer; /// The const pointer used by the container - using const_pointer = T const*; + using ConstPointer = T const*; /// The const reference used by the container - using const_reference = T const&; + using ConstReference = T const&; /// The const iterator used by the container - using const_iterator = const_pointer; + using ConstIterator = ConstPointer; /// Constructor span() = default; @@ -95,11 +96,9 @@ public: span& operator=( span const& ) = default; /** Constructor - - @param data A pointer to the beginning of the range of elements - - @param size The number of elements pointed to by `data` - */ + * @param data A pointer to the beginning of the range of elements + * @param size The number of elements pointed to by `data` + */ span( T* data, std::size_t size ) : m_data( data ), m_size( size ) @@ -108,9 +107,8 @@ public: /** Constructor - - @param container The container to construct from - */ + * @param container The container to construct from + */ template< class ContiguousContainer, class = typename std::enable_if< is_contiguous_container< @@ -143,9 +141,8 @@ public: /** Assignment - - @param container The container to assign from - */ + * @param container The container to assign from + */ template< class ContiguousContainer > typename std::enable_if< is_contiguous_container< ContiguousContainer, T >::value, @@ -205,7 +202,7 @@ public: /// Returns an iterator to the beginning of the span - iterator + Iterator begin() const { return( m_data ); @@ -213,7 +210,7 @@ public: /// Returns an iterator to the beginning of the span - const_iterator + ConstIterator cbegin() const { return( m_data ); @@ -221,7 +218,7 @@ public: /// Returns an iterator to one past the end of the span - iterator + Iterator end() const { return( m_data + m_size ); @@ -229,15 +226,15 @@ public: /// Returns an iterator to one past the end of the span - const_iterator + ConstIterator cend() const { return( m_data + m_size ); } }; // class span -} // namespace base +} // namespace std -} // namespace myx +#endif // if ( __cplusplus >= 201103L ) && ( __cplusplus < 201703L ) -#endif // ifndef MYX_BASE_SPAN_HPP_ +#endif // ifndef MYX_BACKPORTS_CPP_SPAN_HPP_ diff --git a/src/myx/backports/qt/CMakeLists.txt b/src/myx/backports/qt/CMakeLists.txt new file mode 100644 index 0000000..0dcf6bb --- /dev/null +++ b/src/myx/backports/qt/CMakeLists.txt @@ -0,0 +1,42 @@ +# Название основной цели и имя библиотеки в текущем каталоге +set(TRGT backports-qt) + +# cmake-format: off +# Список файлов исходных текстов +set(TRGT_cpp) + +# Список заголовочных файлов +set(TRGT_hpp + ${CMAKE_CURRENT_SOURCE_DIR}/common.hpp + ) + +set(TRGT_headers ${TRGT_hpp}) +# cmake-format: on + +add_library(${TRGT} INTERFACE) +target_sources(${TRGT} INTERFACE ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой clang-tidy +add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой clang-analyze +add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой clazy +add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +# Создание цели для проверки утилитой pvs-studio +add_pvs_check(${TRGT}) + +# Создание цели для автоматического форматирования кода +add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) + +target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src) + +install(FILES ${TRGT_headers} COMPONENT base-dev + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/backports/qt) +generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES}) + +# Цель, используемая только для установки заголовочных файлов без компиляции проекта +add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P + "${CMAKE_BINARY_DIR}/cmake_install.cmake") diff --git a/src/myx/qt/backports.hpp b/src/myx/backports/qt/common.hpp similarity index 65% rename from src/myx/qt/backports.hpp rename to src/myx/backports/qt/common.hpp index 0ce776d..55f68b1 100644 --- a/src/myx/qt/backports.hpp +++ b/src/myx/backports/qt/common.hpp @@ -1,11 +1,9 @@ -#ifndef MYX_QT_BACKPORTS_HPP_ -#define MYX_QT_BACKPORTS_HPP_ +#ifndef MYX_BACKPORTS_QT_COMMON_HPP_ +#define MYX_BACKPORTS_QT_COMMON_HPP_ #pragma once -#if ( defined ( TARGET_LSB_ID_AstraLinuxSE ) && defined ( TARGET_LSB_CODENAME_smolensk ) ) - -#define override +#if defined( QT_VERSION ) #if QT_VERSION <= 0x050700 #include @@ -33,6 +31,7 @@ void qAsConst( const T&& ) = delete; #endif // if QT_VERSION <= 0x050700 -#endif // if ( defined ( TARGET_LSB_ID_AstraLinuxSE ) && defined ( TARGET_LSB_CODENAME_smolensk ) ) -#endif // MYX_QT_BACKPORTS_HPP_ +#endif // if defined( QT_VERSION ) + +#endif // MYX_BACKPORTS_QT_COMMON_HPP_ diff --git a/src/myx/base/config.cpp b/src/myx/base/config.cpp deleted file mode 100644 index 3e8bcfb..0000000 --- a/src/myx/base/config.cpp +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/src/myx/base/CMakeLists.txt b/src/myx/core/CMakeLists.txt similarity index 72% rename from src/myx/base/CMakeLists.txt rename to src/myx/core/CMakeLists.txt index 42627d7..8c6a34a 100644 --- a/src/myx/base/CMakeLists.txt +++ b/src/myx/core/CMakeLists.txt @@ -1,24 +1,22 @@ # Название основной цели и имя библиотеки в текущем каталоге -set(TRGT base) +set(TRGT core) # cmake-format: off # Список файлов исходных текстов -set(TRGT_cpp - ${CMAKE_CURRENT_SOURCE_DIR}/config.cpp) +set(TRGT_cpp) # Список заголовочных файлов set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/config.hpp ${CMAKE_CURRENT_SOURCE_DIR}/limits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/span.hpp ${CMAKE_CURRENT_SOURCE_DIR}/endian_types.hpp ${CMAKE_CURRENT_SOURCE_DIR}/enum_bitmask_operations.hpp) set(TRGT_headers ${TRGT_hpp}) # cmake-format: on -add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) -common_target_properties(${TRGT}) +add_library(${TRGT} INTERFACE) +target_sources(${TRGT} INTERFACE ${TRGT_cpp} ${TRGT_headers}) # Создание цели для проверки утилитой clang-tidy add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) @@ -35,15 +33,10 @@ add_pvs_check(${TRGT}) # Создание цели для автоматического форматирования кода add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) -target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - -install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -if(BUILD_SHARED_LIBS) - install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) -endif() +target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src) generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES}) -install(FILES ${TRGT_headers} ${CMAKE_BINARY_DIR}/include/myx/base/compiler_features.hpp COMPONENT base-dev +install(FILES ${TRGT_headers} ${CMAKE_BINARY_DIR}/include/myx/core/compiler_features.hpp COMPONENT base-dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) # Цель, используемая только для установки заголовочных файлов без компиляции проекта diff --git a/src/myx/base/config.hpp b/src/myx/core/config.hpp similarity index 73% rename from src/myx/base/config.hpp rename to src/myx/core/config.hpp index c179cdf..946d1b2 100644 --- a/src/myx/base/config.hpp +++ b/src/myx/core/config.hpp @@ -1,5 +1,5 @@ -#ifndef MYX_BASE_CONFIG_HPP_ -#define MYX_BASE_CONFIG_HPP_ +#ifndef MYX_CORE_CONFIG_HPP_ +#define MYX_CORE_CONFIG_HPP_ #pragma once @@ -14,4 +14,4 @@ #endif #define MYXLIB_INLINE -#endif // MYX_BASE_CONFIG_HPP_ +#endif // MYX_CORE_CONFIG_HPP_ diff --git a/src/myx/base/config_flags.hpp.in b/src/myx/core/config_flags.hpp.in similarity index 100% rename from src/myx/base/config_flags.hpp.in rename to src/myx/core/config_flags.hpp.in diff --git a/src/myx/base/endian_types.hpp b/src/myx/core/endian_types.hpp similarity index 81% rename from src/myx/base/endian_types.hpp rename to src/myx/core/endian_types.hpp index 063779b..a76747a 100644 --- a/src/myx/base/endian_types.hpp +++ b/src/myx/core/endian_types.hpp @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include @@ -17,7 +17,7 @@ namespace myx { -namespace base { +namespace core { template< typename T > class EndianTypesBase @@ -29,8 +29,8 @@ protected: static T swapBytes( const T& b ) { T n; - myx::base::span< uint8_t > sn( reinterpret_cast< uint8_t* >( &n ), sizeof( T ) ); - myx::base::span< const uint8_t > sb( reinterpret_cast< const uint8_t* >( &b ), sizeof( T ) ); + std::span< uint8_t > sn( reinterpret_cast< uint8_t* >( &n ), sizeof( T ) ); //NOLINT + std::span< const uint8_t > sb( reinterpret_cast< const uint8_t* >( &b ), sizeof( T ) ); //NOLINT std::reverse_copy( sb.begin(), sb.end(), sn.begin() ); return( n ); } // swapBytes @@ -45,12 +45,12 @@ template< typename T > class LittleEndianType : public EndianTypesBase< T > { protected: - T m_data; + T m_data; //NOLINT static T transform( const T& b ) { const uint16_t k_i = 1; - return( ( reinterpret_cast< const char& >( k_i ) == 1 ) ? b : EndianTypesBase< T >::swapBytes( b ) ); + return( ( reinterpret_cast< const char& >( k_i ) == 1 ) ? b : EndianTypesBase< T >::swapBytes( b ) ); //NOLINT } @@ -106,12 +106,12 @@ template< typename T > class BigEndianType : public EndianTypesBase< T > { protected: - T m_data; + T m_data; //NOLINT static T transform( const T& b ) { const uint16_t k_i = 1; - return( ( reinterpret_cast< const char& >( k_i ) == 1 ) ? EndianTypesBase< T >::swapBytes( b ) : b ); + return( ( reinterpret_cast< const char& >( k_i ) == 1 ) ? EndianTypesBase< T >::swapBytes( b ) : b ); //NOLINT } @@ -163,30 +163,30 @@ public: #endif }; // class BigEndianType -} // namespace base +} // namespace core } // namespace myx -using leint16 = myx::base::LittleEndianType< int16_t >; -using leint32 = myx::base::LittleEndianType< int32_t >; -using leint64 = myx::base::LittleEndianType< int64_t >; +using leint16 = myx::core::LittleEndianType< int16_t >; //NOLINT +using leint32 = myx::core::LittleEndianType< int32_t >; //NOLINT +using leint64 = myx::core::LittleEndianType< int64_t >; //NOLINT -using leuint16 = myx::base::LittleEndianType< uint16_t >; -using leuint32 = myx::base::LittleEndianType< uint32_t >; -using leuint64 = myx::base::LittleEndianType< uint64_t >; +using leuint16 = myx::core::LittleEndianType< uint16_t >; //NOLINT +using leuint32 = myx::core::LittleEndianType< uint32_t >; //NOLINT +using leuint64 = myx::core::LittleEndianType< uint64_t >; //NOLINT -using lefloat = myx::base::LittleEndianType< float >; -using ledouble = myx::base::LittleEndianType< double >; +using lefloat = myx::core::LittleEndianType< float >; //NOLINT +using ledouble = myx::core::LittleEndianType< double >; //NOLINT -using beint16 = myx::base::BigEndianType< int16_t >; -using beint32 = myx::base::BigEndianType< int32_t >; -using beint64 = myx::base::BigEndianType< int64_t >; +using beint16 = myx::core::BigEndianType< int16_t >; //NOLINT +using beint32 = myx::core::BigEndianType< int32_t >; //NOLINT +using beint64 = myx::core::BigEndianType< int64_t >; //NOLINT -using beuint16 = myx::base::BigEndianType< uint16_t >; -using beuint32 = myx::base::BigEndianType< uint32_t >; -using beuint64 = myx::base::BigEndianType< uint64_t >; +using beuint16 = myx::core::BigEndianType< uint16_t >; //NOLINT +using beuint32 = myx::core::BigEndianType< uint32_t >; //NOLINT +using beuint64 = myx::core::BigEndianType< uint64_t >; //NOLINT -using befloat = myx::base::BigEndianType< float >; -using bedouble = myx::base::BigEndianType< double >; +using befloat = myx::core::BigEndianType< float >; //NOLINT +using bedouble = myx::core::BigEndianType< double >; //NOLINT #endif // MYX_BASE_ENDIAN_TYPES_HPP_ diff --git a/src/myx/base/enum_bitmask_operations.hpp b/src/myx/core/enum_bitmask_operations.hpp similarity index 91% rename from src/myx/base/enum_bitmask_operations.hpp rename to src/myx/core/enum_bitmask_operations.hpp index e7cf829..1c10f8c 100644 --- a/src/myx/base/enum_bitmask_operations.hpp +++ b/src/myx/core/enum_bitmask_operations.hpp @@ -1,5 +1,5 @@ -#ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_ -#define MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_ +#ifndef MYX_CORE_ENUM_BITWISE_OPERATIONS_HPP_ +#define MYX_CORE_ENUM_BITWISE_OPERATIONS_HPP_ #pragma once @@ -7,7 +7,7 @@ namespace myx { -namespace base { +namespace core { template< typename Enum > struct EnableBitMaskOperators @@ -61,7 +61,7 @@ operator &=( Enum& lhs, Enum rhs ) return( lhs ); } -} // namespace base +} // namespace core } // namespace myx @@ -85,9 +85,9 @@ operator &=( Enum& lhs, Enum rhs ) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ENABLE_BITMASK_OPERATORS( x ) \ template<> \ - struct myx::base::EnableBitMaskOperators< x > \ + struct myx::core::EnableBitMaskOperators< x > \ { \ static const bool kEnable = true; \ }; -#endif // ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_ +#endif // ifndef MYX_CORE_ENUM_BITWISE_OPERATIONS_HPP_ diff --git a/src/myx/base/limits.hpp b/src/myx/core/limits.hpp similarity index 85% rename from src/myx/base/limits.hpp rename to src/myx/core/limits.hpp index 3f5d390..92a9e5e 100644 --- a/src/myx/base/limits.hpp +++ b/src/myx/core/limits.hpp @@ -1,5 +1,5 @@ -#ifndef MYX_BASE_LIMITS_HPP_ -#define MYX_BASE_LIMITS_HPP_ +#ifndef MYX_CORE_LIMITS_HPP_ +#define MYX_CORE_LIMITS_HPP_ #pragma once @@ -7,7 +7,7 @@ namespace myx { -namespace base { +namespace core { /** * @brief Константа, представляющая значение, не являющееся числом, для типа float @@ -24,8 +24,8 @@ constexpr double kDoubleNAN { std::numeric_limits< double >::quiet_NaN() }; */ constexpr double kLongDoubleNAN { std::numeric_limits< long double >::quiet_NaN() }; -} // namespace base +} // namespace core } // namespace myx -#endif // MYX_BASE_LIMITS_HPP_ +#endif // MYX_CORE_LIMITS_HPP_ diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index ee76954..9437a2c 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -1,7 +1,7 @@ -#ifndef MYX_BASE_PATHS_CPP_ -#define MYX_BASE_PATHS_CPP_ +#ifndef MYX_CORE_PATHS_CPP_ +#define MYX_CORE_PATHS_CPP_ -#include +#include #include #include @@ -368,4 +368,4 @@ MYXLIB_INLINE const QString& Paths::prefixDirectory() const } // namespace myx -#endif // MYX_BASE_PATHS_CPP_ +#endif // MYX_CORE_PATHS_CPP_ diff --git a/src/myx/filesystem/paths.hpp b/src/myx/filesystem/paths.hpp index c565e5a..de22f4c 100644 --- a/src/myx/filesystem/paths.hpp +++ b/src/myx/filesystem/paths.hpp @@ -8,7 +8,7 @@ #pragma once -#include +#include #include #include diff --git a/src/myx/qt/CMakeLists.txt b/src/myx/qt/CMakeLists.txt index f2d1861..117a821 100644 --- a/src/myx/qt/CMakeLists.txt +++ b/src/myx/qt/CMakeLists.txt @@ -17,7 +17,6 @@ set(TRGT_moc_private_hpp ) set(TRGT_hpp - ${CMAKE_CURRENT_SOURCE_DIR}/backports.hpp ${CMAKE_CURRENT_SOURCE_DIR}/translators.hpp ) diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp index 1a26d4b..b0d8f9b 100644 --- a/src/myx/qt/posix_signal_watcher.cpp +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -1,7 +1,7 @@ #ifndef MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ #define MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ -#include +#include #include #include @@ -27,8 +27,8 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : #endif // Create a notifier for the read end of the pair - m_notifier.reset( new QSocketNotifier( mSockpair[1], QSocketNotifier::Read ) ); - + // m_notifier.reset( new QSocketNotifier( mSockpair[1], QSocketNotifier::Read ) ); + m_notifier = std::make_unique< QSocketNotifier >( mSockpair[1], QSocketNotifier::Read ); // Called when the signal handler has written to the socket pair. // Emits the Posix signal as a Qt signal. @@ -63,7 +63,7 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) #if MYX_QT_HAS_POSIX_SIGNALS // Register a sigaction which will write to the socket pair struct sigaction sigact {}; - sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; + sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; //NOLINT sigact.sa_flags = 0; sigemptyset( &sigact.sa_mask ); sigact.sa_flags |= SA_RESTART; @@ -98,8 +98,6 @@ MYXLIB_INLINE PosixSignalWatcher::PosixSignalWatcher( QObject* parent ) : } -MYXLIB_INLINE PosixSignalWatcher::~PosixSignalWatcher() = default; - /*! * Register a signal handler for the given \a signal. * diff --git a/src/myx/qt/posix_signal_watcher.hpp b/src/myx/qt/posix_signal_watcher.hpp index b4aaf6b..7b465fc 100644 --- a/src/myx/qt/posix_signal_watcher.hpp +++ b/src/myx/qt/posix_signal_watcher.hpp @@ -3,7 +3,7 @@ #pragma once -#include +#include #include @@ -33,14 +33,13 @@ class PosixSignalWatcher : public QObject public: explicit PosixSignalWatcher( QObject* parent = nullptr ); - ~PosixSignalWatcher() override; void watchForSignal( int signal ); Q_SIGNAL void posixSignal( int signal ); private: PosixSignalWatcherPrivate* const d_ptr = nullptr; - Q_DECLARE_PRIVATE( PosixSignalWatcher ) + Q_DECLARE_PRIVATE( PosixSignalWatcher ) //NOLINT }; // class PosixSignalWatcher } // namespace qt diff --git a/src/myx/qt/posix_signal_watcher_p.hpp b/src/myx/qt/posix_signal_watcher_p.hpp index 2375397..d31b36c 100644 --- a/src/myx/qt/posix_signal_watcher_p.hpp +++ b/src/myx/qt/posix_signal_watcher_p.hpp @@ -3,7 +3,7 @@ #pragma once -#include +#include #include #include diff --git a/src/myx/qt/translators.cpp b/src/myx/qt/translators.cpp index 86b4b9c..32fe57f 100644 --- a/src/myx/qt/translators.cpp +++ b/src/myx/qt/translators.cpp @@ -1,7 +1,7 @@ #ifndef MYX_QT_TRANSLATORS_CPP_ #define MYX_QT_TRANSLATORS_CPP_ -#include +#include #include #include diff --git a/src/myx/qt/translators.hpp b/src/myx/qt/translators.hpp index ae24a51..46aa162 100644 --- a/src/myx/qt/translators.hpp +++ b/src/myx/qt/translators.hpp @@ -3,8 +3,8 @@ #pragma once -#include -#include +#include +#include #include From d124aeb9dd4ca40a91a4d15b175608c465800d19 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 2 Jul 2020 15:53:31 +0300 Subject: [PATCH 25/41] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=AD=D0=BB=D1=8C=D0=B1=D1=80=D1=83=D1=81?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/backports/cpp/helpers.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/myx/backports/cpp/helpers.hpp b/src/myx/backports/cpp/helpers.hpp index ff984b2..038182e 100644 --- a/src/myx/backports/cpp/helpers.hpp +++ b/src/myx/backports/cpp/helpers.hpp @@ -24,7 +24,7 @@ using underlying_type_t = typename std::underlying_type< T >::type; namespace std { -#if defined( __STRICT_ANSI__ ) +#if defined( __STRICT_ANSI__ ) || ( __e2k__ ) template< typename ... Ts > struct make_void { typedef void type; }; template< typename ... Ts > using void_t = typename make_void< Ts... >::type; #endif From bad24e34c7c265e28e7c62903d4e00db935f5098 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 2 Jul 2020 15:58:28 +0300 Subject: [PATCH 26/41] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=A1=D0=BC=D0=BE=D0=BB=D0=B5=D0=BD=D1=81?= =?UTF-8?q?=D0=BA=201.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/qt/posix_signal_watcher.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp index b0d8f9b..a084347 100644 --- a/src/myx/qt/posix_signal_watcher.cpp +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -2,6 +2,7 @@ #define MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ #include +#include #include #include From 11866bf3ba64c468ab38a263a36f118b477399f0 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 2 Jul 2020 16:00:35 +0300 Subject: [PATCH 27/41] =?UTF-8?q?=D0=95=D1=89=D1=91=20=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=A1=D0=BC=D0=BE?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=81=D0=BA=201.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/qt/translators.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/myx/qt/translators.cpp b/src/myx/qt/translators.cpp index 32fe57f..d04ceca 100644 --- a/src/myx/qt/translators.cpp +++ b/src/myx/qt/translators.cpp @@ -2,6 +2,8 @@ #define MYX_QT_TRANSLATORS_CPP_ #include +#include + #include #include From de1c396a5edf7947fd677747d97a8edcdab8c7d8 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 9 Jul 2020 15:05:59 +0300 Subject: [PATCH 28/41] make_unique --- src/myx/backports/cpp/helpers.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/myx/backports/cpp/helpers.hpp b/src/myx/backports/cpp/helpers.hpp index 038182e..18aa1d6 100644 --- a/src/myx/backports/cpp/helpers.hpp +++ b/src/myx/backports/cpp/helpers.hpp @@ -4,6 +4,7 @@ #pragma once #if ( __cplusplus >= 201103L ) +#include #include #endif @@ -15,6 +16,12 @@ namespace std template< class T > using underlying_type_t = typename std::underlying_type< T >::type; +template +std::unique_ptr make_unique(Args&&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} + } // namespace std #endif From e97025a81e1ec72db89f6940358f411f1af63191 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 9 Jul 2020 15:17:23 +0300 Subject: [PATCH 29/41] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D0=BE=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B0=D0=BA=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D0=B0=20QT=5FVERSION?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/backports/qt/common.hpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/myx/backports/qt/common.hpp b/src/myx/backports/qt/common.hpp index 55f68b1..f225fb0 100644 --- a/src/myx/backports/qt/common.hpp +++ b/src/myx/backports/qt/common.hpp @@ -3,10 +3,11 @@ #pragma once -#if defined( QT_VERSION ) - -#if QT_VERSION <= 0x050700 +#if !defined( QT_VERSION ) #include +#endif + +#if (QT_VERSION <= 0x050700) template< typename ... Args > struct QOverload { @@ -29,9 +30,6 @@ Q_DECL_CONSTEXPR typename std::add_const< T >::type& qAsConst( T& t ) noexcept template < typename T > void qAsConst( const T&& ) = delete; - #endif // if QT_VERSION <= 0x050700 -#endif // if defined( QT_VERSION ) - #endif // MYX_BACKPORTS_QT_COMMON_HPP_ From ec720ff8f42553177f70a7539c344217c3b9672b Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 9 Jul 2020 15:45:32 +0300 Subject: [PATCH 30/41] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/backports/cpp/helpers.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/myx/backports/cpp/helpers.hpp b/src/myx/backports/cpp/helpers.hpp index 18aa1d6..3f6b1c0 100644 --- a/src/myx/backports/cpp/helpers.hpp +++ b/src/myx/backports/cpp/helpers.hpp @@ -16,25 +16,25 @@ namespace std template< class T > using underlying_type_t = typename std::underlying_type< T >::type; -template -std::unique_ptr make_unique(Args&&... args) +template< typename T, typename ... Args > +std::unique_ptr< T > make_unique( Args&&... args ) { - return std::unique_ptr(new T(std::forward(args)...)); + return( std::unique_ptr< T >( new T( std::forward< Args >( args )... ) ) ); } } // namespace std #endif -#if ( __cplusplus >= 201103L ) && ( __cplusplus < 201702L ) +#if ( ( __cplusplus >= 201103L ) && ( __cplusplus < 201402L ) ) || \ + ( ( __cplusplus >= 201402L ) && ( __cplusplus < 201702L ) && defined( __STRICT_ANSI__ ) ) + namespace std { -#if defined( __STRICT_ANSI__ ) || ( __e2k__ ) template< typename ... Ts > struct make_void { typedef void type; }; template< typename ... Ts > using void_t = typename make_void< Ts... >::type; -#endif } // namespace std From 1053e703601cd4c21ed834f140b45fc31798efa3 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 9 Jul 2020 15:46:02 +0300 Subject: [PATCH 31/41] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/backports/qt/common.hpp | 2 +- src/myx/qt/posix_signal_watcher.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/myx/backports/qt/common.hpp b/src/myx/backports/qt/common.hpp index f225fb0..33cc259 100644 --- a/src/myx/backports/qt/common.hpp +++ b/src/myx/backports/qt/common.hpp @@ -7,7 +7,7 @@ #include #endif -#if (QT_VERSION <= 0x050700) +#if ( QT_VERSION <= 0x050700 ) template< typename ... Args > struct QOverload { diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp index a084347..8709e41 100644 --- a/src/myx/qt/posix_signal_watcher.cpp +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -63,7 +63,7 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) #if MYX_QT_HAS_POSIX_SIGNALS // Register a sigaction which will write to the socket pair - struct sigaction sigact {}; + struct sigaction sigact; sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; //NOLINT sigact.sa_flags = 0; sigemptyset( &sigact.sa_mask ); From f3c7ff25cfcc7c01a5961652a944e9857bdacafb Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 9 Jul 2020 15:46:50 +0300 Subject: [PATCH 32/41] =?UTF-8?q?=D0=9E=D1=82=D0=BC=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D0=BC=D0=B5=D1=80=D0=BE=D0=B2=20(=D0=B2=D1=80?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D0=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/core/01_endian/CMakeLists.txt | 2 +- examples/filesystem/01_paths/CMakeLists.txt | 2 +- examples/qt/01_translators/CMakeLists.txt | 2 +- examples/qt/02_posix-signal-watcher/CMakeLists.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/core/01_endian/CMakeLists.txt b/examples/core/01_endian/CMakeLists.txt index 41309ad..ada80fa 100644 --- a/examples/core/01_endian/CMakeLists.txt +++ b/examples/core/01_endian/CMakeLists.txt @@ -47,5 +47,5 @@ if(MYXLIB_BUILD_EXAMPLES) add_dependencies(${TRGT} create_auxilary_symlinks) # Правила для установки - install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + # install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/filesystem/01_paths/CMakeLists.txt b/examples/filesystem/01_paths/CMakeLists.txt index bc6c3a6..aa16e57 100644 --- a/examples/filesystem/01_paths/CMakeLists.txt +++ b/examples/filesystem/01_paths/CMakeLists.txt @@ -48,5 +48,5 @@ if(MYXLIB_BUILD_EXAMPLES) add_dependencies(${TRGT} create_auxilary_symlinks) # Правила для установки - install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + # install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/qt/01_translators/CMakeLists.txt b/examples/qt/01_translators/CMakeLists.txt index a90e559..c8be1ac 100644 --- a/examples/qt/01_translators/CMakeLists.txt +++ b/examples/qt/01_translators/CMakeLists.txt @@ -55,5 +55,5 @@ if(MYXLIB_BUILD_EXAMPLES) add_dependencies(${TRGT} create_auxilary_symlinks) # Правила для установки - install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + # install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/examples/qt/02_posix-signal-watcher/CMakeLists.txt b/examples/qt/02_posix-signal-watcher/CMakeLists.txt index 204cec2..ed49dbb 100644 --- a/examples/qt/02_posix-signal-watcher/CMakeLists.txt +++ b/examples/qt/02_posix-signal-watcher/CMakeLists.txt @@ -49,5 +49,5 @@ if(MYXLIB_BUILD_EXAMPLES) add_dependencies(${TRGT} create_auxilary_symlinks) # Правила для установки - install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + # install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() From f59e96bcaf38a88229d5f7fff7036b1c3dce5306 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 10 Jul 2020 11:08:33 +0300 Subject: [PATCH 33/41] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8=20=D1=81=20=D0=A1=D0=BC=D0=BE=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=81=D0=BA=201.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/backports/compiler/gcc.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/myx/backports/compiler/gcc.hpp b/src/myx/backports/compiler/gcc.hpp index 67a614b..15639d8 100644 --- a/src/myx/backports/compiler/gcc.hpp +++ b/src/myx/backports/compiler/gcc.hpp @@ -13,11 +13,10 @@ #pragma clang diagnostic ignored "-Wkeyword-macro" #endif -// NOLINTNEXTLINE +#if ( __cplusplus < 201103L ) #define override - -// NOLINTNEXTLINE -#define constexpr const +#define constexpr +#endif #ifdef __clang__ #pragma clang diagnostic pop From 45191907681f3d27281d4ce81dc8f4133c39f214 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 10 Jul 2020 11:13:02 +0300 Subject: [PATCH 34/41] =?UTF-8?q?=D0=95=D1=89=D1=91=20=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/backports/compiler/gcc.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/myx/backports/compiler/gcc.hpp b/src/myx/backports/compiler/gcc.hpp index 15639d8..c3e505c 100644 --- a/src/myx/backports/compiler/gcc.hpp +++ b/src/myx/backports/compiler/gcc.hpp @@ -14,10 +14,11 @@ #endif #if ( __cplusplus < 201103L ) -#define override #define constexpr #endif +#define override + #ifdef __clang__ #pragma clang diagnostic pop #endif From 3c628659bc891c4286444cac60f8e0601abcb3e4 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 10 Jul 2020 15:28:26 +0300 Subject: [PATCH 35/41] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=B8=D0=BD?= =?UTF-8?q?=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=BF=D1=83=D1=82=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/filesystem/paths.cpp | 56 +++++++++------ src/myx/filesystem/paths.hpp | 127 +++++++++++++++++++---------------- 2 files changed, 106 insertions(+), 77 deletions(-) diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index 9437a2c..c4d4677 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -13,7 +13,14 @@ namespace myx { namespace filesystem { -MYXLIB_INLINE Paths::Paths() = default; +MYXLIB_INLINE Paths::Paths() +{ + QFileInfo procSelfExe( QStringLiteral( "/proc/self/exe" ) ); + QFileInfo currentExecutable = procSelfExe.canonicalFilePath(); + m_executableName = currentExecutable.fileName(); + m_executableFilePath = currentExecutable.absoluteFilePath(); + m_executableDirectory = currentExecutable.absolutePath(); +} MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultPrefixDirectory, @@ -172,20 +179,8 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() } // Paths::getHierarchyType -MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& configFileExtension ) +MYXLIB_INLINE bool Paths::initCommon() { - QFileInfo procSelfExe( QStringLiteral( "/proc/self/exe" ) ); - QFileInfo currentExecutable = procSelfExe.canonicalFilePath(); - m_executableName = currentExecutable.fileName(); - m_executableFilePath = currentExecutable.absoluteFilePath(); - m_executableDirectory = currentExecutable.absolutePath(); - - m_projectName = projectDir.isEmpty() ? m_executableName - : projectDir; - m_configFileExtension = configFileExtension.isEmpty() ? QStringLiteral( "conf" ) - : configFileExtension; - m_configFileName = m_projectName + "." + m_configFileExtension; - m_homeDirectory = QDir::homePath(); m_tempDirectory = QDir::tempPath(); @@ -214,6 +209,33 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config } // Paths::updatePaths +MYXLIB_INLINE bool Paths::init() +{ + m_projectName = m_executableName; + m_configFileName = m_executableName + ".conf"; + return( initCommon() ); +} + + +MYXLIB_INLINE bool Paths::init( const QString& configFileName ) +{ + m_projectName = m_executableName; + m_configFileName = configFileName; + return( initCommon() ); +} + + +MYXLIB_INLINE bool Paths::init( const QString& projectName, const QString& configFileExtension ) +{ + m_projectName = projectName.isEmpty() ? m_executableName + : projectName; + auto ext = configFileExtension.isEmpty() ? QStringLiteral( "conf" ) + : configFileExtension; + m_configFileName = m_projectName + "." + ext; + return( initCommon() ); +} + + MYXLIB_INLINE bool Paths::makeDefaultDirectories() { bool status = true; @@ -281,12 +303,6 @@ MYXLIB_INLINE const QString& Paths::configFileName() const } -MYXLIB_INLINE const QString& Paths::configFileExtension() const -{ - return( m_configFileExtension ); -} - - MYXLIB_INLINE const QString& Paths::userVarDataDirectory() const { return( m_userVarDataDirectory ); diff --git a/src/myx/filesystem/paths.hpp b/src/myx/filesystem/paths.hpp index de22f4c..9baf284 100644 --- a/src/myx/filesystem/paths.hpp +++ b/src/myx/filesystem/paths.hpp @@ -44,62 +44,6 @@ class Paths kDevelopment = 0x07 }; - /// @brief Тип расположения файлов по каталогам - HierarchyType m_hierarchyType { HierarchyType::kFlat }; - - /// @brief Имя проекта, которое используется при формировании имён файлов и каталогов - QString m_projectName; - - QString m_executableName; - QString m_executableFilePath; - QString m_executableDirectory; - - /// @brief Общий префикс для файлов проекта - QString m_prefixDirectory; - - /// @brief Путь к каталогу с временными файлами - QString m_tempDirectory; - /// @brief Путь к домашнему каталогу текущего пользователя - QString m_homeDirectory; - - /// @brief Путь к пользовательскому каталогу с изменяемыми файлами - QString m_userVarDataDirectory; - /// @brief Путь к системному каталогу с изменяемыми файлами - QString m_systemVarDataDirectory; - - /// @brief Путь к пользовательскому каталогу с неизменяемыми файлами - QString m_userConstDataDirectory; - /// @brief Путь к системному каталогу с неизменяемыми файлами - QString m_systemConstDataDirectory; - - /// @brief Путь к пользовательскому каталогу с журналами работы - QString m_userLogDirectory; - /// @brief Путь к системному каталогу с журналами работы - QString m_systemLogDirectory; - - /// @brief Путь к пользовательскому каталогу с файлами настройки - QString m_userConfigDirectory; - /// @brief Путь к системному каталогу с файлами настройки - QString m_systemConfigDirectory; - - /// @brief Полный путь к файлу настройки - QString m_configFilePath; - /// @brief Имя файла настройки - QString m_configFileName; - /// @brief Расширение для файла настройки - QString m_configFileExtension; - - void setupSystemDirectories( const QString& defaultPrefixDirectory, - const QString& defaultEtcDirectory, - const QString& defaultConstDataDirectory, - const QString& defaultVarDataDirectory, - const QString& defaultLogDirectory ); - HierarchyType getHierarchyType(); - -protected: - Paths(); - ~Paths() = default; - public: Paths( const Paths& ) = delete; Paths& operator=( const Paths& ) = delete; @@ -120,7 +64,20 @@ public: /** * @brief Обновление путей с учётом расположения исполняемого файла */ - bool init( const QString& projectDir, const QString& configFileExtension = QStringLiteral("conf") ); + bool init(); + + /** + * @brief Обновление путей с учётом расположения исполняемого файла + * @param configFileName Имя файла настроек + */ + bool init( const QString& configFileName ); + + /** + * @brief Обновление путей с учётом расположения исполняемого файла + * @param projectName Имя проекта + * @param configFileExtension Расширение для файла настроек + */ + bool init( const QString& projectName, const QString& configFileExtension ); /** * @brief Создание стандартных каталогов @@ -226,6 +183,62 @@ public: * @brief Имя подкаталога для проекта */ const QString& projectName() const; + +protected: + Paths(); + ~Paths() = default; + +private: + /// @brief Тип расположения файлов по каталогам + HierarchyType m_hierarchyType { HierarchyType::kFlat }; + + /// @brief Имя проекта, которое используется при формировании имён файлов и каталогов + QString m_projectName; + + QString m_executableName; + QString m_executableFilePath; + QString m_executableDirectory; + + /// @brief Общий префикс для файлов проекта + QString m_prefixDirectory; + + /// @brief Путь к каталогу с временными файлами + QString m_tempDirectory; + /// @brief Путь к домашнему каталогу текущего пользователя + QString m_homeDirectory; + + /// @brief Путь к пользовательскому каталогу с изменяемыми файлами + QString m_userVarDataDirectory; + /// @brief Путь к системному каталогу с изменяемыми файлами + QString m_systemVarDataDirectory; + + /// @brief Путь к пользовательскому каталогу с неизменяемыми файлами + QString m_userConstDataDirectory; + /// @brief Путь к системному каталогу с неизменяемыми файлами + QString m_systemConstDataDirectory; + + /// @brief Путь к пользовательскому каталогу с журналами работы + QString m_userLogDirectory; + /// @brief Путь к системному каталогу с журналами работы + QString m_systemLogDirectory; + + /// @brief Путь к пользовательскому каталогу с файлами настройки + QString m_userConfigDirectory; + /// @brief Путь к системному каталогу с файлами настройки + QString m_systemConfigDirectory; + + /// @brief Полный путь к файлу настройки + QString m_configFilePath; + /// @brief Имя файла настройки + QString m_configFileName; + + void setupSystemDirectories( const QString& defaultPrefixDirectory, + const QString& defaultEtcDirectory, + const QString& defaultConstDataDirectory, + const QString& defaultVarDataDirectory, + const QString& defaultLogDirectory ); + bool initCommon(); + HierarchyType getHierarchyType(); }; // class Paths } // namespace filesystem From 078732d3080a3ce1c791e94758acd99504ee914d Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 10 Jul 2020 15:29:51 +0300 Subject: [PATCH 36/41] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/qt/posix_signal_watcher.cpp | 5 +++-- src/myx/qt/translators.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp index 8709e41..fa98ff2 100644 --- a/src/myx/qt/posix_signal_watcher.cpp +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -1,8 +1,8 @@ #ifndef MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ #define MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ -#include #include +#include #include #include @@ -67,7 +67,8 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; //NOLINT sigact.sa_flags = 0; sigemptyset( &sigact.sa_mask ); - sigact.sa_flags |= SA_RESTART; + sigact.sa_flags |= SA_RESTART; + sigact.sa_restorer = nullptr; if ( ::sigaction( signal, &sigact, nullptr ) != 0 ) { qDebug() << "PosixSignalWatcher: sigaction: " << ::strerror( errno ); diff --git a/src/myx/qt/translators.cpp b/src/myx/qt/translators.cpp index d04ceca..1fd5beb 100644 --- a/src/myx/qt/translators.cpp +++ b/src/myx/qt/translators.cpp @@ -1,8 +1,8 @@ #ifndef MYX_QT_TRANSLATORS_CPP_ #define MYX_QT_TRANSLATORS_CPP_ -#include #include +#include #include From d951fd81cb4830781eda1b7edb42a4204266dc0a Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Wed, 22 Jul 2020 15:57:41 +0300 Subject: [PATCH 37/41] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B4=D1=83=D0=BF=D1=80=D0=B5=D0=B6=D0=B4?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/backports/cpp/span.hpp | 2 +- src/myx/qt/posix_signal_watcher.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/myx/backports/cpp/span.hpp b/src/myx/backports/cpp/span.hpp index 6cf6339..ac09b51 100644 --- a/src/myx/backports/cpp/span.hpp +++ b/src/myx/backports/cpp/span.hpp @@ -144,7 +144,7 @@ public: * @param container The container to assign from */ template< class ContiguousContainer > - typename std::enable_if< is_contiguous_container< + typename std::enable_if< is_contiguous_container< //NOLINT ContiguousContainer, T >::value, span& >::type operator=( ContiguousContainer&& container ) diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp index fa98ff2..4d5cc7d 100644 --- a/src/myx/qt/posix_signal_watcher.cpp +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -37,7 +37,7 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : Q_Q( PosixSignalWatcher ); int signal = 0; - (void)::read( sockfd, &signal, sizeof( signal ) ); + Q_UNUSED( !::read( sockfd, &signal, sizeof( signal ) ) ); qDebug() << "Caught signal: " << ::strsignal( signal ); Q_EMIT q->posixSignal( signal ); } ); @@ -63,7 +63,7 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) #if MYX_QT_HAS_POSIX_SIGNALS // Register a sigaction which will write to the socket pair - struct sigaction sigact; + struct sigaction sigact; //NOLINT sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; //NOLINT sigact.sa_flags = 0; sigemptyset( &sigact.sa_mask ); @@ -86,7 +86,7 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) */ MYXLIB_INLINE void PosixSignalWatcherPrivate::signalHandler( int signal ) { - (void)::write( mSockpair[0], &signal, sizeof( signal ) ); + Q_UNUSED( !::write( mSockpair[0], &signal, sizeof( signal ) ) ); } From c418aa8df0005c5d3a2dca379c10c30937f24392 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 23 Jul 2020 10:23:42 +0300 Subject: [PATCH 38/41] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/cmlib | 2 +- src/myx/qt/posix_signal_watcher.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmake/cmlib b/cmake/cmlib index 186d67c..5c90828 160000 --- a/cmake/cmlib +++ b/cmake/cmlib @@ -1 +1 @@ -Subproject commit 186d67c4bbc2fa91ecfd837d753631610aff0b1d +Subproject commit 5c90828e4e189e78fce1d93bf1700519e7aff76c diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp index 8709e41..e918b8a 100644 --- a/src/myx/qt/posix_signal_watcher.cpp +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -16,16 +16,16 @@ std::array< int, 2 > PosixSignalWatcherPrivate::mSockpair { { 0, 0 } }; PosixSignalWatcherPrivate::~PosixSignalWatcherPrivate() = default; PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : - q_ptr( q ) + q_ptr( q ) { - #if MYX_QT_HAS_POSIX_SIGNALS + #if MYX_QT_HAS_POSIX_SIGNALS // Create socket pair if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, mSockpair.data() ) != 0 ) { qDebug() << "PosixSignalWatcher: socketpair: " << ::strerror( errno ); return; } - #endif + #endif // Create a notifier for the read end of the pair // m_notifier.reset( new QSocketNotifier( mSockpair[1], QSocketNotifier::Read ) ); @@ -37,7 +37,7 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : Q_Q( PosixSignalWatcher ); int signal = 0; - (void)::read( sockfd, &signal, sizeof( signal ) ); + (void)!::read( sockfd, &signal, sizeof( signal ) ); qDebug() << "Caught signal: " << ::strsignal( signal ); Q_EMIT q->posixSignal( signal ); } ); @@ -61,7 +61,7 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) return; } - #if MYX_QT_HAS_POSIX_SIGNALS + #if MYX_QT_HAS_POSIX_SIGNALS // Register a sigaction which will write to the socket pair struct sigaction sigact; sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; //NOLINT @@ -73,7 +73,7 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) qDebug() << "PosixSignalWatcher: sigaction: " << ::strerror( errno ); return; } - #endif + #endif m_watchedSignals.append( signal ); } // PosixSignalWatcherPrivate::watchForSignal @@ -85,7 +85,7 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) */ MYXLIB_INLINE void PosixSignalWatcherPrivate::signalHandler( int signal ) { - (void)::write( mSockpair[0], &signal, sizeof( signal ) ); + (void)!::write( mSockpair[0], &signal, sizeof( signal ) ); } @@ -93,8 +93,8 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::signalHandler( int signal ) * Create a new PosixSignalWatcher as a child of the given \a parent. */ MYXLIB_INLINE PosixSignalWatcher::PosixSignalWatcher( QObject* parent ) : - QObject( parent ), - d_ptr ( new PosixSignalWatcherPrivate( this ) ) + QObject( parent ), + d_ptr ( new PosixSignalWatcherPrivate( this ) ) { } From ee681940c56d6c3dbb73d37dc86e044411ca7b82 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Mon, 3 Aug 2020 15:19:05 +0300 Subject: [PATCH 39/41] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/cmlib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/cmlib b/cmake/cmlib index 5c90828..e3600e9 160000 --- a/cmake/cmlib +++ b/cmake/cmlib @@ -1 +1 @@ -Subproject commit 5c90828e4e189e78fce1d93bf1700519e7aff76c +Subproject commit e3600e96ce859625abbcbcede84c81ca3c3da765 From c5a9b5118b4d0132aa05a5afe82395d9466e483d Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 24 Sep 2020 13:12:23 +0300 Subject: [PATCH 40/41] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/find | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/find b/cmake/find index 00bbf68..bb640e3 160000 --- a/cmake/find +++ b/cmake/find @@ -1 +1 @@ -Subproject commit 00bbf686cdb5bd32ba7105bec1234c85aee6f0aa +Subproject commit bb640e3cf2f287643db784df519d23ddf0a6f1f4 From 7c2d52172cbb811a268bc837f314e4dfc6693306 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Mon, 12 Oct 2020 16:47:42 +0300 Subject: [PATCH 41/41] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/cmlib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/cmlib b/cmake/cmlib index e3600e9..39111c8 160000 --- a/cmake/cmlib +++ b/cmake/cmlib @@ -1 +1 @@ -Subproject commit e3600e96ce859625abbcbcede84c81ca3c3da765 +Subproject commit 39111c890acb8a7dc0c2d861deeb600b7704752b