Compare commits
32 Commits
a27f18d7b6
...
2901c5c04e
Author | SHA1 | Date | |
---|---|---|---|
2901c5c04e | |||
e160b83c45 | |||
7ec97f8f19 | |||
a39e514278 | |||
df9b2ff599 | |||
a168e29d8d | |||
76a655aa6c | |||
ce596d8113 | |||
c38781b2e7 | |||
a1d34d4c32 | |||
d687dd8e98 | |||
6e43742b2c | |||
e09a7f4e3e | |||
7bb28946de | |||
b6d33b8c29 | |||
5a6cc75a58 | |||
347920ed36 | |||
f87e6207d2 | |||
189d85719e | |||
4f507da585 | |||
691b768c94 | |||
f740a21d8f | |||
ff188d68aa | |||
e27d6c4476 | |||
47885c73ab | |||
d030ee5a44 | |||
96c1619148 | |||
8f7a08bea6 | |||
44466b80de | |||
4069aaf315 | |||
97554275b2 | |||
b2c786edeb |
42
.clang-tidy
42
.clang-tidy
@ -1,5 +1,25 @@
|
||||
---
|
||||
Checks: '-*,bugprone-*,cppcoreguidelines-*,google-*,clang-analyzer-*,misc-*,modernize-*,readability-*,performance-*,portability-*,readability-identifier-naming,-cppcoreguidelines-owning-memory'
|
||||
Checks: '-*,
|
||||
bugprone-*,
|
||||
clang-analyzer-*,
|
||||
cppcoreguidelines-*,
|
||||
google-*,
|
||||
llvm-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
readability-*,
|
||||
performance-*,
|
||||
portability-*,
|
||||
-cppcoreguidelines-owning-memory,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||
-readability-magic-numbers,
|
||||
-readability-else-after-return,
|
||||
-modernize-use-trailing-return-type,
|
||||
-modernize-avoid-c-arrays,
|
||||
-performance-no-automatic-move,
|
||||
'
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.AbstractClassCase
|
||||
value: CamelCase
|
||||
@ -14,9 +34,9 @@ CheckOptions:
|
||||
- key: readability-identifier-naming.ClassSuffix
|
||||
value: ''
|
||||
- key: readability-identifier-naming.ClassConstantCase
|
||||
value: UPPER_CASE
|
||||
value: CamelCase
|
||||
- key: readability-identifier-naming.ClassConstantPrefix
|
||||
value: ''
|
||||
value: 'k_'
|
||||
- key: readability-identifier-naming.ClassConstantSuffix
|
||||
value: ''
|
||||
- key: readability-identifier-naming.ClassMemberCase
|
||||
@ -32,9 +52,9 @@ CheckOptions:
|
||||
- key: readability-identifier-naming.ClassMethodSuffix
|
||||
value: ''
|
||||
- key: readability-identifier-naming.ConstantCase
|
||||
value: UPPER_CASE
|
||||
value: CamelCase
|
||||
- key: readability-identifier-naming.ConstantPrefix
|
||||
value: PRE
|
||||
value: 'k_'
|
||||
- key: readability-identifier-naming.ConstantSuffix
|
||||
value: POST
|
||||
- key: readability-identifier-naming.ConstantMemberCase
|
||||
@ -80,9 +100,9 @@ CheckOptions:
|
||||
- key: readability-identifier-naming.EnumSuffix
|
||||
value: ''
|
||||
- key: readability-identifier-naming.EnumConstantCase
|
||||
value: UPPER_CASE
|
||||
value: CamelCase
|
||||
- key: readability-identifier-naming.EnumConstantPrefix
|
||||
value: ''
|
||||
value: 'k_'
|
||||
- key: readability-identifier-naming.EnumConstantSuffix
|
||||
value: ''
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
@ -92,9 +112,9 @@ CheckOptions:
|
||||
- key: readability-identifier-naming.FunctionSuffix
|
||||
value: ''
|
||||
- key: readability-identifier-naming.GlobalConstantCase
|
||||
value: UPPER_CASE
|
||||
value: CamelCase
|
||||
- key: readability-identifier-naming.GlobalConstantPrefix
|
||||
value: ''
|
||||
value: 'k_'
|
||||
- key: readability-identifier-naming.GlobalConstantSuffix
|
||||
value: ''
|
||||
- key: readability-identifier-naming.GlobalConstantPointerCase
|
||||
@ -130,7 +150,7 @@ CheckOptions:
|
||||
- key: readability-identifier-naming.LocalConstantCase
|
||||
value: camelBack
|
||||
- key: readability-identifier-naming.LocalConstantPrefix
|
||||
value: ''
|
||||
value: 'k_'
|
||||
- key: readability-identifier-naming.LocalConstantSuffix
|
||||
value: ''
|
||||
- key: readability-identifier-naming.LocalConstantPointerCase
|
||||
@ -226,7 +246,7 @@ CheckOptions:
|
||||
- key: readability-identifier-naming.StaticConstantCase
|
||||
value: camelBack
|
||||
- key: readability-identifier-naming.StaticConstantPrefix
|
||||
value: ''
|
||||
value: 'k_'
|
||||
- key: readability-identifier-naming.StaticConstantSuffix
|
||||
value: ''
|
||||
- key: readability-identifier-naming.StaticVariableCase
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,3 +2,6 @@ CMakeLists.txt.user*
|
||||
_build
|
||||
_output
|
||||
*.autosave
|
||||
files/lib/*
|
||||
files/log/*
|
||||
|
||||
|
@ -10,6 +10,9 @@ orel212-nightly:
|
||||
bionic-nightly:
|
||||
extends: .scheduled-bionic
|
||||
|
||||
focal-nightly:
|
||||
extends: .scheduled-focal
|
||||
|
||||
elbrus-nightly:
|
||||
extends: .scheduled-elbrus
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
variables:
|
||||
GIT_SUBMODULE_STRATEGY: recursive
|
||||
GET_SOURCES_ATTEMPTS: 10
|
||||
|
||||
.scheduled-test:
|
||||
only:
|
||||
@ -66,6 +67,11 @@ variables:
|
||||
image: bionic-dev
|
||||
tags: ['docker']
|
||||
|
||||
.scheduled-focal:
|
||||
extends: .scheduled-test
|
||||
image: focal-dev
|
||||
tags: ['docker']
|
||||
|
||||
.scheduled-elbrus:
|
||||
extends: .scheduled-test
|
||||
tags: ['elbrus']
|
||||
|
@ -20,6 +20,10 @@ option(BUILD_EXAMPLES "Build examples" OFF)
|
||||
# Поиск библиотек с помощью pkgconfig
|
||||
find_package(PkgConfig)
|
||||
|
||||
# Потоки
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# Qt5
|
||||
find_package(Qt5 COMPONENTS Core Network Gui Widgets DBus Concurrent Sql REQUIRED)
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 9719383c86dd3789f9fb34eff36967262188257f
|
||||
Subproject commit c9c13df5527f59c4f9eff6229152205aa296605b
|
@ -1 +1 @@
|
||||
Subproject commit b5e3fb02619418d2e574232033e3df37be99212e
|
||||
Subproject commit bab7df69d9fdf1f22db7b2173c9f1f40de2c476b
|
@ -1 +1 @@
|
||||
Subproject commit 878e1d8a27f1512d5c39fb8fdad467ba5f6d8285
|
||||
Subproject commit eb34f3ffb32205b382c4ee56de890b5de9371fa7
|
@ -27,13 +27,13 @@ add_dependencies(${current_target} filesystem)
|
||||
# Qt5
|
||||
# qt_translation(TARGET ${current_target} TS_DIR ${CMAKE_SOURCE_DIR}/l10n LANGUAGES ru_RU)
|
||||
target_include_directories(${current_target} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${FMT_INCLUDE_DIRS})
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${SPDLOG_INCLUDE_DIRS})
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
target_compile_options(${current_target} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
|
||||
|
||||
target_link_libraries(${current_target} myx-filesystem)
|
||||
target_link_libraries(${current_target} Qt5::Core)
|
||||
target_link_libraries(${current_target} Threads::Threads)
|
||||
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${current_target}
|
||||
@ -46,5 +46,7 @@ add_sanitizers(${current_target})
|
||||
|
||||
# cotire(${current_target})
|
||||
|
||||
add_dependencies(${current_target} create_auxilary_symlinks)
|
||||
|
||||
# Правила для установки
|
||||
install(TARGETS ${current_target} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
@ -1,22 +1,36 @@
|
||||
#include "cmlib_private_config.hpp"
|
||||
|
||||
#include <myx/base/config.hpp>
|
||||
|
||||
#include <myx/filesystem/paths.hpp>
|
||||
#include <myx/filesystem/paths_mt.hpp>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
namespace MF = myx::filesystem;
|
||||
|
||||
// Переменные для защиты экземпляра класса MF::PathsMT
|
||||
std::atomic< MF::PathsMT* > MF::PathsMT::mInstance;
|
||||
std::mutex MF::PathsMT::mMutex;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
QCoreApplication::setApplicationName( PROJECT_NAME );
|
||||
MF::Paths paths;
|
||||
QCoreApplication::setApplicationName( QStringLiteral( CMLIB_PROJECT_NAME ) );
|
||||
MF::PathsMT& pathsMT = MF::PathsMT::instance();
|
||||
MF::Paths& paths = MF::Paths::instance();
|
||||
|
||||
paths.updatePaths();
|
||||
paths.makeDefaultDirectories();
|
||||
paths.findConfigFile( "test" );
|
||||
pathsMT.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) );
|
||||
pathsMT.findConfigFile( QStringLiteral( "test" ) );
|
||||
qDebug() << pathsMT.systemLogDirectory();
|
||||
qDebug() << pathsMT.systemConfigDirectory();
|
||||
|
||||
paths.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) );
|
||||
paths.findConfigFile( QStringLiteral( "test" ) );
|
||||
qDebug() << paths.systemConstDataDirectory();
|
||||
qDebug() << paths.configFileName();
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -25,10 +25,8 @@ add_dependencies(${current_target} base)
|
||||
add_dependencies(${current_target} qt)
|
||||
|
||||
# Qt5
|
||||
qt_translation(TARGET ${current_target} TS_DIR ${CMAKE_SOURCE_DIR}/l10n LANGUAGES ru_RU)
|
||||
qt5_translation(TARGET ${current_target} TS_DIR ${CMAKE_SOURCE_DIR}/l10n LANGUAGES ru_RU)
|
||||
target_include_directories(${current_target} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${FMT_INCLUDE_DIRS})
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${SPDLOG_INCLUDE_DIRS})
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
target_compile_options(${current_target} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
|
||||
|
||||
@ -46,5 +44,7 @@ add_sanitizers(${current_target})
|
||||
|
||||
# cotire(${current_target})
|
||||
|
||||
add_dependencies(${current_target} create_auxilary_symlinks)
|
||||
|
||||
# Правила для установки
|
||||
install(TARGETS ${current_target} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
@ -12,7 +12,7 @@ int main( int argc, char** argv )
|
||||
MQ::QTranslatorsList tl;
|
||||
|
||||
qDebug() << QObject::tr( "Yes" );
|
||||
MQ::append_translators( tl, "example-qt-translators" );
|
||||
MQ::append_translators( tl, QStringLiteral( "example-qt-translators" ) );
|
||||
qDebug() << QObject::tr( "Yes" );
|
||||
|
||||
return( 0 );
|
||||
|
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 86 KiB |
0
files/etc/myx.conf
Normal file
0
files/etc/myx.conf
Normal file
0
files/lib/.keep-directory
Normal file
0
files/lib/.keep-directory
Normal file
0
files/log/.keep-directory
Normal file
0
files/log/.keep-directory
Normal file
@ -8,6 +8,8 @@ set(current_target_sources
|
||||
# Список заголовочных файлов (используется для установки)
|
||||
set(current_target_headers
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/config.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/limits.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/enum_bitmask_operations.hpp
|
||||
)
|
||||
|
||||
add_common_library(TARGET ${current_target} OUTPUT_NAME myx-${current_target}
|
||||
@ -40,8 +42,7 @@ install(TARGETS ${current_target}_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIB
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(TARGETS ${current_target}_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
install(FILES ${CMAKE_BINARY_DIR}/include/cmlib_config.hpp
|
||||
${CMAKE_BINARY_DIR}/include/config_flags.hpp
|
||||
install(FILES ${CMAKE_BINARY_DIR}/include/config_flags.hpp
|
||||
${current_target_headers}
|
||||
COMPONENT headers
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${current_target})
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef MYX_BASE_CONFIG_HPP_
|
||||
#define MYX_BASE_CONFIG_HPP_
|
||||
|
||||
#include "cmlib_config.hpp"
|
||||
#include "config_flags.hpp"
|
||||
|
||||
#endif // MYX_BASE_CONFIG_HPP_
|
||||
|
58
src/myx/base/enum_bitmask_operations.hpp
Normal file
58
src/myx/base/enum_bitmask_operations.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
||||
#define MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace base {
|
||||
|
||||
template< typename Enum >
|
||||
struct EnableBitMaskOperators
|
||||
{
|
||||
static const bool enable = false;
|
||||
};
|
||||
|
||||
template< typename Enum >
|
||||
typename std::enable_if< EnableBitMaskOperators< Enum >::enable, 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 )
|
||||
) );
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
|
||||
} // namespace myx
|
||||
|
||||
/**
|
||||
* @brief Макрос, предоставляющий возможность выполнять битовые операции в enum class
|
||||
*
|
||||
* Источник: http://blog.bitwigglers.org/using-enum-classes-as-type-safe-bitmasks/
|
||||
* Пример использования:
|
||||
*
|
||||
* namespace ns {
|
||||
* enum class Permissions
|
||||
* {
|
||||
* Readable = 0x4,
|
||||
* Writeable = 0x2,
|
||||
* Executable = 0x1
|
||||
* };
|
||||
* }
|
||||
* ENABLE_BITMASK_OPERATORS(ns::Permissions)
|
||||
*/
|
||||
|
||||
#define ENABLE_BITMASK_OPERATORS( x ) \
|
||||
template<> \
|
||||
struct myx::base::EnableBitMaskOperators< x > \
|
||||
{ \
|
||||
static const bool enable = true; \
|
||||
};
|
||||
|
||||
#endif // ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
31
src/myx/base/limits.hpp
Normal file
31
src/myx/base/limits.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef MYX_BASE_LIMITS_HPP_
|
||||
#define MYX_BASE_LIMITS_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace base {
|
||||
|
||||
/**
|
||||
* @brief Константа, представляющая значение, не являющееся числом, для типа float
|
||||
*/
|
||||
constexpr float k_FloatNAN { std::numeric_limits< float >::quiet_NaN() };
|
||||
|
||||
/**
|
||||
* @brief Константа, представляющая значение, не являющееся числом, для типа double
|
||||
*/
|
||||
constexpr double k_DoubleNAN { std::numeric_limits< double >::quiet_NaN() };
|
||||
|
||||
/**
|
||||
* @brief Константа, представляющая значение, не являющееся числом, для типа long double
|
||||
*/
|
||||
constexpr double k_LongDoubleNAN { std::numeric_limits< long double >::quiet_NaN() };
|
||||
|
||||
} // namespace base
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // MYX_BASE_LIMITS_HPP_
|
@ -5,12 +5,14 @@ set(current_target filesystem)
|
||||
set(current_target_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/current_executable.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/paths_mt.cpp
|
||||
)
|
||||
|
||||
# Список заголовочных файлов (используется для установки)
|
||||
set(current_target_headers
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/current_executable.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/paths.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/paths_mt.hpp
|
||||
)
|
||||
|
||||
add_common_library(TARGET ${current_target}
|
||||
|
@ -1,43 +1,31 @@
|
||||
#include "current_executable.hpp"
|
||||
|
||||
#include <myx/base/config.hpp>
|
||||
#include <myx/filesystem/current_executable.hpp>
|
||||
|
||||
#include <paths.h>
|
||||
#include <QString>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
#if !defined ( __linux__ )
|
||||
error "Class CurrentExecutable is supported only in Linux"
|
||||
#endif
|
||||
|
||||
CurrentExecutable::CurrentExecutable() :
|
||||
m_procFilePath( "/proc/self/exe" )
|
||||
m_procFilePath( QStringLiteral( "/proc/self/exe" ) )
|
||||
{
|
||||
auto canonicalFilePath = m_procFilePath.canonicalFilePath();
|
||||
auto canonicalPath = m_procFilePath.canonicalPath();
|
||||
m_fileName = canonicalFilePath.remove( canonicalPath ).remove( '/' );
|
||||
m_canonicalFilePath = canonicalFilePath;
|
||||
m_canonicalPath = canonicalPath;
|
||||
m_canonicalFilePath = m_procFilePath.canonicalFilePath();
|
||||
}
|
||||
|
||||
|
||||
QFileInfo CurrentExecutable::canonicalFilePath() const
|
||||
const QFileInfo& CurrentExecutable::canonicalFilePath() const
|
||||
{
|
||||
return( m_canonicalFilePath );
|
||||
}
|
||||
|
||||
|
||||
QDir CurrentExecutable::canonicalPath() const
|
||||
{
|
||||
return( m_canonicalPath );
|
||||
}
|
||||
|
||||
|
||||
QString CurrentExecutable::fileName() const
|
||||
{
|
||||
return( m_fileName );
|
||||
}
|
||||
|
||||
} // namespace filesystem
|
||||
|
||||
} // namespace myx
|
||||
|
@ -1,48 +1,41 @@
|
||||
/**
|
||||
* @file current_executable.hpp
|
||||
* @brief Параметры исполняемового файла
|
||||
* @brief Параметры исполняемого файла
|
||||
*/
|
||||
|
||||
#ifndef MYX_FILESYSTEM_CURRENT_EXECUTABLE_HPP_
|
||||
#define MYX_FILESYSTEM_CURRENT_EXECUTABLE_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
class CurrentExecutable
|
||||
{
|
||||
/// Путь к символической ссылке, указывающей на текущий исполняемый файл
|
||||
/// @brief Путь к символической ссылке, указывающей на текущий исполняемый файл
|
||||
QFileInfo m_procFilePath;
|
||||
/// Канонический путь к текущему исполняемому файлу
|
||||
QFileInfo m_canonicalFilePath;
|
||||
/// Канонический путь к каталогу с текущим исполняемым файлом
|
||||
QDir m_canonicalPath;
|
||||
/// Имя текущего исполняемого файла
|
||||
QString m_fileName;
|
||||
|
||||
/// @brief Канонический путь к текущему исполняемому файлу
|
||||
QFileInfo m_canonicalFilePath;
|
||||
|
||||
friend class Paths;
|
||||
public:
|
||||
/**
|
||||
* @brief Конструктор, собирающий информацию о текущем исполняемом файле.
|
||||
* Иницализируются все внутренние переменные.
|
||||
*/
|
||||
CurrentExecutable();
|
||||
|
||||
/**
|
||||
* @brief Канонический путь к текущему исполняемому файлу
|
||||
*/
|
||||
QFileInfo canonicalFilePath() const;
|
||||
/**
|
||||
* @brief Канонический путь к каталогу с текущим исполняемым файлом
|
||||
*/
|
||||
QDir canonicalPath() const;
|
||||
/**
|
||||
* @brief Имя текущего исполняемого файла
|
||||
*/
|
||||
QString fileName() const;
|
||||
const QFileInfo& canonicalFilePath() const;
|
||||
}; // class CurrentExecutable
|
||||
|
||||
} // namespace filesystem
|
||||
|
@ -1,211 +1,165 @@
|
||||
#include "paths.hpp"
|
||||
|
||||
#include <myx/base/config.hpp>
|
||||
#include <myx/filesystem/current_executable.hpp>
|
||||
#include <myx/filesystem/paths.hpp>
|
||||
|
||||
#include <paths.h>
|
||||
#include <QString>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
QString Paths::executableFileName() const
|
||||
Paths::Paths() = default;
|
||||
|
||||
Paths::HierarchyType Paths::getHierarchyType()
|
||||
{
|
||||
return( m_currentExecutable.fileName() );
|
||||
}
|
||||
QRegExp binRegexp( "/s*bin$" );
|
||||
auto binaryDir = m_currentExecutable.m_canonicalFilePath.canonicalPath();
|
||||
|
||||
|
||||
QString Paths::configFileName() const
|
||||
{
|
||||
return( m_configFileName );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setConfigFileName( const QString& configFileName )
|
||||
{
|
||||
m_configFileName = configFileName;
|
||||
}
|
||||
|
||||
|
||||
QFileInfo Paths::executableFilePath() const
|
||||
{
|
||||
return( m_currentExecutable.canonicalFilePath() );
|
||||
}
|
||||
|
||||
|
||||
QFileInfo Paths::configFilePath() const
|
||||
{
|
||||
return( m_configFilePath );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setConfigFilePath( const QFileInfo& configFilePath )
|
||||
{
|
||||
m_configFilePath = configFilePath;
|
||||
}
|
||||
|
||||
|
||||
QDir Paths::logDirectory() const
|
||||
{
|
||||
return( m_logDirectory );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setLogDirectory( const QString& logDirectory )
|
||||
{
|
||||
m_logDirectory = logDirectory;
|
||||
}
|
||||
|
||||
|
||||
Paths::Paths( const QString& configFileExtension ) :
|
||||
m_configFileExtension( configFileExtension )
|
||||
|
||||
{
|
||||
m_prefixDirectory = "/opt/" + QCoreApplication::organizationName().toLower() +
|
||||
"/" + QCoreApplication::applicationName().toLower();
|
||||
auto pd = m_prefixDirectory.absolutePath();
|
||||
m_binaryDirectory = pd + "/bin";
|
||||
m_configDirectory = pd + "/etc";
|
||||
m_cacheDirectory = pd + "/var";
|
||||
m_logDirectory = pd + "/var/log";
|
||||
m_tempDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "TMPDIR" ) ) );
|
||||
m_dataDirectory = pd + "/share";
|
||||
m_homeDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "HOME" ) ) );
|
||||
m_configFileName = QCoreApplication::applicationName().toLower() +
|
||||
"." + m_configFileExtension;
|
||||
m_configFilePath = m_binaryDirectory.absolutePath() +
|
||||
"/" + m_configFileName;
|
||||
|
||||
|
||||
if ( m_tempDirectory.absolutePath().isEmpty() || ( m_tempDirectory.path() == "." ) )
|
||||
if ( binRegexp.indexIn( binaryDir ) == -1 )
|
||||
{
|
||||
m_tempDirectory = _PATH_TMP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QDir Paths::prefixDirectory() const
|
||||
{
|
||||
return( m_prefixDirectory );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setPrefixDirectory( const QString& prefixDirectory )
|
||||
{
|
||||
m_prefixDirectory = prefixDirectory;
|
||||
}
|
||||
|
||||
|
||||
QDir Paths::binaryDirectory() const
|
||||
{
|
||||
return( m_binaryDirectory );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setBinaryDirectory( const QString& binaryDirectory )
|
||||
{
|
||||
m_binaryDirectory = binaryDirectory;
|
||||
}
|
||||
|
||||
|
||||
QDir Paths::configDirectory() const
|
||||
{
|
||||
return( m_configDirectory );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setConfigDirectory( const QString& configDirectory )
|
||||
{
|
||||
m_configDirectory = configDirectory;
|
||||
}
|
||||
|
||||
|
||||
QDir Paths::cacheDirectory() const
|
||||
{
|
||||
return( m_cacheDirectory );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setCacheDirectory( const QString& cacheDirectory )
|
||||
{
|
||||
m_cacheDirectory = cacheDirectory;
|
||||
}
|
||||
|
||||
|
||||
QDir Paths::tempDirectory() const
|
||||
{
|
||||
return( m_tempDirectory );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setTempDirectory( const QString& tempDirectory )
|
||||
{
|
||||
m_tempDirectory = tempDirectory;
|
||||
}
|
||||
|
||||
|
||||
QDir Paths::dataDirectory() const
|
||||
{
|
||||
return( m_dataDirectory );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setDataDirectory( const QString& dataDirectory )
|
||||
{
|
||||
m_dataDirectory = dataDirectory;
|
||||
}
|
||||
|
||||
|
||||
bool Paths::updatePaths()
|
||||
{
|
||||
m_binaryDirectory = m_currentExecutable.canonicalPath();
|
||||
|
||||
if ( m_binaryDirectory.absolutePath().endsWith( "/bin" ) )
|
||||
{
|
||||
m_prefixDirectory = m_binaryDirectory.absolutePath().remove( QRegExp( "/bin$" ) );
|
||||
m_configDirectory = m_prefixDirectory.absolutePath() + "/etc";
|
||||
m_cacheDirectory = m_prefixDirectory.absolutePath() + "/var";
|
||||
m_logDirectory = m_prefixDirectory.absolutePath() + "/var/log";
|
||||
m_dataDirectory = m_prefixDirectory.absolutePath() + "/share";
|
||||
m_configFilePath = QFile( m_configDirectory.absolutePath() +
|
||||
"/" + QCoreApplication::applicationName() +
|
||||
"." + m_configFileExtension );
|
||||
return ( HierarchyType::kFlat );
|
||||
}
|
||||
|
||||
if ( m_prefixDirectory.absolutePath().startsWith( "/opt" ) ||
|
||||
m_prefixDirectory.absolutePath().startsWith( "/usr" ) )
|
||||
QRegExp optRegexp( "^/opt(/|/.+/)" + m_projectName + "/" );
|
||||
|
||||
if ( optRegexp.indexIn( binaryDir ) >= 0 )
|
||||
{
|
||||
QString dataDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "XDG_DATA_HOME" ) ) );
|
||||
if ( dataDirectory.isEmpty() )
|
||||
{
|
||||
dataDirectory = m_homeDirectory.absolutePath() + ".local/share";
|
||||
}
|
||||
m_dataDirectory = dataDirectory + "/" +
|
||||
QCoreApplication::organizationName().toLower() + "/" +
|
||||
QCoreApplication::applicationName().toLower();
|
||||
binaryDir.remove( binRegexp );
|
||||
QFileInfo etcDirInfo { binaryDir + "/etc" };
|
||||
if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QString configDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "XDG_CONFIG_HOME" ) ) );
|
||||
if ( configDirectory.isEmpty() )
|
||||
{
|
||||
configDirectory = m_homeDirectory.absolutePath() + ".config";
|
||||
}
|
||||
m_configDirectory = configDirectory + "/" +
|
||||
QCoreApplication::organizationName().toLower() + "/" +
|
||||
QCoreApplication::applicationName().toLower();
|
||||
QFileInfo constDataDirInfo { binaryDir + "/files/data" };
|
||||
if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QString cacheDirectory = QString::fromLocal8Bit( qgetenv( qPrintable( "XDG_CACHE_HOME" ) ) );
|
||||
if ( cacheDirectory.isEmpty() )
|
||||
{
|
||||
cacheDirectory = m_homeDirectory.absolutePath() + ".cache";
|
||||
}
|
||||
m_cacheDirectory = cacheDirectory + "/" +
|
||||
QCoreApplication::organizationName().toLower() + "/" +
|
||||
QCoreApplication::applicationName().toLower();
|
||||
m_logDirectory = m_cacheDirectory.absolutePath() + "/log";
|
||||
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();
|
||||
|
||||
return ( HierarchyType::kOpt );
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
return ( HierarchyType::kStandard );
|
||||
}
|
||||
|
||||
if ( binaryDir.startsWith( m_homeDirectory.canonicalPath() + "/.local/bin" ) ||
|
||||
binaryDir.startsWith( m_homeDirectory.canonicalPath() + "/bin" ) )
|
||||
{
|
||||
QFileInfo etcDirInfo { m_userConfigDirectory.canonicalPath() };
|
||||
if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo constDataDirInfo { m_userConstDataDirectory.canonicalPath() };
|
||||
if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo varDataDirInfo { m_userVarDataDirectory.canonicalPath() };
|
||||
if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo logDirInfo { m_userLogDirectory.canonicalPath() };
|
||||
if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
m_systemConfigDirectory = etcDirInfo.canonicalFilePath();
|
||||
m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath();
|
||||
m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath();
|
||||
m_systemLogDirectory = logDirInfo.canonicalFilePath();
|
||||
|
||||
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();
|
||||
|
||||
return ( HierarchyType::kUser );
|
||||
} // Paths::getHierarchyType
|
||||
|
||||
|
||||
bool Paths::init( const QString& projectDir, const QString& configFileExtension )
|
||||
{
|
||||
m_projectName = projectDir.isEmpty() ? m_currentExecutable.m_canonicalFilePath.fileName()
|
||||
: projectDir;
|
||||
m_configFileExtension = configFileExtension.isEmpty() ? QStringLiteral( "conf" )
|
||||
: configFileExtension;
|
||||
m_configFileName = m_projectName + "." + m_configFileExtension;
|
||||
|
||||
m_homeDirectory = QString::fromLocal8Bit( qgetenv( "HOME" ) );
|
||||
m_tempDirectory = QString::fromLocal8Bit( qgetenv( "TMPDIR" ) );
|
||||
if ( !m_tempDirectory.exists() || ( m_tempDirectory.path() == QStringLiteral( "." ) ) )
|
||||
{
|
||||
m_tempDirectory = QStringLiteral( _PATH_TMP );
|
||||
}
|
||||
|
||||
auto configHome = QString::fromLocal8Bit( qgetenv( "XDG_CONFIG_HOME" ) );
|
||||
if ( configHome.isEmpty() )
|
||||
{
|
||||
configHome = m_homeDirectory.canonicalPath() + "/.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_projectName;
|
||||
m_userConstDataDirectory = dataHome + "/data";
|
||||
m_userVarDataDirectory = dataHome + "/lib";
|
||||
m_userLogDirectory = dataHome + "/log";
|
||||
|
||||
m_hierarchyType = getHierarchyType();
|
||||
|
||||
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_configFilePath = m_systemConfigDirectory.canonicalPath() + "/" + m_configFileName;
|
||||
|
||||
return( true );
|
||||
} // Paths::updatePaths
|
||||
|
||||
@ -214,17 +168,17 @@ bool Paths::makeDefaultDirectories()
|
||||
{
|
||||
bool status = true;
|
||||
|
||||
if ( !m_dataDirectory.mkpath( m_dataDirectory.absolutePath() ) ) { status = false; }
|
||||
if ( !m_configDirectory.mkpath( m_configDirectory.absolutePath() ) ) { status = false; }
|
||||
if ( !m_cacheDirectory.mkpath( m_cacheDirectory.absolutePath() ) ) { status = false; }
|
||||
if ( !m_logDirectory.mkpath( m_logDirectory.absolutePath() ) ) { status = false; }
|
||||
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; }
|
||||
return( status );
|
||||
}
|
||||
|
||||
|
||||
QString Paths::findConfigFile( const QString& defaultConfigFile )
|
||||
{
|
||||
if ( QFileInfo( defaultConfigFile ).isReadable() )
|
||||
if ( !defaultConfigFile.isEmpty() && QFileInfo( defaultConfigFile ).isReadable() )
|
||||
{
|
||||
m_configFilePath = defaultConfigFile;
|
||||
return( defaultConfigFile );
|
||||
@ -246,6 +200,108 @@ QString Paths::findConfigFile( const QString& defaultConfigFile )
|
||||
return( QString() );
|
||||
} // Paths::findConfigFile
|
||||
|
||||
|
||||
QDir Paths::binaryDirectory() const
|
||||
{
|
||||
return( m_currentExecutable.m_canonicalFilePath.dir() );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::userConfigDirectory() const
|
||||
{
|
||||
return( m_userConfigDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::systemConfigDirectory() const
|
||||
{
|
||||
return( m_systemConfigDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QFileInfo& Paths::configFilePath() const
|
||||
{
|
||||
return( m_configFilePath );
|
||||
}
|
||||
|
||||
|
||||
const QString& Paths::configFileName() const
|
||||
{
|
||||
return( m_configFileName );
|
||||
}
|
||||
|
||||
|
||||
const QString& Paths::configFileExtension() const
|
||||
{
|
||||
return( m_configFileExtension );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::userVarDataDirectory() const
|
||||
{
|
||||
return( m_userVarDataDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::systemVarDataDirectory() const
|
||||
{
|
||||
return( m_systemVarDataDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::userConstDataDirectory() const
|
||||
{
|
||||
return( m_userConstDataDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::systemConstDataDirectory() const
|
||||
{
|
||||
return( m_systemConstDataDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::userLogDirectory() const
|
||||
{
|
||||
return( m_userLogDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::systemLogDirectory() const
|
||||
{
|
||||
return( m_systemLogDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::tempDirectory() const
|
||||
{
|
||||
return( m_tempDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QDir& Paths::homeDirectory() const
|
||||
{
|
||||
return( m_homeDirectory );
|
||||
}
|
||||
|
||||
|
||||
const QString& Paths::projectName() const
|
||||
{
|
||||
return( m_projectName );
|
||||
}
|
||||
|
||||
|
||||
QString Paths::executableFileName() const
|
||||
{
|
||||
return( m_currentExecutable.m_canonicalFilePath.fileName() );
|
||||
}
|
||||
|
||||
|
||||
const QFileInfo& Paths::executableFilePath() const
|
||||
{
|
||||
return( m_currentExecutable.m_canonicalFilePath );
|
||||
}
|
||||
|
||||
} // namespace filesystem
|
||||
|
||||
} // namespace myx
|
||||
|
@ -6,6 +6,8 @@
|
||||
#ifndef MYX_FILESYSTEM_PATHS_HPP_
|
||||
#define MYX_FILESYSTEM_PATHS_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/filesystem/current_executable.hpp>
|
||||
|
||||
#include <QString>
|
||||
@ -16,125 +18,85 @@ namespace myx {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
/// @brief Класс, предоставляющий методы для получения стандартных путей к каталогам и файлам
|
||||
class Paths
|
||||
{
|
||||
/// Путь к базовому каталогу
|
||||
QDir m_prefixDirectory;
|
||||
/// Путь к каталогу с исполняемым файлом
|
||||
QDir m_binaryDirectory;
|
||||
/// Путь к каталогу с изменяемыми файлами
|
||||
QDir m_cacheDirectory;
|
||||
/// Путь к каталогу с временными файлами
|
||||
enum class HierarchyType : intptr_t
|
||||
{
|
||||
kSplit = 0x00,
|
||||
kFlat = 0x01,
|
||||
kOpt = 0x02,
|
||||
kStandard = 0x04,
|
||||
kUser = 0x08,
|
||||
kHome = 0x10,
|
||||
};
|
||||
|
||||
/// @brief Тип расположения файлов по каталогам
|
||||
HierarchyType m_hierarchyType { HierarchyType::kFlat };
|
||||
|
||||
/// @brief Параметры текущего исполняемого файла
|
||||
CurrentExecutable m_currentExecutable;
|
||||
|
||||
/// @brief Имя проекта, которое используется при формировании имён файлов и каталогов
|
||||
QString m_projectName;
|
||||
|
||||
/// @brief Путь к каталогу с временными файлами
|
||||
QDir m_tempDirectory;
|
||||
/// Путь к каталогу с неизменяемыми файлами
|
||||
QDir m_dataDirectory;
|
||||
/// Путь к каталогу с журналами работы
|
||||
QDir m_logDirectory;
|
||||
/// Путь к домашнему каталогу текущего пользователя
|
||||
/// @brief Путь к домашнему каталогу текущего пользователя
|
||||
QDir m_homeDirectory;
|
||||
/// Путь к каталогу с файлами настройки
|
||||
QDir m_configDirectory;
|
||||
/// Полный путь к файлу настройки
|
||||
|
||||
/// @brief Путь к пользовательскому каталогу с изменяемыми файлами
|
||||
QDir m_userVarDataDirectory;
|
||||
/// @brief Путь к системному каталогу с изменяемыми файлами
|
||||
QDir m_systemVarDataDirectory;
|
||||
|
||||
/// @brief Путь к пользовательскому каталогу с неизменяемыми файлами
|
||||
QDir m_userConstDataDirectory;
|
||||
/// @brief Путь к системному каталогу с неизменяемыми файлами
|
||||
QDir m_systemConstDataDirectory;
|
||||
|
||||
/// @brief Путь к пользовательскому каталогу с журналами работы
|
||||
QDir m_userLogDirectory;
|
||||
/// @brief Путь к системному каталогу с журналами работы
|
||||
QDir m_systemLogDirectory;
|
||||
|
||||
/// @brief Путь к пользовательскому каталогу с файлами настройки
|
||||
QDir m_userConfigDirectory;
|
||||
/// @brief Путь к системному каталогу с файлами настройки
|
||||
QDir m_systemConfigDirectory;
|
||||
|
||||
/// @brief Полный путь к файлу настройки
|
||||
QFileInfo m_configFilePath;
|
||||
/// Имя файла настройки
|
||||
/// @brief Имя файла настройки
|
||||
QString m_configFileName;
|
||||
/// Расширение для файла настройки
|
||||
/// @brief Расширение для файла настройки
|
||||
QString m_configFileExtension;
|
||||
|
||||
/// Параметры текущего исполняемого файла
|
||||
CurrentExecutable m_currentExecutable;
|
||||
HierarchyType getHierarchyType();
|
||||
|
||||
protected:
|
||||
Paths();
|
||||
~Paths() = default;
|
||||
Paths( const Paths& ) = delete;
|
||||
Paths& operator=( const Paths& ) = delete;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Конструктор
|
||||
* @param configFileExtension Расширение для файла настройки
|
||||
* @brief getInstance
|
||||
* @return Уникальный экземпляр класса Paths
|
||||
*/
|
||||
Paths( const QString& configFileExtension = "conf" );
|
||||
/**
|
||||
* @brief Получение пути к базовому каталогу
|
||||
*/
|
||||
QDir prefixDirectory() const;
|
||||
/**
|
||||
* @brief Установка пути к базовому каталогу
|
||||
*/
|
||||
void setPrefixDirectory( const QString& prefixDirectory );
|
||||
/**
|
||||
* @brief Получение пути к каталогу с исполняемым файлом
|
||||
*/
|
||||
QDir binaryDirectory() const;
|
||||
/**
|
||||
* @brief Установка пути к каталогу с исполняемым файлом
|
||||
*/
|
||||
void setBinaryDirectory( const QString& binaryDirectory );
|
||||
/**
|
||||
* @brief Получение пути к каталогу с файлами настройки
|
||||
*/
|
||||
QDir configDirectory() const;
|
||||
/**
|
||||
* @brief Установка пути к каталогу с файлами настройки
|
||||
*/
|
||||
void setConfigDirectory( const QString& configDirectory );
|
||||
/**
|
||||
* @brief Получение пути к каталогу с изменяемыми файлами
|
||||
*/
|
||||
QDir cacheDirectory() const;
|
||||
/**
|
||||
* @brief Установка пути к каталогу с изменяемыми файлами
|
||||
*/
|
||||
void setCacheDirectory( const QString& cacheDirectory );
|
||||
/**
|
||||
* @brief Получение пути к каталогу с временными файлами
|
||||
*/
|
||||
QDir tempDirectory() const;
|
||||
/**
|
||||
* @brief Установка пути к каталогу с временными файлами
|
||||
*/
|
||||
void setTempDirectory( const QString& tempDirectory );
|
||||
/**
|
||||
* @brief Получение пути к каталогу с неизменяемыми файлами
|
||||
*/
|
||||
QDir dataDirectory() const;
|
||||
/**
|
||||
* @brief Установка пути к каталогу с неизменяемыми файлами
|
||||
*/
|
||||
void setDataDirectory( const QString& dataDirectory );
|
||||
/**
|
||||
* @brief Получение пути к каталогу с журналами работы
|
||||
*/
|
||||
QDir logDirectory() const;
|
||||
/**
|
||||
* @brief Установка пути к каталогу с журналами работы
|
||||
*/
|
||||
void setLogDirectory( const QString& logDirectory );
|
||||
/**
|
||||
* @brief Имя исполняемого файла
|
||||
*/
|
||||
QString executableFileName() const;
|
||||
/**
|
||||
* @brief Полный путь к исполняемому файлу
|
||||
*/
|
||||
QFileInfo executableFilePath() const;
|
||||
/**
|
||||
* @brief Имя файла настройки
|
||||
*/
|
||||
QString configFileName() const;
|
||||
/**
|
||||
* @brief Установка имени файла настройки
|
||||
*/
|
||||
void setConfigFileName( const QString& configFileName );
|
||||
/**
|
||||
* @brief Полный путь к файлу настройки
|
||||
*/
|
||||
QFileInfo configFilePath() const;
|
||||
/**
|
||||
* @brief Установка полного пути к файлу настройки
|
||||
*/
|
||||
void setConfigFilePath( const QFileInfo& configFilePath );
|
||||
static Paths& instance()
|
||||
{
|
||||
static Paths p;
|
||||
return( p );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Обновление путей с учётом расположения исполняемого файла
|
||||
*/
|
||||
bool updatePaths();
|
||||
bool init( const QString& projectDir, const QString& configFileExtension = QStringLiteral("conf") );
|
||||
|
||||
/**
|
||||
* @brief Создание стандартных каталогов
|
||||
*/
|
||||
@ -144,11 +106,101 @@ public:
|
||||
* @brief Поиск существующего файла настойки.
|
||||
* Поиск выполняется до тех пор пока не будет найден файл в следующем порядке:
|
||||
* 1. Имя файла, указанное в качестве параметра функции
|
||||
* 2. Имя файла, заданное переменной окружения вида PORJECT_NAME_CONFIG
|
||||
* 2. Имя файла, заданное переменной окружения вида PROJECT_NAME_CONFIG
|
||||
* 3. Имя файла, полученное из внутренней переменной класса
|
||||
* Если файл настройки не будет найден, то будет возвращена пустая строка
|
||||
*/
|
||||
QString findConfigFile( const QString& defaultConfigFile = "" );
|
||||
QString findConfigFile( const QString& defaultConfigFile = QLatin1String("") );
|
||||
|
||||
/**
|
||||
* @brief Получение пути к базовому каталогу
|
||||
*/
|
||||
const QDir& prefixDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к каталогу с исполняемым файлом
|
||||
*/
|
||||
QDir binaryDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к пользовательскому каталогу с файлами настройки
|
||||
*/
|
||||
const QDir& userConfigDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к системному каталогу с файлами настройки
|
||||
*/
|
||||
const QDir& systemConfigDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Полный путь к файлу настройки
|
||||
*/
|
||||
const QFileInfo& configFilePath() const;
|
||||
|
||||
/**
|
||||
* @brief Имя файла настройки
|
||||
*/
|
||||
const QString& configFileName() const;
|
||||
|
||||
/**
|
||||
* @brief Расширение у файла настройки
|
||||
*/
|
||||
const QString& configFileExtension() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к пользовательскому каталогу с изменяемыми файлами
|
||||
*/
|
||||
const QDir& userVarDataDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к системному каталогу с изменяемыми файлами
|
||||
*/
|
||||
const QDir& systemVarDataDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к пользовательскому каталогу с неизменяемыми файлами
|
||||
*/
|
||||
const QDir& userConstDataDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к системному каталогу с неизменяемыми файлами
|
||||
*/
|
||||
const QDir& systemConstDataDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к пользовательскому каталогу с журналами работы
|
||||
*/
|
||||
const QDir& userLogDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к системному каталогу с журналами работы
|
||||
*/
|
||||
const QDir& systemLogDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к каталогу с временными файлами
|
||||
*/
|
||||
const QDir& tempDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Получение пути к домашнему каталогу текущего пользователя
|
||||
*/
|
||||
const QDir& homeDirectory() const;
|
||||
|
||||
/**
|
||||
* @brief Имя подкаталога для проекта
|
||||
*/
|
||||
const QString& projectName() const;
|
||||
|
||||
/**
|
||||
* @brief Имя исполняемого файла
|
||||
*/
|
||||
QString executableFileName() const;
|
||||
|
||||
/**
|
||||
* @brief Полный путь к исполняемому файлу
|
||||
*/
|
||||
const QFileInfo& executableFilePath() const;
|
||||
}; // class Paths
|
||||
|
||||
} // namespace filesystem
|
||||
|
34
src/myx/filesystem/paths_mt.cpp
Normal file
34
src/myx/filesystem/paths_mt.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <myx/base/config.hpp>
|
||||
#include <myx/filesystem/current_executable.hpp>
|
||||
#include <myx/filesystem/paths_mt.hpp>
|
||||
|
||||
#include <paths.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
PathsMT::PathsMT() = default;
|
||||
|
||||
PathsMT& PathsMT::instance()
|
||||
{
|
||||
volatile PathsMT* localInstance = mInstance.load( std::memory_order_acquire );
|
||||
if ( localInstance == nullptr )
|
||||
{
|
||||
std::lock_guard< std::mutex > myLock( mMutex );
|
||||
localInstance = mInstance.load( std::memory_order_relaxed );
|
||||
if ( localInstance == nullptr ) // -V1036
|
||||
{
|
||||
localInstance = new PathsMT();
|
||||
mInstance.store( const_cast< PathsMT* >( localInstance ), std::memory_order_release ); // NOLINT
|
||||
}
|
||||
}
|
||||
return( const_cast< PathsMT& >( *localInstance ) ); // NOLINT
|
||||
}
|
||||
|
||||
} // namespace filesystem
|
||||
|
||||
} // namespace myx
|
50
src/myx/filesystem/paths_mt.hpp
Normal file
50
src/myx/filesystem/paths_mt.hpp
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @file paths.hpp
|
||||
* @brief Стандартные пути к каталогам и файлам
|
||||
*/
|
||||
|
||||
#ifndef MYX_FILESYSTEM_PATHS_MT_HPP_
|
||||
#define MYX_FILESYSTEM_PATHS_MT_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/filesystem/paths.hpp>
|
||||
#include <myx/filesystem/current_executable.hpp>
|
||||
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
/// @brief Потокобезопасная версия класса myx::filesystem::Paths
|
||||
class PathsMT : public Paths
|
||||
{
|
||||
PathsMT();
|
||||
~PathsMT() = default;
|
||||
PathsMT( const PathsMT& ) = delete;
|
||||
PathsMT& operator=( const PathsMT& ) = delete;
|
||||
|
||||
static std::atomic< PathsMT* > mInstance;
|
||||
static std::mutex mMutex;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief getInstance
|
||||
* @return Уникальный экземпляр класса PathsMT
|
||||
*/
|
||||
static PathsMT& instance();
|
||||
}; // class PathsMT
|
||||
|
||||
} // namespace filesystem
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // MYX_FILESYSTEM_PATHS_MT_HPP_
|
@ -1,5 +1,5 @@
|
||||
#include <myx/math/float_cmp_types.hpp>
|
||||
#include <myx/math/almost_equal_ulps.hpp>
|
||||
#include <myx/math/float_cmp_types.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@ -14,6 +14,7 @@ bool almost_equal_ulps( const float a, const float b,
|
||||
float_cmp_t uB( b );
|
||||
|
||||
// Если знаки разные, то числа не равны.
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||
if ( uA.negative() != uB.negative() )
|
||||
{
|
||||
// Кроме случая, когда +0==-0
|
||||
@ -21,7 +22,7 @@ bool almost_equal_ulps( const float a, const float b,
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||
#endif
|
||||
if ( a == b )
|
||||
if ( a == b ) // -V550
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
@ -32,6 +33,7 @@ bool almost_equal_ulps( const float a, const float b,
|
||||
}
|
||||
|
||||
// Разница в младших битах.
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||
auto ulpsDiff = std::abs( uA.i - uB.i );
|
||||
if ( ulpsDiff <= maxUlpsDiff )
|
||||
{
|
||||
@ -48,6 +50,7 @@ bool almost_equal_ulps( const double a, const double b,
|
||||
double_cmp_t uB( b );
|
||||
|
||||
// Если знаки разные, то числа не равны.
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||
if ( uA.negative() != uB.negative() )
|
||||
{
|
||||
// Кроме случая, когда +0==-0
|
||||
@ -55,7 +58,7 @@ bool almost_equal_ulps( const double a, const double b,
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||
#endif
|
||||
if ( a == b )
|
||||
if ( a == b ) // -V550
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
@ -66,6 +69,7 @@ bool almost_equal_ulps( const double a, const double b,
|
||||
}
|
||||
|
||||
// Разница в младших битах.
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||
auto ulpsDiff = std::abs( uA.i - uB.i );
|
||||
if ( ulpsDiff <= maxUlpsDiff )
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <myx/math/float_cmp_types.hpp>
|
||||
#include <myx/math/almost_equal_ulps_and_abs.hpp>
|
||||
#include <myx/math/float_cmp_types.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@ -22,12 +22,14 @@ bool almost_equal_ulps_and_abs( const float a, const float b,
|
||||
float_cmp_t uB( b );
|
||||
|
||||
// Different signs means they do not match.
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||
if ( uA.negative() != uB.negative() )
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
|
||||
// Find the difference in ULPs.
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||
int ulpsDiff = std::abs( uA.i - uB.i );
|
||||
if ( ulpsDiff <= maxUlpsDiff )
|
||||
{
|
||||
@ -53,12 +55,14 @@ bool almost_equal_ulps_and_abs( const double a, const double b,
|
||||
double_cmp_t uB( b );
|
||||
|
||||
// Different signs means they do not match.
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||
if ( uA.negative() != uB.negative() )
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
|
||||
// Find the difference in ULPs.
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
|
||||
auto ulpsDiff = std::abs( uA.i - uB.i );
|
||||
if ( ulpsDiff <= maxUlpsDiff )
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ namespace math {
|
||||
* \return Квадрат значения
|
||||
*/
|
||||
template < typename T >
|
||||
auto pow2( T const& value )->decltype( boost::math::pow< 2 >( value ) )
|
||||
auto pow2( T const& value ) -> decltype( boost::math::pow< 2 >( value ) )
|
||||
{
|
||||
return( boost::math::pow< 2 >( value ) );
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ template< typename ... Args >
|
||||
struct QOverload
|
||||
{
|
||||
template< typename C, typename R >
|
||||
static constexpr auto of( R ( C::* pmf )( Args... ) )->decltype( pmf )
|
||||
static constexpr auto of( R ( C::* pmf )( Args... ) ) -> decltype( pmf )
|
||||
{
|
||||
return( pmf );
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include <myx/base/config.hpp>
|
||||
#include "translators.hpp"
|
||||
|
||||
#include <myx/base/config.hpp>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QLocale>
|
||||
#include <QLibraryInfo>
|
||||
#include <QLocale>
|
||||
|
||||
namespace myx {
|
||||
|
||||
@ -11,10 +12,10 @@ namespace qt {
|
||||
|
||||
void append_translators( QTranslatorsList& translators, const QString& appName )
|
||||
{
|
||||
auto translator = new QTranslator( qApp );
|
||||
auto* translator = new QTranslator( qApp );
|
||||
|
||||
if ( translator->load( QLocale(), appName, QStringLiteral( "_" ),
|
||||
QStringLiteral( ":/qm" ) ) )
|
||||
if ( translator->load( QLocale(),
|
||||
appName, QStringLiteral( "_" ), QStringLiteral( ":/qm" ) ) )
|
||||
{
|
||||
translators.append( translator );
|
||||
}
|
||||
@ -46,11 +47,11 @@ void append_translators( QTranslatorsList& translators, const QString& appName )
|
||||
translator->deleteLater();
|
||||
}
|
||||
|
||||
for ( auto i : qAsConst( translators ) )
|
||||
for ( auto* i : qAsConst( translators ) )
|
||||
{
|
||||
qApp->installTranslator( i );
|
||||
}
|
||||
} // install_translators
|
||||
} // append_translators
|
||||
|
||||
} // namespace qt
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include <client.hpp>
|
||||
#include <client_p.hpp>
|
||||
|
||||
using namespace qxredis;
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
ClientPrivate::ClientPrivate( Client* client ) :
|
||||
lexer ( &socket ),
|
||||
@ -48,7 +50,7 @@ Request* Client::sendCommand( const QByteArray& command )
|
||||
{
|
||||
d->socket.write( command + "\r\n" );
|
||||
|
||||
auto request = new Request( this );
|
||||
auto* request = new Request( this );
|
||||
d->queue.enqueue( request );
|
||||
return( request );
|
||||
}
|
||||
@ -64,3 +66,7 @@ bool Client::waitForDisconnected( int msecs )
|
||||
{
|
||||
return( d->socket.waitForDisconnected( msecs ) );
|
||||
}
|
||||
|
||||
} // namespace redis
|
||||
|
||||
} // namespace myx
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef QXREDIS_CLIENT_HPP_
|
||||
#define QXREDIS_CLIENT_HPP_
|
||||
#ifndef MYX_REDIS_CLIENT_HPP_
|
||||
#define MYX_REDIS_CLIENT_HPP_
|
||||
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
@ -7,15 +7,16 @@
|
||||
#include <config.hpp>
|
||||
#include <request.hpp>
|
||||
|
||||
namespace qxredis
|
||||
{
|
||||
namespace myx {
|
||||
|
||||
class QXREDIS_EXPORT ClientPrivate;
|
||||
namespace redis {
|
||||
|
||||
class MYX_REDIS_EXPORT ClientPrivate;
|
||||
|
||||
/**
|
||||
* @brief Provides access to a Redis server
|
||||
*/
|
||||
class QXREDIS_EXPORT Client : public QObject
|
||||
class MYX_REDIS_EXPORT Client : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -103,8 +104,10 @@ public:
|
||||
private:
|
||||
|
||||
const QScopedPointer< ClientPrivate > d;
|
||||
}; // class QXREDIS_EXPORT
|
||||
}; // class MYX_REDIS_EXPORT
|
||||
|
||||
} // namespace QXRedis
|
||||
} // namespace redis
|
||||
|
||||
#endif // QXREDIS_CLIENT_HPP_
|
||||
} // namespace myx
|
||||
|
||||
#endif // MYX_REDIS_CLIENT_HPP_
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef QREDIS_CLIENT_P_H
|
||||
#define QREDIS_CLIENT_P_H
|
||||
#ifndef MYX_REDIS_CLIENT_P_HPP_
|
||||
#define MYX_REDIS_CLIENT_P_HPP_
|
||||
|
||||
#include <QObject>
|
||||
#include <QQueue>
|
||||
@ -11,8 +11,9 @@
|
||||
#include <lexer.hpp>
|
||||
#include <parser.hpp>
|
||||
|
||||
namespace qxredis
|
||||
{
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
class ClientPrivate : public QObject
|
||||
{
|
||||
@ -28,9 +29,10 @@ public:
|
||||
Parser parser;
|
||||
|
||||
private:
|
||||
Q_SLOT void sendReply(const qxredis::Reply & );
|
||||
Q_SLOT void sendReply(const myx::redis::Reply & );
|
||||
}; // class ClientPrivate
|
||||
|
||||
} // namespace QRedis
|
||||
}
|
||||
}
|
||||
|
||||
#endif // QREDIS_CLIENT_H
|
||||
#endif // MYX_REDIS_CLIENT_P_HPP_
|
||||
|
@ -1,15 +1,14 @@
|
||||
#ifndef QXREDIS_CONFIG_HPP_
|
||||
#define QXREDIS_CONFIG_HPP_
|
||||
#ifndef MYX_REDIS_CONFIG_HPP_
|
||||
#define MYX_REDIS_CONFIG_HPP_
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
// #if defined( qredis_EXPORTS )
|
||||
#define QXREDIS_EXPORT Q_DECL_EXPORT
|
||||
#define MYX_REDIS_EXPORT Q_DECL_EXPORT
|
||||
// #else
|
||||
// #define QXREDIS_EXPORT Q_DECL_IMPORT
|
||||
// #define MYX_REDIS_EXPORT Q_DECL_IMPORT
|
||||
// #endif
|
||||
|
||||
#include "cmlib_config.hpp"
|
||||
#include "config_flags.hpp"
|
||||
|
||||
#endif // QXREDIS_CONFIG_HPP_
|
||||
#endif // MYX_REDIS_CONFIG_HPP_
|
||||
|
@ -4,4 +4,3 @@
|
||||
// #cmakedefine
|
||||
|
||||
#endif /* @CMLIB_PROJECT_NAME_CANONICAL@_CONFIG_FLAGS_HPP_ */
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "lexer.hpp"
|
||||
|
||||
using namespace qxredis;
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
Lexer::Lexer( QIODevice* device, QObject* parent ) :
|
||||
QObject ( parent ),
|
||||
@ -100,7 +102,7 @@ bool Lexer::readUnsafeString()
|
||||
|
||||
bool Lexer::readSafeString()
|
||||
{
|
||||
if ( m_buffer.size() < m_length + 2 )
|
||||
if ( m_buffer.size() - m_length < 2 )
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
@ -113,3 +115,7 @@ bool Lexer::readSafeString()
|
||||
m_state = DoingNothing;
|
||||
return( true );
|
||||
}
|
||||
|
||||
} // namespace redis
|
||||
|
||||
} // namespace myx
|
||||
|
@ -1,11 +1,12 @@
|
||||
#ifndef QXREDIS_LEXER_HPP_
|
||||
#define QXREDIS_LEXER_HPP_
|
||||
#ifndef MYX_REDIS_LEXER_HPP_
|
||||
#define MYX_REDIS_LEXER_HPP_
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QObject>
|
||||
|
||||
namespace qxredis
|
||||
{
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
class Lexer : public QObject
|
||||
{
|
||||
@ -46,6 +47,8 @@ private:
|
||||
int m_length;
|
||||
}; // class Lexer
|
||||
|
||||
} // namespace QRedis
|
||||
} // namespace redis
|
||||
|
||||
#endif // QREDIS_LEXER_H
|
||||
} // namespace myx
|
||||
|
||||
#endif // MYX_REDIS_LEXER_HPP_
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "parser.hpp"
|
||||
|
||||
using namespace qxredis;
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
Parser::Parser( Lexer* lexer, QObject* parent ) :
|
||||
QObject( parent )
|
||||
@ -74,3 +76,7 @@ void Parser::descend()
|
||||
tos().reply.value().toList().append( QVariant::fromValue( r ) );
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace redis
|
||||
|
||||
} // namespace myx
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef QREDIS_PARSER_H
|
||||
#define QREDIS_PARSER_H
|
||||
#ifndef MYX_REDIS_PARSER_HPP_
|
||||
#define MYX_REDIS_PARSER_HPP_
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
@ -9,8 +9,9 @@
|
||||
#include <reply.hpp>
|
||||
#include <lexer.hpp>
|
||||
|
||||
namespace qxredis
|
||||
{
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
class Parser : public QObject
|
||||
{
|
||||
@ -20,7 +21,7 @@ public:
|
||||
Parser( Lexer*, QObject* = nullptr );
|
||||
virtual ~Parser() = default;
|
||||
|
||||
Q_SIGNAL void reply( const qxredis::Reply& );
|
||||
Q_SIGNAL void reply( const myx::redis::Reply& );
|
||||
|
||||
private:
|
||||
Q_SLOT void readCharacter( const char );
|
||||
@ -49,6 +50,8 @@ public:
|
||||
Task& tos() { return( stack.last() ); }
|
||||
}; // class Parser
|
||||
|
||||
} // namespace QRedis
|
||||
} // namespace redis
|
||||
|
||||
#endif // QREDIS_PARSER_H
|
||||
} // namespace myx
|
||||
|
||||
#endif // MYX_REDIS_PARSER_HPP_
|
||||
|
@ -1,17 +1,18 @@
|
||||
#ifndef QXREDIS_REPLY_HPP_
|
||||
#define QXREDIS_REPLY_HPP_
|
||||
#ifndef MYX_REDIS_REPLY_HPP_
|
||||
#define MYX_REDIS_REPLY_HPP_
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
#include <config.hpp>
|
||||
|
||||
namespace qxredis
|
||||
{
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
/**
|
||||
* @brief Represents a Redis reply
|
||||
*/
|
||||
class QXREDIS_EXPORT Reply
|
||||
class MYX_REDIS_EXPORT Reply
|
||||
{
|
||||
public:
|
||||
|
||||
@ -98,10 +99,12 @@ private:
|
||||
|
||||
Type _type;
|
||||
QVariant _value;
|
||||
}; // class QXREDIS_EXPORT Reply
|
||||
}; // class MYX_REDIS_EXPORT Reply
|
||||
|
||||
} // namespace qxredis
|
||||
} // namespace redis
|
||||
|
||||
Q_DECLARE_METATYPE( qxredis::Reply )
|
||||
} // namespace myx
|
||||
|
||||
#endif // QXREDIS_REPLY_HPP_
|
||||
Q_DECLARE_METATYPE( myx::redis::Reply )
|
||||
|
||||
#endif // MYX_REDIS_REPLY_HPP_
|
||||
|
@ -3,7 +3,9 @@
|
||||
#include <request.hpp>
|
||||
#include <request_p.hpp>
|
||||
|
||||
using namespace qxredis;
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
void RequestPrivate::quitEventLoop()
|
||||
{
|
||||
@ -34,3 +36,7 @@ bool Request::waitForReply( int msecs )
|
||||
*/
|
||||
return( ( d->loop.exec( QEventLoop::ExcludeUserInputEvents ) != 0 ) );
|
||||
}
|
||||
|
||||
} // namespace redis
|
||||
|
||||
} // namespace myx
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef QREDIS_REQUEST_H
|
||||
#define QREDIS_REQUEST_H
|
||||
#ifndef MYX_REDIS_REQUEST_HPP_
|
||||
#define MYX_REDIS_REQUEST_HPP_
|
||||
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
@ -7,15 +7,16 @@
|
||||
#include <config.hpp>
|
||||
#include <reply.hpp>
|
||||
|
||||
namespace qxredis
|
||||
{
|
||||
namespace myx {
|
||||
|
||||
class QXREDIS_EXPORT RequestPrivate;
|
||||
namespace redis {
|
||||
|
||||
class MYX_REDIS_EXPORT RequestPrivate;
|
||||
|
||||
/**
|
||||
* @brief Represents a Redis command and its response
|
||||
*/
|
||||
class QXREDIS_EXPORT Request : public QObject
|
||||
class MYX_REDIS_EXPORT Request : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -43,13 +44,15 @@ public:
|
||||
* @brief Emitted when a reply is received
|
||||
* @param reply the reply received
|
||||
*/
|
||||
Q_SIGNAL void reply( const qxredis::Reply& reply );
|
||||
Q_SIGNAL void reply( const myx::redis::Reply& reply );
|
||||
|
||||
private:
|
||||
|
||||
const QScopedPointer< RequestPrivate > d;
|
||||
}; // class QXREDIS_EXPORT
|
||||
}; // class MYX_REDIS_EXPORT
|
||||
|
||||
} // namespace QRedis
|
||||
} // namespace redis
|
||||
|
||||
#endif // QREDIS_REQUEST_H
|
||||
} // namespace myx
|
||||
|
||||
#endif // MYX_REDIS_REQUEST_HPP_
|
||||
|
@ -1,11 +1,12 @@
|
||||
#ifndef QREDIS_REQUEST_P_H
|
||||
#define QREDIS_REQUEST_P_H
|
||||
#ifndef MYX_REDIS_REQUEST_P_HPP_
|
||||
#define MYX_REDIS_REQUEST_P_HPP_
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QObject>
|
||||
|
||||
namespace qxredis
|
||||
{
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
class RequestPrivate : public QObject
|
||||
{
|
||||
@ -18,6 +19,7 @@ public:
|
||||
Q_SLOT void quitEventLoop();
|
||||
};
|
||||
|
||||
} // namespace QRedis
|
||||
}
|
||||
|
||||
#endif // QREDIS_REQUEST_P_H
|
||||
}
|
||||
#endif // MYX_REDIS_REQUEST_P_HPP_
|
||||
|
Loading…
x
Reference in New Issue
Block a user