Compare commits
100 Commits
b86cf01973
...
myx-cmake
Author | SHA1 | Date | |
---|---|---|---|
3bdf4ceda3 | |||
1e635fc7bb | |||
6f2d2361fd | |||
6c1728bce0 | |||
6dbde42d6f | |||
023b493eff | |||
31a3fc3dc7 | |||
52c618c590 | |||
ece9b7cf70 | |||
bb580c0938 | |||
547a127956 | |||
554ab7efdf | |||
7319a202c3 | |||
c1235edaa9 | |||
a4ea9864be | |||
347ef3d46d | |||
b21def5945 | |||
cfe4fe8a2e | |||
11c572a96c | |||
e3d5243f80 | |||
3f633ee15c | |||
458dcd82c6 | |||
a4b181a838 | |||
2261982479 | |||
d159417bbb | |||
66ddb8a1fb | |||
dd1010a826 | |||
35ad2e1db8 | |||
7d0c2f68d6 | |||
7396f77054 | |||
3d3690ca64 | |||
105ed96f5f | |||
5645c5ea31 | |||
e63e6a4c8a | |||
a017ca6814 | |||
8114675c1c | |||
d839fa6ed4 | |||
a368091252 | |||
9468f95dd3 | |||
56a0b595d2 | |||
716545e49c | |||
b575634554 | |||
299dabf295 | |||
a29cea6f61 | |||
360b2b41d1 | |||
297b04bd56 | |||
3b2332a82f | |||
2d1537a9b8 | |||
77683831b9 | |||
c1c0325bce | |||
5d2098b4fc | |||
feda5be3ba | |||
29b56561ca | |||
b2cb06853e | |||
fcac4dd4fe | |||
9f62d67135 | |||
d1fbeb9400 | |||
4024029944 | |||
5dff256613 | |||
668af95136 | |||
82b7c2ea51 | |||
15e19333a0 | |||
f152ba8017 | |||
1fb71f4481 | |||
6aeedb2bd1 | |||
39b264628c | |||
ac6ae7b24d | |||
cb6a82d9b5 | |||
827f153c2e | |||
1af27eaf54 | |||
1abebc0be6 | |||
0a544a773d | |||
661b63f963 | |||
7c2d52172c | |||
c5a9b5118b | |||
ee681940c5 | |||
7b0128dfe3 | |||
c418aa8df0 | |||
d951fd81cb | |||
078732d308 | |||
3c628659bc | |||
4519190768 | |||
f59e96bcaf | |||
f3c7ff25cf | |||
1053e70360 | |||
ec720ff8f4 | |||
e97025a81e | |||
de1c396a5e | |||
11866bf3ba | |||
bad24e34c7 | |||
d124aeb9dd | |||
6358fe0820 | |||
cf52aba9a3 | |||
3cb5cbd6c1 | |||
a4d00ed80b | |||
ca83f98484 | |||
44cd25464f | |||
0557003117 | |||
5f3831c935 | |||
57118ea2bb |
@ -18,6 +18,8 @@ portability-*,
|
|||||||
-readability-else-after-return,
|
-readability-else-after-return,
|
||||||
-modernize-use-trailing-return-type,
|
-modernize-use-trailing-return-type,
|
||||||
-modernize-avoid-c-arrays,
|
-modernize-avoid-c-arrays,
|
||||||
|
-modernize-use-nodiscard,
|
||||||
|
-modernize-concat-nested-namespaces,
|
||||||
-performance-no-automatic-move,
|
-performance-no-automatic-move,
|
||||||
'
|
'
|
||||||
|
|
||||||
|
248
.cmake-format.py
Normal file
248
.cmake-format.py
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# ----------------------------------
|
||||||
|
# Options affecting listfile parsing
|
||||||
|
# ----------------------------------
|
||||||
|
with section("parse"):
|
||||||
|
|
||||||
|
# Specify structure for custom cmake functions
|
||||||
|
additional_commands = {
|
||||||
|
'add_doxygen': { 'flags' : [],
|
||||||
|
'kwargs': { 'LATEX': 1,
|
||||||
|
'HTML': 1,
|
||||||
|
'COMMENT': 1}},
|
||||||
|
'add_breathe': { 'flags' : [],
|
||||||
|
'kwargs': { 'COMMENT': 1}},
|
||||||
|
'add_common_library': { 'flags' : [],
|
||||||
|
'kwargs': { 'OUTPUT_NAME': 1,
|
||||||
|
'SOURCES': '*',
|
||||||
|
'TARGET': 1}},
|
||||||
|
'qt5_translation': { 'flags' : [],
|
||||||
|
'kwargs': { 'OUTPUT_DIR': 1,
|
||||||
|
'LANGUAGES': '*',
|
||||||
|
'SOURCES': '*',
|
||||||
|
'BASE_NAME': 1}},
|
||||||
|
'pvs_studio_add_target': { 'flags' : [ 'COMPILE_COMMANDS',
|
||||||
|
'OUTPUT',
|
||||||
|
'HIDE_HELP'],
|
||||||
|
'kwargs': { 'ARGS': '*',
|
||||||
|
'CONFIG': '*',
|
||||||
|
'DEPENDS': '*',
|
||||||
|
'FORMAT': '*',
|
||||||
|
'MODE': '*',
|
||||||
|
'TARGET': 1}},
|
||||||
|
'write_compiler_detection_header': { 'flags' : [],
|
||||||
|
'kwargs': { 'COMPILERS': '*',
|
||||||
|
'FEATURES': '*',
|
||||||
|
'FILE': '*',
|
||||||
|
'PREFIX': '*'}}}
|
||||||
|
|
||||||
|
# Specify variable tags.
|
||||||
|
vartags = []
|
||||||
|
|
||||||
|
# Specify property tags.
|
||||||
|
proptags = []
|
||||||
|
|
||||||
|
# -----------------------------
|
||||||
|
# Options affecting formatting.
|
||||||
|
# -----------------------------
|
||||||
|
with section("format"):
|
||||||
|
|
||||||
|
# How wide to allow formatted cmake files
|
||||||
|
line_width = 110
|
||||||
|
|
||||||
|
# How many spaces to tab for indent
|
||||||
|
tab_size = 2
|
||||||
|
|
||||||
|
# If an argument group contains more than this many sub-groups (parg or kwarg
|
||||||
|
# groups) then force it to a vertical layout.
|
||||||
|
max_subgroups_hwrap = 3
|
||||||
|
|
||||||
|
# If a positional argument group contains more than this many arguments, then
|
||||||
|
# force it to a vertical layout.
|
||||||
|
max_pargs_hwrap = 5
|
||||||
|
|
||||||
|
# If a cmdline positional group consumes more than this many lines without
|
||||||
|
# nesting, then invalidate the layout (and nest)
|
||||||
|
max_rows_cmdline = 2
|
||||||
|
|
||||||
|
# If true, separate flow control names from their parentheses with a space
|
||||||
|
separate_ctrl_name_with_space = False
|
||||||
|
|
||||||
|
# If true, separate function names from parentheses with a space
|
||||||
|
separate_fn_name_with_space = False
|
||||||
|
|
||||||
|
# If a statement is wrapped to more than one line, than dangle the closing
|
||||||
|
# parenthesis on its own line.
|
||||||
|
dangle_parens = False
|
||||||
|
|
||||||
|
# If the trailing parenthesis must be 'dangled' on its on line, then align it
|
||||||
|
# to this reference: `prefix`: the start of the statement, `prefix-indent`:
|
||||||
|
# the start of the statement, plus one indentation level, `child`: align to
|
||||||
|
# the column of the arguments
|
||||||
|
dangle_align = 'prefix'
|
||||||
|
|
||||||
|
# If the statement spelling length (including space and parenthesis) is
|
||||||
|
# smaller than this amount, then force reject nested layouts.
|
||||||
|
min_prefix_chars = 4
|
||||||
|
|
||||||
|
# If the statement spelling length (including space and parenthesis) is larger
|
||||||
|
# than the tab width by more than this amount, then force reject un-nested
|
||||||
|
# layouts.
|
||||||
|
max_prefix_chars = 2
|
||||||
|
|
||||||
|
# If a candidate layout is wrapped horizontally but it exceeds this many
|
||||||
|
# lines, then reject the layout.
|
||||||
|
max_lines_hwrap = 2
|
||||||
|
|
||||||
|
# What style line endings to use in the output.
|
||||||
|
line_ending = 'unix'
|
||||||
|
|
||||||
|
# Format command names consistently as 'lower' or 'upper' case
|
||||||
|
command_case = 'canonical'
|
||||||
|
|
||||||
|
# Format keywords consistently as 'lower' or 'upper' case
|
||||||
|
keyword_case = 'upper'
|
||||||
|
|
||||||
|
# A list of command names which should always be wrapped
|
||||||
|
always_wrap = []
|
||||||
|
|
||||||
|
# If true, the argument lists which are known to be sortable will be sorted
|
||||||
|
# lexicographicall
|
||||||
|
enable_sort = True
|
||||||
|
|
||||||
|
# If true, the parsers may infer whether or not an argument list is sortable
|
||||||
|
# (without annotation).
|
||||||
|
autosort = False
|
||||||
|
|
||||||
|
# By default, if cmake-format cannot successfully fit everything into the
|
||||||
|
# desired linewidth it will apply the last, most agressive attempt that it
|
||||||
|
# made. If this flag is True, however, cmake-format will print error, exit
|
||||||
|
# with non-zero status code, and write-out nothing
|
||||||
|
require_valid_layout = False
|
||||||
|
|
||||||
|
# A dictionary mapping layout nodes to a list of wrap decisions. See the
|
||||||
|
# documentation for more information.
|
||||||
|
layout_passes = {}
|
||||||
|
|
||||||
|
# ------------------------------------------------
|
||||||
|
# Options affecting comment reflow and formatting.
|
||||||
|
# ------------------------------------------------
|
||||||
|
with section("markup"):
|
||||||
|
|
||||||
|
# What character to use for bulleted lists
|
||||||
|
bullet_char = '*'
|
||||||
|
|
||||||
|
# What character to use as punctuation after numerals in an enumerated list
|
||||||
|
enum_char = '.'
|
||||||
|
|
||||||
|
# If comment markup is enabled, don't reflow the first comment block in each
|
||||||
|
# listfile. Use this to preserve formatting of your copyright/license
|
||||||
|
# statements.
|
||||||
|
first_comment_is_literal = False
|
||||||
|
|
||||||
|
# If comment markup is enabled, don't reflow any comment block which matches
|
||||||
|
# this (regex) pattern. Default is `None` (disabled).
|
||||||
|
literal_comment_pattern = None
|
||||||
|
|
||||||
|
# Regular expression to match preformat fences in comments default=
|
||||||
|
# ``r'^\s*([`~]{3}[`~]*)(.*)$'``
|
||||||
|
fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
|
||||||
|
|
||||||
|
# Regular expression to match rulers in comments default=
|
||||||
|
# ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'``
|
||||||
|
ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
|
||||||
|
|
||||||
|
# If a comment line matches starts with this pattern then it is explicitly a
|
||||||
|
# trailing comment for the preceeding argument. Default is '#<'
|
||||||
|
explicit_trailing_pattern = '#<'
|
||||||
|
|
||||||
|
# If a comment line starts with at least this many consecutive hash
|
||||||
|
# characters, then don't lstrip() them off. This allows for lazy hash rulers
|
||||||
|
# where the first hash char is not separated by space
|
||||||
|
hashruler_min_length = 10
|
||||||
|
|
||||||
|
# If true, then insert a space between the first hash char and remaining hash
|
||||||
|
# chars in a hash ruler, and normalize its length to fill the column
|
||||||
|
canonicalize_hashrulers = True
|
||||||
|
|
||||||
|
# enable comment markup parsing and reflow
|
||||||
|
enable_markup = False
|
||||||
|
|
||||||
|
# ----------------------------
|
||||||
|
# Options affecting the linter
|
||||||
|
# ----------------------------
|
||||||
|
with section("lint"):
|
||||||
|
|
||||||
|
# a list of lint codes to disable
|
||||||
|
disabled_codes = ['C0113']
|
||||||
|
|
||||||
|
# regular expression pattern describing valid function names
|
||||||
|
function_pattern = '[0-9a-z_]+'
|
||||||
|
|
||||||
|
# regular expression pattern describing valid macro names
|
||||||
|
macro_pattern = '[0-9A-Z_]+'
|
||||||
|
|
||||||
|
# regular expression pattern describing valid names for variables with global
|
||||||
|
# scope
|
||||||
|
global_var_pattern = '[0-9A-Z][0-9A-Z_]+'
|
||||||
|
|
||||||
|
# regular expression pattern describing valid names for variables with global
|
||||||
|
# scope (but internal semantic)
|
||||||
|
internal_var_pattern = '_[0-9A-Z][0-9A-Z_]+'
|
||||||
|
|
||||||
|
# regular expression pattern describing valid names for variables with local
|
||||||
|
# scope
|
||||||
|
local_var_pattern = '[0-9a-z_]+'
|
||||||
|
|
||||||
|
# regular expression pattern describing valid names for privatedirectory
|
||||||
|
# variables
|
||||||
|
private_var_pattern = '_[0-9a-z_]+'
|
||||||
|
|
||||||
|
# regular expression pattern describing valid names for publicdirectory
|
||||||
|
# variables
|
||||||
|
public_var_pattern = '[0-9A-Z][0-9A-Z_]+'
|
||||||
|
|
||||||
|
# regular expression pattern describing valid names for keywords used in
|
||||||
|
# functions or macros
|
||||||
|
keyword_pattern = '[0-9A-Z_]+'
|
||||||
|
|
||||||
|
# In the heuristic for C0201, how many conditionals to match within a loop in
|
||||||
|
# before considering the loop a parser.
|
||||||
|
max_conditionals_custom_parser = 2
|
||||||
|
|
||||||
|
# Require at least this many newlines between statements
|
||||||
|
min_statement_spacing = 1
|
||||||
|
|
||||||
|
# Require no more than this many newlines between statements
|
||||||
|
max_statement_spacing = 2
|
||||||
|
max_returns = 6
|
||||||
|
max_branches = 12
|
||||||
|
max_arguments = 5
|
||||||
|
max_localvars = 15
|
||||||
|
max_statements = 50
|
||||||
|
|
||||||
|
# -------------------------------
|
||||||
|
# Options affecting file encoding
|
||||||
|
# -------------------------------
|
||||||
|
with section("encode"):
|
||||||
|
|
||||||
|
# If true, emit the unicode byte-order mark (BOM) at the start of the file
|
||||||
|
emit_byteorder_mark = False
|
||||||
|
|
||||||
|
# Specify the encoding of the input file. Defaults to utf-8
|
||||||
|
input_encoding = 'utf-8'
|
||||||
|
|
||||||
|
# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
|
||||||
|
# only claims to support utf-8 so be careful when using anything else
|
||||||
|
output_encoding = 'utf-8'
|
||||||
|
|
||||||
|
# -------------------------------------
|
||||||
|
# Miscellaneous configurations options.
|
||||||
|
# -------------------------------------
|
||||||
|
with section("misc"):
|
||||||
|
|
||||||
|
# A dictionary containing any per-command configuration overrides. Currently
|
||||||
|
# only `command_case` is supported.
|
||||||
|
per_command = {}
|
||||||
|
|
43
.gitignore
vendored
43
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
# Каталог для результатов сборки проекта
|
# Каталог для результатов сборки проекта
|
||||||
_build
|
_build
|
||||||
|
build
|
||||||
|
|
||||||
# Каталог для тестирования установки
|
# Каталог для тестирования установки
|
||||||
_output
|
_output
|
||||||
@ -13,6 +14,8 @@ files/etc/*.conf
|
|||||||
files/lib/*
|
files/lib/*
|
||||||
files/log/*
|
files/log/*
|
||||||
|
|
||||||
|
!.gitkeep
|
||||||
|
!.gitignore
|
||||||
|
|
||||||
###
|
###
|
||||||
### Общие настройки для C, C++, Fortran, Qt, CMake, Ninja, LaTeX и редакторов
|
### Общие настройки для C, C++, Fortran, Qt, CMake, Ninja, LaTeX и редакторов
|
||||||
@ -43,6 +46,8 @@ files/log/*
|
|||||||
[._]ss[a-gi-z]
|
[._]ss[a-gi-z]
|
||||||
[._]sw[a-p]
|
[._]sw[a-p]
|
||||||
|
|
||||||
|
# Project
|
||||||
|
.vimprj
|
||||||
# Temporary
|
# Temporary
|
||||||
.netrwhist
|
.netrwhist
|
||||||
*~
|
*~
|
||||||
@ -106,6 +111,10 @@ compile_commands.json
|
|||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
_deps
|
_deps
|
||||||
|
|
||||||
|
### CMake Patch ###
|
||||||
|
# External projects
|
||||||
|
*-prefix/
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
### Ninja
|
### Ninja
|
||||||
@ -162,6 +171,38 @@ target_wrapper.*
|
|||||||
*_qmlcache.qrc
|
*_qmlcache.qrc
|
||||||
|
|
||||||
|
|
||||||
|
### KDevelop4 ###
|
||||||
|
*.kdev4
|
||||||
|
.kdev4/
|
||||||
|
|
||||||
|
|
||||||
|
### vscode ###
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
*.code-workspace
|
||||||
|
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.metadata
|
||||||
|
.settings/
|
||||||
|
.recommenders/
|
||||||
|
|
||||||
|
# TeXlipse
|
||||||
|
.texlipse
|
||||||
|
|
||||||
|
# PyDev specific (Python IDE for Eclipse)
|
||||||
|
*.pydevproject
|
||||||
|
|
||||||
|
# CDT-specific (C/C++ Development Tooling)
|
||||||
|
.cproject
|
||||||
|
|
||||||
|
# CDT- autotools
|
||||||
|
.autotools
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
### Latex
|
### Latex
|
||||||
###
|
###
|
||||||
@ -173,6 +214,7 @@ target_wrapper.*
|
|||||||
*.blg
|
*.blg
|
||||||
*.dvi
|
*.dvi
|
||||||
*.fdb_latexmk
|
*.fdb_latexmk
|
||||||
|
*.fls
|
||||||
*.glg
|
*.glg
|
||||||
*.glo
|
*.glo
|
||||||
*.gls
|
*.gls
|
||||||
@ -195,6 +237,7 @@ target_wrapper.*
|
|||||||
*.synctex.gz
|
*.synctex.gz
|
||||||
*.toc
|
*.toc
|
||||||
*.vrb
|
*.vrb
|
||||||
|
*.xdv
|
||||||
*.xdy
|
*.xdy
|
||||||
*.tdo
|
*.tdo
|
||||||
|
|
||||||
|
@ -18,3 +18,7 @@ focal-nightly:
|
|||||||
elbrus-nightly:
|
elbrus-nightly:
|
||||||
extends: .scheduled-elbrus
|
extends: .scheduled-elbrus
|
||||||
|
|
||||||
|
check-format-sources:
|
||||||
|
only:
|
||||||
|
- merge_requests
|
||||||
|
extends: .check-format-sources
|
||||||
|
15
.gitmodules
vendored
15
.gitmodules
vendored
@ -1,15 +0,0 @@
|
|||||||
[submodule "cmake/etc/uncrustify"]
|
|
||||||
path = cmake/etc/uncrustify
|
|
||||||
url = ../../f1x1t/uncrustify-config.git
|
|
||||||
[submodule "cmake/cmlib"]
|
|
||||||
path = cmake/cmlib
|
|
||||||
url = ../../f1x1t/cmlib
|
|
||||||
[submodule "cmake/find"]
|
|
||||||
path = cmake/find
|
|
||||||
url = ../../f1x1t/cmake-find
|
|
||||||
[submodule "cmake/generators"]
|
|
||||||
path = cmake/generators
|
|
||||||
url = ../../f1x1t/cmake-generators
|
|
||||||
[submodule "cmake/doc"]
|
|
||||||
path = cmake/doc
|
|
||||||
url = ../../f1x1t/cmake-doc
|
|
3371
.uncrustify.cfg
Normal file
3371
.uncrustify.cfg
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,15 +3,13 @@ cmake_minimum_required(VERSION 3.3)
|
|||||||
cmake_policy(VERSION 3.0.2..3.7)
|
cmake_policy(VERSION 3.0.2..3.7)
|
||||||
|
|
||||||
# Название проекта
|
# Название проекта
|
||||||
project(myx VERSION 0.4.0 LANGUAGES C CXX)
|
project(myx VERSION 0.9.0 LANGUAGES C CXX)
|
||||||
|
|
||||||
# В каталоге cmake/lib находятся файлы с библиотечными функциями
|
# Обязательные переменные
|
||||||
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/cmake/cmlib)
|
set(MYX_CMAKE_ORGANIZATION_NAME "ECS5" CACHE STRING "")
|
||||||
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/cmlib)
|
set(MYX_CMAKE_AUTHOR_NAME "Андрей Астафьев" CACHE STRING "")
|
||||||
else()
|
set(MYX_CMAKE_AUTHOR_EMAIL "dev@246060.ru" CACHE STRING "")
|
||||||
message(FATAL_ERROR "CMake library directory not exists")
|
set(MYX_CMAKE_DESCRIPTION "Разные функции" CACHE STRING "")
|
||||||
endif()
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/find)
|
|
||||||
|
|
||||||
if(NOT DEFINED MYXLIB_MASTER_PROJECT)
|
if(NOT DEFINED MYXLIB_MASTER_PROJECT)
|
||||||
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||||
@ -21,13 +19,10 @@ if(NOT DEFINED MYXLIB_MASTER_PROJECT)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(CMLibCommon)
|
find_package(MyxCMake 0.4.5 REQUIRED)
|
||||||
|
|
||||||
option(MYXLIB_BUILD_LIBRARIES "Build libraries" OFF)
|
#cmlib_set_cxx_standard(11)
|
||||||
if(MYXLIB_BUILD_LIBRARIES)
|
option(MYXLIB_BUILD_EXAMPLES "Build examples" OFF)
|
||||||
option(MYXLIB_BUILD_EXAMPLES "Build examples" OFF)
|
|
||||||
endif()
|
|
||||||
option(MYXLIB_BUILD_EXAMPLES_HO "Build examples using header only version" OFF)
|
|
||||||
|
|
||||||
# Поиск библиотек с помощью pkgconfig
|
# Поиск библиотек с помощью pkgconfig
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
@ -39,17 +34,28 @@ find_package(Threads REQUIRED)
|
|||||||
# Qt5
|
# Qt5
|
||||||
find_package(Qt5 COMPONENTS Core Network REQUIRED)
|
find_package(Qt5 COMPONENTS Core Network REQUIRED)
|
||||||
|
|
||||||
|
myx_cmake_generate_private_config_header()
|
||||||
|
|
||||||
# Библиотеки
|
# Библиотеки
|
||||||
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/filesystem)
|
||||||
add_subdirectory(src/myx/qt)
|
add_subdirectory(src/myx/qt)
|
||||||
|
|
||||||
|
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
||||||
|
add_custom_target(myxlib-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=dev -P
|
||||||
|
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
||||||
# Примеры
|
# Примеры
|
||||||
if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO)
|
if(MYXLIB_BUILD_EXAMPLES)
|
||||||
add_subdirectory(examples/base)
|
add_subdirectory(examples/core)
|
||||||
add_subdirectory(examples/filesystem)
|
add_subdirectory(examples/filesystem)
|
||||||
add_subdirectory(examples/qt)
|
add_subdirectory(examples/qt)
|
||||||
|
add_custom_target(examples example-core-endian example-filesystem-paths example-qt-tranlators
|
||||||
|
example-qt-posix-signal-watcher)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Документация
|
# Документация
|
||||||
add_subdirectory(cmake/doc)
|
myx_cmake_doc_doxygen(LATEX YES HTML YES)
|
||||||
|
myx_cmake_doc_breathe()
|
||||||
|
Submodule cmake/cmlib deleted from 23be253a8d
Submodule cmake/doc deleted from dc9622f57e
@ -1,12 +0,0 @@
|
|||||||
set(ORGANIZATION_NAME "RTIS")
|
|
||||||
set(AUTHOR_NAME "Андрей Астафьев")
|
|
||||||
|
|
||||||
set(DOXYGEN_PROJECT_TITLE "MyXLib")
|
|
||||||
set(DOXYGEN_GENERATE_LATEX YES)
|
|
||||||
set(DOXYGEN_GENERATE_HTML YES)
|
|
||||||
|
|
||||||
set(CPACK_COMPONENTS_ALL examples)
|
|
||||||
set(CPACK_PACKAGE_CONTACT "Andrei Astafev <dev@246060.ru>")
|
|
||||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Mixed functions")
|
|
||||||
|
|
||||||
set(CMLIB_GENERATED_HEADERS_PATH ${CMAKE_BINARY_DIR}/include/myx/base)
|
|
Submodule cmake/etc/uncrustify deleted from 7324d80f3d
Submodule cmake/find deleted from 00bbf686cd
Submodule cmake/generators deleted from 74d499b9cb
@ -1,77 +0,0 @@
|
|||||||
# Название основной цели в текущем каталоге
|
|
||||||
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()
|
|
@ -1 +0,0 @@
|
|||||||
add_subdirectory(01_endian)
|
|
21
examples/core/01_endian/CMakeLists.txt
Normal file
21
examples/core/01_endian/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Название основной цели в текущем каталоге
|
||||||
|
set(TRGT example-core-endian)
|
||||||
|
|
||||||
|
# Список файлов исходных текстов
|
||||||
|
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/endian.cpp)
|
||||||
|
|
||||||
|
if(MYXLIB_BUILD_EXAMPLES)
|
||||||
|
# Цель для создания исполняемого файла
|
||||||
|
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
||||||
|
myx_cmake_common_target_properties(${TRGT})
|
||||||
|
|
||||||
|
# Имя выходного файла для цели
|
||||||
|
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME endian-minimal)
|
||||||
|
|
||||||
|
# Qt5
|
||||||
|
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||||
|
add_dependencies(${TRGT} core)
|
||||||
|
|
||||||
|
target_link_libraries(${TRGT} Qt5::Core)
|
||||||
|
target_link_libraries(${TRGT} Threads::Threads)
|
||||||
|
endif()
|
@ -1,12 +1,11 @@
|
|||||||
#include <myx/base/config.hpp>
|
#include <myx/core/config.hpp>
|
||||||
#include <myx/base/endian_types.hpp>
|
#include <myx/core/endian_types.hpp>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
//NOLINTNEXTLINE
|
||||||
#define CMLIB_PROJECT_NAME "myxlib"
|
#define CMLIB_PROJECT_NAME "myxlib"
|
||||||
|
|
||||||
namespace MB = myx::base;
|
|
||||||
|
|
||||||
|
|
||||||
int main( int argc, char** argv )
|
int main( int argc, char** argv )
|
||||||
{
|
{
|
||||||
@ -14,11 +13,11 @@ int main( int argc, char** argv )
|
|||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
beint64 bi = 1;
|
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;
|
qDebug() << hex << bi << bii;
|
||||||
|
|
||||||
leint64 li = 1;
|
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;
|
qDebug() << hex << li << lii;
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
21
examples/core/02_current-system/CMakeLists.txt
Normal file
21
examples/core/02_current-system/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Название основной цели в текущем каталоге
|
||||||
|
set(TRGT example-core-current-system)
|
||||||
|
|
||||||
|
# Список файлов исходных текстов
|
||||||
|
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/current_system.cpp)
|
||||||
|
|
||||||
|
if(MYXLIB_BUILD_EXAMPLES)
|
||||||
|
# Цель для создания исполняемого файла
|
||||||
|
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
||||||
|
myx_cmake_common_target_properties(${TRGT})
|
||||||
|
|
||||||
|
# Имя выходного файла для цели
|
||||||
|
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME current-system-minimal)
|
||||||
|
|
||||||
|
# Qt5
|
||||||
|
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||||
|
add_dependencies(${TRGT} core)
|
||||||
|
|
||||||
|
target_link_libraries(${TRGT} Qt5::Core)
|
||||||
|
target_link_libraries(${TRGT} Threads::Threads)
|
||||||
|
endif()
|
23
examples/core/02_current-system/current_system.cpp
Normal file
23
examples/core/02_current-system/current_system.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <myx/core/config.hpp>
|
||||||
|
#include <myx/core/current_system.hpp>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
//NOLINTNEXTLINE
|
||||||
|
#define CMLIB_PROJECT_NAME "myxlib"
|
||||||
|
|
||||||
|
namespace MC = myx::core;
|
||||||
|
|
||||||
|
int main( int argc, char** argv )
|
||||||
|
{
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
|
||||||
|
MC::CurrentSystem& currentSystem = MC::CurrentSystem::instance();
|
||||||
|
qDebug() << "Current OS: " << QString::fromStdString( currentSystem.os() );
|
||||||
|
qDebug() << "OS distrib: " << QString::fromStdString( currentSystem.distribution() );
|
||||||
|
qDebug() << "OS variant: " << QString::fromStdString( currentSystem.variant() );
|
||||||
|
qDebug() << "OS version: " << QString::fromStdString( currentSystem.version() );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
} // main
|
2
examples/core/CMakeLists.txt
Normal file
2
examples/core/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
add_subdirectory(01_endian)
|
||||||
|
add_subdirectory(02_current-system)
|
@ -1,77 +0,0 @@
|
|||||||
# Название основной цели в текущем каталоге
|
|
||||||
set(TRGT example-filesystem-minimal)
|
|
||||||
|
|
||||||
# Список файлов исходных текстов
|
|
||||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/minimal.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 filesystem)
|
|
||||||
|
|
||||||
target_link_libraries(${TRGT} base_static filesystem_static)
|
|
||||||
target_link_libraries(${TRGT} Qt5::Core)
|
|
||||||
target_link_libraries(${TRGT} Threads::Threads)
|
|
||||||
|
|
||||||
# Имя выходного файла для цели
|
|
||||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME filesystem-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 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()
|
|
22
examples/filesystem/01_paths/CMakeLists.txt
Normal file
22
examples/filesystem/01_paths/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Название основной цели в текущем каталоге
|
||||||
|
set(TRGT example-filesystem-paths)
|
||||||
|
|
||||||
|
# Список файлов исходных текстов
|
||||||
|
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp)
|
||||||
|
|
||||||
|
if(MYXLIB_BUILD_EXAMPLES)
|
||||||
|
# Цель для создания исполняемого файла
|
||||||
|
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
||||||
|
myx_cmake_common_target_properties(${TRGT})
|
||||||
|
|
||||||
|
# Имя выходного файла для цели
|
||||||
|
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME filesystem-minimal)
|
||||||
|
|
||||||
|
# Qt5
|
||||||
|
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||||
|
add_dependencies(${TRGT} core filesystem)
|
||||||
|
|
||||||
|
target_link_libraries(${TRGT} filesystem-static)
|
||||||
|
target_link_libraries(${TRGT} Qt5::Core)
|
||||||
|
target_link_libraries(${TRGT} Threads::Threads)
|
||||||
|
endif()
|
@ -1,10 +1,11 @@
|
|||||||
#include <myx/base/config.hpp>
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
#include <myx/filesystem/paths.hpp>
|
#include <myx/filesystem/paths.hpp>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
//NOLINTNEXTLINE
|
||||||
#define CMLIB_PROJECT_NAME "myxlib"
|
#define CMLIB_PROJECT_NAME "myxlib"
|
||||||
|
|
||||||
namespace MF = myx::filesystem;
|
namespace MF = myx::filesystem;
|
||||||
@ -17,22 +18,19 @@ int main( int argc, char** argv )
|
|||||||
QCoreApplication::setApplicationName( QStringLiteral( CMLIB_PROJECT_NAME ) );
|
QCoreApplication::setApplicationName( QStringLiteral( CMLIB_PROJECT_NAME ) );
|
||||||
MF::Paths& paths = MF::Paths::instance();
|
MF::Paths& paths = MF::Paths::instance();
|
||||||
|
|
||||||
paths.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) );
|
qDebug() << "prefixDirectory : " << paths.projectDirectory();
|
||||||
|
|
||||||
qDebug() << "prefixDirectory : " << paths.prefixDirectory();
|
|
||||||
|
|
||||||
qDebug() << "executableName : " << paths.executableName();
|
qDebug() << "executableName : " << paths.executableName();
|
||||||
qDebug() << "executableFilePath : " << paths.executableFilePath();
|
qDebug() << "executableFilePath : " << paths.executableFilePath();
|
||||||
qDebug() << "executableDirectory : " << paths.executableDirectory();
|
qDebug() << "executableDirectory : " << paths.executableDirectory() << endl;
|
||||||
|
|
||||||
qDebug() << "configFileName : " << paths.configFileName();
|
|
||||||
qDebug() << "configFilePath : " << paths.configFilePath();
|
|
||||||
|
|
||||||
|
qDebug() << "systemThemeDirectory : " << paths.systemThemeDirectory();
|
||||||
qDebug() << "systemConfigDirectory : " << paths.systemConfigDirectory();
|
qDebug() << "systemConfigDirectory : " << paths.systemConfigDirectory();
|
||||||
qDebug() << "systemConstDataDirectory : " << paths.systemConstDataDirectory();
|
qDebug() << "systemConstDataDirectory : " << paths.systemConstDataDirectory();
|
||||||
qDebug() << "systemVarDataDirectory : " << paths.systemVarDataDirectory();
|
qDebug() << "systemVarDataDirectory : " << paths.systemVarDataDirectory();
|
||||||
qDebug() << "systemLogDirectory : " << paths.systemLogDirectory();
|
qDebug() << "systemLogDirectory : " << paths.systemLogDirectory() << endl;
|
||||||
|
|
||||||
|
qDebug() << "userThemeDirectory : " << paths.userThemeDirectory();
|
||||||
qDebug() << "userConfigDirectory : " << paths.userConfigDirectory();
|
qDebug() << "userConfigDirectory : " << paths.userConfigDirectory();
|
||||||
qDebug() << "userConstDataDirectory : " << paths.userConstDataDirectory();
|
qDebug() << "userConstDataDirectory : " << paths.userConstDataDirectory();
|
||||||
qDebug() << "userVarDataDirectory : " << paths.userVarDataDirectory();
|
qDebug() << "userVarDataDirectory : " << paths.userVarDataDirectory();
|
@ -1 +1 @@
|
|||||||
add_subdirectory(01_minimal)
|
add_subdirectory(01_paths)
|
||||||
|
@ -4,82 +4,26 @@ set(TRGT example-qt-translators)
|
|||||||
# Список файлов исходных текстов
|
# Список файлов исходных текстов
|
||||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp)
|
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp)
|
||||||
|
|
||||||
qt5_translation(
|
myx_cmake_qt5_translation(
|
||||||
TRGT_qrc
|
TRGT_qrc
|
||||||
OUTPUT_DIR ${CMAKE_SOURCE_DIR}/l10n
|
OUTPUT_DIR ${CMAKE_SOURCE_DIR}/l10n
|
||||||
BASE_NAME ${TRGT}
|
BASE_NAME ${TRGT}
|
||||||
LANGUAGES ru_RU)
|
LANGUAGES ru_RU)
|
||||||
|
|
||||||
if(MYXLIB_BUILD_EXAMPLES)
|
if(MYXLIB_BUILD_EXAMPLES)
|
||||||
|
|
||||||
# Путь поиска библиотек внутри проекта
|
|
||||||
link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
|
||||||
|
|
||||||
# Цель для создания исполняемого файла
|
# Цель для создания исполняемого файла
|
||||||
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
||||||
common_target_properties(${TRGT})
|
myx_cmake_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-translators)
|
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME qt-translators)
|
||||||
|
|
||||||
add_sanitizers(${TRGT})
|
# Qt5
|
||||||
|
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||||
|
add_dependencies(${TRGT} core qt)
|
||||||
|
|
||||||
cotire(${TRGT})
|
target_link_libraries(${TRGT} qt-static)
|
||||||
|
|
||||||
add_dependencies(${TRGT} create_auxilary_symlinks)
|
target_link_libraries(${TRGT} Qt5::Core)
|
||||||
|
target_link_libraries(${TRGT} Threads::Threads)
|
||||||
# Правила для установки
|
|
||||||
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()
|
endif()
|
||||||
|
23
examples/qt/02_posix-signal-watcher/CMakeLists.txt
Normal file
23
examples/qt/02_posix-signal-watcher/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Название основной цели в текущем каталоге
|
||||||
|
set(TRGT example-qt-posix-signal-watcher)
|
||||||
|
|
||||||
|
# Список файлов исходных текстов
|
||||||
|
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher.cpp)
|
||||||
|
|
||||||
|
if(MYXLIB_BUILD_EXAMPLES)
|
||||||
|
# Цель для создания исполняемого файла
|
||||||
|
add_executable(${TRGT} ${TRGT_cpp})
|
||||||
|
myx_cmake_common_target_properties(${TRGT})
|
||||||
|
|
||||||
|
# Имя выходного файла для цели
|
||||||
|
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME qt-posix-signal-watcher)
|
||||||
|
|
||||||
|
# Qt5
|
||||||
|
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||||
|
add_dependencies(${TRGT} core qt)
|
||||||
|
|
||||||
|
target_link_libraries(${TRGT} qt-static)
|
||||||
|
|
||||||
|
target_link_libraries(${TRGT} Qt5::Core)
|
||||||
|
target_link_libraries(${TRGT} Threads::Threads)
|
||||||
|
endif()
|
21
examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp
Normal file
21
examples/qt/02_posix-signal-watcher/posix_signal_watcher.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <myx/qt/posix_signal_watcher.hpp>
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
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 = QCoreApplication::exec();
|
||||||
|
qDebug() << "Goodbye";
|
||||||
|
return( exitcode );
|
||||||
|
}
|
23
examples/qt/03_message-logger/CMakeLists.txt
Normal file
23
examples/qt/03_message-logger/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Название основной цели в текущем каталоге
|
||||||
|
set(TRGT example-qt-message-logger)
|
||||||
|
|
||||||
|
# Список файлов исходных текстов
|
||||||
|
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/message_logger.cpp)
|
||||||
|
|
||||||
|
if(MYXLIB_BUILD_EXAMPLES)
|
||||||
|
# Цель для создания исполняемого файла
|
||||||
|
add_executable(${TRGT} ${TRGT_cpp})
|
||||||
|
myx_cmake_common_target_properties(${TRGT})
|
||||||
|
|
||||||
|
# Имя выходного файла для цели
|
||||||
|
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME qt-message-logger)
|
||||||
|
|
||||||
|
# Qt5
|
||||||
|
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||||
|
add_dependencies(${TRGT} core qt)
|
||||||
|
|
||||||
|
target_link_libraries(${TRGT} qt-static)
|
||||||
|
|
||||||
|
target_link_libraries(${TRGT} Qt5::Core)
|
||||||
|
target_link_libraries(${TRGT} Threads::Threads)
|
||||||
|
endif()
|
29
examples/qt/03_message-logger/message_logger.cpp
Normal file
29
examples/qt/03_message-logger/message_logger.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <myx/qt/message_logger_default.hpp>
|
||||||
|
#include <myx/qt/message_logger_handler.hpp>
|
||||||
|
#include <myx/qt/message_logger_syslog.hpp>
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
namespace MQ = myx::qt;
|
||||||
|
int main( int argc, char* argv[] )
|
||||||
|
{
|
||||||
|
QCoreApplication app( argc, argv );
|
||||||
|
|
||||||
|
auto mld = QSharedPointer< MQ::MessageLoggerDefault >( new MQ::MessageLoggerDefault );
|
||||||
|
MQ::messageLoggersList.append( mld );
|
||||||
|
MQ::messageLoggersList.append( mld );
|
||||||
|
auto mls = QSharedPointer< MQ::MessageLoggerSyslog >( new MQ::MessageLoggerSyslog );
|
||||||
|
MQ::messageLoggersList.append( mls );
|
||||||
|
qInstallMessageHandler( MQ::message_logger_handler );
|
||||||
|
|
||||||
|
qDebug() << "Hello from process:" << QCoreApplication::applicationPid();
|
||||||
|
qWarning() << "Warning";
|
||||||
|
|
||||||
|
qInstallMessageHandler( nullptr );
|
||||||
|
|
||||||
|
qDebug() << "Reset user handlers";
|
||||||
|
qWarning() << "Goodbye";
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
@ -1 +1,3 @@
|
|||||||
add_subdirectory(01_translators)
|
add_subdirectory(01_translators)
|
||||||
|
add_subdirectory(02_posix-signal-watcher)
|
||||||
|
add_subdirectory(03_message-logger)
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 86 KiB |
0
files/var/.gitkeep
Normal file
0
files/var/.gitkeep
Normal file
21
src/myx/backports/compiler/CMakeLists.txt
Normal file
21
src/myx/backports/compiler/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Название основной цели и имя библиотеки в текущем каталоге
|
||||||
|
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})
|
||||||
|
|
||||||
|
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||||
|
install(FILES ${TRGT_headers} COMPONENT dev
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/backports/compiler)
|
29
src/myx/backports/compiler/gcc.hpp
Normal file
29
src/myx/backports/compiler/gcc.hpp
Normal file
@ -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
|
||||||
|
|
||||||
|
#if ( __cplusplus < 201103L )
|
||||||
|
#define constexpr
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define override
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // if GCC_VERSION <= 40702
|
||||||
|
#endif // ifdef __GNUC__
|
||||||
|
|
||||||
|
#endif // ifndef MYX_BACKPORTS_COMPILER_GCC_HPP_
|
22
src/myx/backports/cpp/CMakeLists.txt
Normal file
22
src/myx/backports/cpp/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Название основной цели и имя библиотеки в текущем каталоге
|
||||||
|
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})
|
||||||
|
|
||||||
|
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||||
|
install(FILES ${TRGT_headers} COMPONENT dev
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/backports/cpp)
|
46
src/myx/backports/cpp/helpers.hpp
Normal file
46
src/myx/backports/cpp/helpers.hpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#ifndef MYX_BACKPORTS_CPP_HELPERS_HPP_
|
||||||
|
#define MYX_BACKPORTS_CPP_HELPERS_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if ( __cplusplus >= 201103L )
|
||||||
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ( __cplusplus >= 201103L ) && ( __cplusplus < 201402L )
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
|
||||||
|
template< class T >
|
||||||
|
using underlying_type_t = typename std::underlying_type< T >::type;
|
||||||
|
|
||||||
|
template< typename T, typename ... Args >
|
||||||
|
std::unique_ptr< T > make_unique( Args&&... args )
|
||||||
|
{
|
||||||
|
return( std::unique_ptr< T >( new T( std::forward< Args >( args )... ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ( ( __cplusplus >= 201103L ) && ( __cplusplus < 201402L ) ) || \
|
||||||
|
( ( __cplusplus >= 201402L ) && ( __cplusplus < 201702L ) && defined( __STRICT_ANSI__ ) )
|
||||||
|
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
|
||||||
|
template< typename ... Ts > struct make_void { typedef void type; };
|
||||||
|
|
||||||
|
#ifndef __cpp_lib_void_t
|
||||||
|
template< typename ... Ts > using void_t = typename make_void< Ts... >::type;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ifndef MYX_BACKPORTS_CPP_HELPERS_HPP_
|
@ -7,20 +7,25 @@
|
|||||||
// Official repository: https://github.com/boostorg/beast
|
// Official repository: https://github.com/boostorg/beast
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef MYX_BASE_SPAN_HPP_
|
#ifndef MYX_BACKPORTS_CPP_SPAN_HPP_
|
||||||
#define MYX_BASE_SPAN_HPP_
|
#define MYX_BACKPORTS_CPP_SPAN_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if ( __cplusplus > 201703L )
|
||||||
|
|
||||||
|
#include <span>
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <myx/backports/cpp/helpers.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace myx {
|
namespace std { //-V1061
|
||||||
|
|
||||||
namespace base {
|
|
||||||
|
|
||||||
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 >
|
template< class T, class E, class = void >
|
||||||
struct is_contiguous_container : std::false_type {}; // NOLINT
|
struct is_contiguous_container : std::false_type {}; // NOLINT
|
||||||
@ -59,31 +64,31 @@ class span //
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/// The type of value, including cv qualifiers
|
/// The type of value, including cv qualifiers
|
||||||
using element_type = T;
|
using ElementType = T;
|
||||||
|
|
||||||
/// The type of value of each span element
|
/// 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
|
/// 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
|
/// A pointer to a span element
|
||||||
using pointer = T*;
|
using Pointer = T*;
|
||||||
|
|
||||||
/// A reference to a span element
|
/// A reference to a span element
|
||||||
using reference = T&;
|
using Reference = T&;
|
||||||
|
|
||||||
/// The iterator used by the container
|
/// The iterator used by the container
|
||||||
using iterator = pointer;
|
using Iterator = Pointer;
|
||||||
|
|
||||||
/// The const pointer used by the container
|
/// The const pointer used by the container
|
||||||
using const_pointer = T const*;
|
using ConstPointer = T const*;
|
||||||
|
|
||||||
/// The const reference used by the container
|
/// The const reference used by the container
|
||||||
using const_reference = T const&;
|
using ConstReference = T const&;
|
||||||
|
|
||||||
/// The const iterator used by the container
|
/// The const iterator used by the container
|
||||||
using const_iterator = const_pointer;
|
using ConstIterator = ConstPointer;
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
span() = default;
|
span() = default;
|
||||||
@ -95,10 +100,8 @@ public:
|
|||||||
span& operator=( span const& ) = default;
|
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`
|
||||||
|
|
||||||
@param size The number of elements pointed to by `data`
|
|
||||||
*/
|
*/
|
||||||
span( T* data, std::size_t size ) :
|
span( T* data, std::size_t size ) :
|
||||||
m_data( data ),
|
m_data( data ),
|
||||||
@ -106,10 +109,8 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Constructor
|
/** Constructor
|
||||||
|
* @param container The container to construct from
|
||||||
@param container The container to construct from
|
|
||||||
*/
|
*/
|
||||||
template< class ContiguousContainer,
|
template< class ContiguousContainer,
|
||||||
class = typename std::enable_if<
|
class = typename std::enable_if<
|
||||||
@ -123,7 +124,6 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class CharT, class Traits, class Allocator >
|
template< class CharT, class Traits, class Allocator >
|
||||||
explicit
|
explicit
|
||||||
span( std::basic_string< CharT, Traits, Allocator >& s ) :
|
span( std::basic_string< CharT, Traits, Allocator >& s ) :
|
||||||
@ -132,7 +132,6 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class CharT, class Traits, class Allocator >
|
template< class CharT, class Traits, class Allocator >
|
||||||
explicit
|
explicit
|
||||||
span( std::basic_string< CharT, Traits, Allocator > const& s ) :
|
span( std::basic_string< CharT, Traits, Allocator > const& s ) :
|
||||||
@ -141,13 +140,11 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Assignment
|
/** Assignment
|
||||||
|
* @param container The container to assign from
|
||||||
@param container The container to assign from
|
|
||||||
*/
|
*/
|
||||||
template< class ContiguousContainer >
|
template< class ContiguousContainer >
|
||||||
typename std::enable_if< is_contiguous_container<
|
typename std::enable_if< is_contiguous_container< //NOLINT
|
||||||
ContiguousContainer, T >::value,
|
ContiguousContainer, T >::value,
|
||||||
span& >::type
|
span& >::type
|
||||||
operator=( ContiguousContainer&& container )
|
operator=( ContiguousContainer&& container )
|
||||||
@ -157,7 +154,6 @@ public:
|
|||||||
return( *this );
|
return( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class CharT, class Traits, class Allocator >
|
template< class CharT, class Traits, class Allocator >
|
||||||
span&
|
span&
|
||||||
operator=( std::basic_string<
|
operator=( std::basic_string<
|
||||||
@ -168,7 +164,6 @@ public:
|
|||||||
return( *this );
|
return( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template< class CharT, class Traits, class Allocator >
|
template< class CharT, class Traits, class Allocator >
|
||||||
span&
|
span&
|
||||||
operator=( std::basic_string<
|
operator=( std::basic_string<
|
||||||
@ -179,7 +174,6 @@ public:
|
|||||||
return( *this );
|
return( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns `true` if the span is empty
|
/// Returns `true` if the span is empty
|
||||||
bool
|
bool
|
||||||
empty() const
|
empty() const
|
||||||
@ -187,7 +181,6 @@ public:
|
|||||||
return( m_size == 0 );
|
return( m_size == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns a pointer to the beginning of the span
|
/// Returns a pointer to the beginning of the span
|
||||||
T*
|
T*
|
||||||
data() const
|
data() const
|
||||||
@ -195,7 +188,6 @@ public:
|
|||||||
return( m_data );
|
return( m_data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns the number of elements in the span
|
/// Returns the number of elements in the span
|
||||||
std::size_t
|
std::size_t
|
||||||
size() const
|
size() const
|
||||||
@ -203,41 +195,37 @@ public:
|
|||||||
return( m_size );
|
return( m_size );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns an iterator to the beginning of the span
|
/// Returns an iterator to the beginning of the span
|
||||||
iterator
|
Iterator
|
||||||
begin() const
|
begin() const
|
||||||
{
|
{
|
||||||
return( m_data );
|
return( m_data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns an iterator to the beginning of the span
|
/// Returns an iterator to the beginning of the span
|
||||||
const_iterator
|
ConstIterator
|
||||||
cbegin() const
|
cbegin() const
|
||||||
{
|
{
|
||||||
return( m_data );
|
return( m_data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns an iterator to one past the end of the span
|
/// Returns an iterator to one past the end of the span
|
||||||
iterator
|
Iterator
|
||||||
end() const
|
end() const
|
||||||
{
|
{
|
||||||
return( m_data + m_size );
|
return( m_data + m_size );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns an iterator to one past the end of the span
|
/// Returns an iterator to one past the end of the span
|
||||||
const_iterator
|
ConstIterator
|
||||||
cend() const
|
cend() const
|
||||||
{
|
{
|
||||||
return( m_data + m_size );
|
return( m_data + m_size );
|
||||||
}
|
}
|
||||||
}; // class span
|
}; // class span
|
||||||
|
|
||||||
} // namespace base
|
} // namespace std
|
||||||
|
|
||||||
} // namespace myx
|
#endif // if ( __cplusplus > 201703L )
|
||||||
|
|
||||||
#endif // ifndef MYX_BASE_SPAN_HPP_
|
#endif // ifndef MYX_BACKPORTS_CPP_SPAN_HPP_
|
21
src/myx/backports/qt/CMakeLists.txt
Normal file
21
src/myx/backports/qt/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Название основной цели и имя библиотеки в текущем каталоге
|
||||||
|
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})
|
||||||
|
|
||||||
|
install(FILES ${TRGT_headers} COMPONENT dev
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/backports/qt)
|
||||||
|
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
@ -1,14 +1,13 @@
|
|||||||
#ifndef MYX_QT_BACKPORTS_HPP_
|
#ifndef MYX_BACKPORTS_QT_COMMON_HPP_
|
||||||
#define MYX_QT_BACKPORTS_HPP_
|
#define MYX_BACKPORTS_QT_COMMON_HPP_
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if ( defined ( TARGET_LSB_ID_AstraLinuxSE ) && defined ( TARGET_LSB_CODENAME_smolensk ) )
|
#if !defined( QT_VERSION )
|
||||||
|
|
||||||
#define override
|
|
||||||
|
|
||||||
#if QT_VERSION <= 0x050700
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ( QT_VERSION <= 0x050700 )
|
||||||
template< typename ... Args >
|
template< typename ... Args >
|
||||||
struct QOverload
|
struct QOverload
|
||||||
{
|
{
|
||||||
@ -31,8 +30,6 @@ Q_DECL_CONSTEXPR typename std::add_const< T >::type& qAsConst( T& t ) noexcept
|
|||||||
template < typename T >
|
template < typename T >
|
||||||
void qAsConst( const T&& ) = delete;
|
void qAsConst( const T&& ) = delete;
|
||||||
|
|
||||||
|
|
||||||
#endif // if QT_VERSION <= 0x050700
|
#endif // if QT_VERSION <= 0x050700
|
||||||
#endif // if ( defined ( TARGET_LSB_ID_AstraLinuxSE ) && defined ( TARGET_LSB_CODENAME_smolensk ) )
|
|
||||||
|
|
||||||
#endif // MYX_QT_BACKPORTS_HPP_
|
#endif // MYX_BACKPORTS_QT_COMMON_HPP_
|
@ -1,61 +0,0 @@
|
|||||||
# Название основной цели и имя библиотеки в текущем каталоге
|
|
||||||
set(TRGT base)
|
|
||||||
|
|
||||||
# cmake-format: off
|
|
||||||
# Список файлов исходных текстов
|
|
||||||
set(TRGT_cpp
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/config.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_library(${TRGT}-header-only INTERFACE)
|
|
||||||
target_include_directories(
|
|
||||||
${TRGT}-header-only SYSTEM INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
|
||||||
|
|
||||||
if(MYXLIB_BUILD_LIBRARIES)
|
|
||||||
add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers})
|
|
||||||
common_target_properties(${TRGT})
|
|
||||||
|
|
||||||
# Создание цели для проверки утилитой 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_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})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
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
|
|
||||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT})
|
|
||||||
|
|
||||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
|
||||||
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
|
|
||||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
@ -1,10 +0,0 @@
|
|||||||
#ifndef MYX_BASE_CONFIG_CPP_
|
|
||||||
#define MYX_BASE_CONFIG_CPP_
|
|
||||||
|
|
||||||
#ifndef MYXLIB_HEADER_ONLY
|
|
||||||
#include <myx/base/config.hpp>
|
|
||||||
#else
|
|
||||||
#pragma once
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MYX_BASE_CONFIG_CPP_
|
|
@ -1,29 +0,0 @@
|
|||||||
#ifndef MYX_BASE_CONFIG_HPP_
|
|
||||||
#define MYX_BASE_CONFIG_HPP_
|
|
||||||
|
|
||||||
#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 )
|
|
||||||
#else
|
|
||||||
#define MYXLIB_API __declspec( dllimport )
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#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_
|
|
@ -1,192 +0,0 @@
|
|||||||
#ifndef MYX_BASE_ENDIAN_TYPES_HPP_
|
|
||||||
#define MYX_BASE_ENDIAN_TYPES_HPP_
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <myx/base/span.hpp>
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#ifdef QT_CORE_LIB
|
|
||||||
#include <QDebug>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Основа здесь: https://github.com/tatewake/endian-template/
|
|
||||||
|
|
||||||
namespace myx {
|
|
||||||
|
|
||||||
namespace base {
|
|
||||||
|
|
||||||
template< typename T >
|
|
||||||
class EndianTypesBase
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
#if defined ( _MSC_VER )
|
|
||||||
#pragma warning ( push )
|
|
||||||
#endif
|
|
||||||
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::reverse_copy( sb.begin(), sb.end(), sn.begin() );
|
|
||||||
return( n );
|
|
||||||
} // swapBytes
|
|
||||||
|
|
||||||
|
|
||||||
#if defined( _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
|
|
||||||
// NOLINTNEXTLINE
|
|
||||||
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 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 >
|
|
||||||
{
|
|
||||||
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
|
|
||||||
// NOLINTNEXTLINE
|
|
||||||
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< T > 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_
|
|
26
src/myx/core/CMakeLists.txt
Normal file
26
src/myx/core/CMakeLists.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Название основной цели и имя библиотеки в текущем каталоге
|
||||||
|
set(TRGT core)
|
||||||
|
|
||||||
|
# cmake-format: off
|
||||||
|
# Список файлов исходных текстов
|
||||||
|
set(TRGT_cpp)
|
||||||
|
|
||||||
|
# Список заголовочных файлов
|
||||||
|
set(TRGT_hpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/config.hpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/limits.hpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/current_system.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_library(${TRGT} INTERFACE)
|
||||||
|
target_sources(${TRGT} INTERFACE ${TRGT_cpp} ${TRGT_headers})
|
||||||
|
|
||||||
|
target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src)
|
||||||
|
|
||||||
|
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||||
|
install(FILES ${TRGT_headers} COMPONENT dev
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT})
|
17
src/myx/core/config.hpp
Normal file
17
src/myx/core/config.hpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef MYX_CORE_CONFIG_HPP_
|
||||||
|
#define MYX_CORE_CONFIG_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if defined( _WIN32 ) && defined( MYXLIB_SHARED_LIB )
|
||||||
|
#ifdef myxlib_EXPORTS
|
||||||
|
#define MYXLIB_API __declspec( dllexport )
|
||||||
|
#else
|
||||||
|
#define MYXLIB_API __declspec( dllimport )
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define MYXLIB_API
|
||||||
|
#endif
|
||||||
|
#define MYXLIB_INLINE
|
||||||
|
|
||||||
|
#endif // MYX_CORE_CONFIG_HPP_
|
109
src/myx/core/current_system.hpp
Normal file
109
src/myx/core/current_system.hpp
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#ifndef MYX_CORE_CURRENT_SYSTEM_HPP_
|
||||||
|
#define MYX_CORE_CURRENT_SYSTEM_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class CurrentSystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CurrentSystem( const CurrentSystem& ) = delete;
|
||||||
|
CurrentSystem& operator=( const CurrentSystem& ) = delete;
|
||||||
|
CurrentSystem( CurrentSystem&& ) = delete;
|
||||||
|
CurrentSystem& operator=( CurrentSystem&& ) = delete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief instance
|
||||||
|
* @return Уникальный экземпляр класса CurrentSystem
|
||||||
|
*/
|
||||||
|
static CurrentSystem& instance()
|
||||||
|
{
|
||||||
|
static CurrentSystem sCurrentSystem;
|
||||||
|
return( sCurrentSystem );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string os() const { return( m_os ); }
|
||||||
|
std::string distribution() const { return( m_distribution ); }
|
||||||
|
std::string variant() const { return( m_variant ); }
|
||||||
|
std::string version() const { return( m_version ); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CurrentSystem() :
|
||||||
|
m_os
|
||||||
|
(
|
||||||
|
#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __NT__ )
|
||||||
|
"windows"
|
||||||
|
#elif __linux__
|
||||||
|
"linux"
|
||||||
|
#else
|
||||||
|
#error "Unknown OS"
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
{
|
||||||
|
#if defined( __e2k__ )
|
||||||
|
m_distribution = "debian";
|
||||||
|
m_variant = "elbrus";
|
||||||
|
std::ifstream file( "/etc/mcst_version" );
|
||||||
|
if ( file.is_open() )
|
||||||
|
{
|
||||||
|
std::getline( file, m_version );
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
std::ifstream file( "/etc/os-release" );
|
||||||
|
if ( file.is_open() )
|
||||||
|
{
|
||||||
|
std::string line;
|
||||||
|
while ( std::getline( file, line ) )
|
||||||
|
{
|
||||||
|
std::size_t pos = line.find( "ID=" );
|
||||||
|
if ( pos == 0 )
|
||||||
|
{
|
||||||
|
m_distribution = line.replace( pos, sizeof( "ID=" ) - 1, "" );
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = line.find( "VARIANT_ID=" );
|
||||||
|
if ( pos != std::string::npos )
|
||||||
|
{
|
||||||
|
m_variant = line.replace( pos, sizeof( "VARIANT_ID=" ) - 1, "" );
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = line.find( "VERSION_ID=" );
|
||||||
|
if ( pos != std::string::npos )
|
||||||
|
{
|
||||||
|
m_version = line.replace( pos, sizeof( "VERSION_ID=" ) - 1, "" );
|
||||||
|
while ( ( pos = m_version.find( '"' ) ) != std::string::npos )
|
||||||
|
{
|
||||||
|
m_version.erase( pos, sizeof( '"' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
#endif // if defined( __e2k__ )
|
||||||
|
}
|
||||||
|
|
||||||
|
~CurrentSystem() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_os;
|
||||||
|
std::string m_distribution;
|
||||||
|
std::string m_variant;
|
||||||
|
std::string m_version;
|
||||||
|
}; // class CurrentSystem
|
||||||
|
|
||||||
|
// class CurrentSystem
|
||||||
|
|
||||||
|
} // namespace core
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
|
||||||
|
#endif // MYX_CORE_CURRENT_SYSTEM_HPP_
|
189
src/myx/core/endian_types.hpp
Normal file
189
src/myx/core/endian_types.hpp
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
#ifndef MYX_BASE_ENDIAN_TYPES_HPP_
|
||||||
|
#define MYX_BASE_ENDIAN_TYPES_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <myx/backports/cpp/span.hpp>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#ifdef QT_CORE_LIB
|
||||||
|
#include <QDebug>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Основа здесь: https://github.com/tatewake/endian-template/
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
class EndianTypesBase
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
#if defined( _MSC_VER )
|
||||||
|
#pragma warning ( push )
|
||||||
|
#endif
|
||||||
|
static T swapBytes( const T& b )
|
||||||
|
{
|
||||||
|
T n;
|
||||||
|
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
|
||||||
|
|
||||||
|
#if defined( _MSC_VER )
|
||||||
|
#pragma warning ( pop )
|
||||||
|
#endif
|
||||||
|
}; // class EndianTypesBase
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
class LittleEndianType : public EndianTypesBase< T >
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
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 ) ); //NOLINT
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
// NOLINTNEXTLINE
|
||||||
|
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 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 >
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
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 ); //NOLINT
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
// NOLINTNEXTLINE
|
||||||
|
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< T > &b ) { out << T( b ); return( out ); }
|
||||||
|
QString toQString() { return( QString::number( transform( m_data ) ) ); }
|
||||||
|
#endif
|
||||||
|
}; // class BigEndianType
|
||||||
|
|
||||||
|
} // namespace core
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
|
||||||
|
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::core::LittleEndianType< uint16_t >; //NOLINT
|
||||||
|
using leuint32 = myx::core::LittleEndianType< uint32_t >; //NOLINT
|
||||||
|
using leuint64 = myx::core::LittleEndianType< uint64_t >; //NOLINT
|
||||||
|
|
||||||
|
using lefloat = myx::core::LittleEndianType< float >; //NOLINT
|
||||||
|
using ledouble = myx::core::LittleEndianType< double >; //NOLINT
|
||||||
|
|
||||||
|
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::core::BigEndianType< uint16_t >; //NOLINT
|
||||||
|
using beuint32 = myx::core::BigEndianType< uint32_t >; //NOLINT
|
||||||
|
using beuint64 = myx::core::BigEndianType< uint64_t >; //NOLINT
|
||||||
|
|
||||||
|
using befloat = myx::core::BigEndianType< float >; //NOLINT
|
||||||
|
using bedouble = myx::core::BigEndianType< double >; //NOLINT
|
||||||
|
|
||||||
|
#endif // MYX_BASE_ENDIAN_TYPES_HPP_
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
#ifndef MYX_CORE_ENUM_BITWISE_OPERATIONS_HPP_
|
||||||
#define MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
#define MYX_CORE_ENUM_BITWISE_OPERATIONS_HPP_
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace myx {
|
namespace myx {
|
||||||
|
|
||||||
namespace base {
|
namespace core {
|
||||||
|
|
||||||
template< typename Enum >
|
template< typename Enum >
|
||||||
struct EnableBitMaskOperators
|
struct EnableBitMaskOperators
|
||||||
@ -17,7 +17,7 @@ struct EnableBitMaskOperators
|
|||||||
|
|
||||||
template< typename Enum >
|
template< typename Enum >
|
||||||
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type
|
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type
|
||||||
operator ~( Enum e )
|
operator~( Enum e )
|
||||||
{
|
{
|
||||||
using Underlying = typename std::underlying_type< Enum >::type;
|
using Underlying = typename std::underlying_type< Enum >::type;
|
||||||
return( static_cast< Enum >( ~static_cast< Underlying >( e ) ) );
|
return( static_cast< Enum >( ~static_cast< Underlying >( e ) ) );
|
||||||
@ -26,7 +26,7 @@ operator ~( Enum e )
|
|||||||
|
|
||||||
template< typename Enum >
|
template< typename Enum >
|
||||||
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type
|
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type
|
||||||
operator |( Enum lhs, Enum rhs )
|
operator|( Enum lhs, Enum rhs )
|
||||||
{
|
{
|
||||||
using Underlying = typename std::underlying_type< Enum >::type;
|
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 ) ) );
|
||||||
@ -35,7 +35,7 @@ operator |( Enum lhs, Enum rhs )
|
|||||||
|
|
||||||
template< typename Enum >
|
template< typename Enum >
|
||||||
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, typename std::add_lvalue_reference< Enum >::type >::type
|
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, typename std::add_lvalue_reference< Enum >::type >::type
|
||||||
operator |=( Enum& lhs, Enum rhs )
|
operator|=( Enum& lhs, Enum rhs )
|
||||||
{
|
{
|
||||||
using Underlying = typename std::underlying_type< Enum >::type;
|
using Underlying = typename std::underlying_type< Enum >::type;
|
||||||
lhs = static_cast< Enum >( static_cast< Underlying >( lhs ) | static_cast< Underlying >( rhs ) );
|
lhs = static_cast< Enum >( static_cast< Underlying >( lhs ) | static_cast< Underlying >( rhs ) );
|
||||||
@ -45,7 +45,7 @@ operator |=( Enum& lhs, Enum rhs )
|
|||||||
|
|
||||||
template< typename Enum >
|
template< typename Enum >
|
||||||
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type
|
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type
|
||||||
operator &( Enum lhs, Enum rhs )
|
operator&( Enum lhs, Enum rhs )
|
||||||
{
|
{
|
||||||
using Underlying = typename std::underlying_type< Enum >::type;
|
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 ) ) );
|
||||||
@ -54,14 +54,14 @@ operator &( Enum lhs, Enum rhs )
|
|||||||
|
|
||||||
template< typename Enum >
|
template< typename Enum >
|
||||||
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, typename std::add_lvalue_reference< Enum >::type >::type
|
typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, typename std::add_lvalue_reference< Enum >::type >::type
|
||||||
operator &=( Enum& lhs, Enum rhs )
|
operator&=( Enum& lhs, Enum rhs )
|
||||||
{
|
{
|
||||||
using Underlying = typename std::underlying_type< Enum >::type;
|
using Underlying = typename std::underlying_type< Enum >::type;
|
||||||
lhs = static_cast< Enum >( static_cast< Underlying >( lhs ) & static_cast< Underlying >( rhs ) );
|
lhs = static_cast< Enum >( static_cast< Underlying >( lhs ) & static_cast< Underlying >( rhs ) );
|
||||||
return( lhs );
|
return( lhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace base
|
} // namespace core
|
||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
@ -85,9 +85,9 @@ operator &=( Enum& lhs, Enum rhs )
|
|||||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||||
#define ENABLE_BITMASK_OPERATORS( x ) \
|
#define ENABLE_BITMASK_OPERATORS( x ) \
|
||||||
template<> \
|
template<> \
|
||||||
struct myx::base::EnableBitMaskOperators< x > \
|
struct myx::core::EnableBitMaskOperators< x > \
|
||||||
{ \
|
{ \
|
||||||
static const bool kEnable = true; \
|
static const bool kEnable = true; \
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
|
#endif // ifndef MYX_CORE_ENUM_BITWISE_OPERATIONS_HPP_
|
@ -1,5 +1,6 @@
|
|||||||
#ifndef MYX_BASE_LIMITS_HPP_
|
#ifndef MYX_CORE_LIMITS_HPP_
|
||||||
#define MYX_BASE_LIMITS_HPP_
|
#define MYX_CORE_LIMITS_HPP_
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@ -7,7 +8,7 @@
|
|||||||
|
|
||||||
namespace myx {
|
namespace myx {
|
||||||
|
|
||||||
namespace base {
|
namespace core {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Константа, представляющая значение, не являющееся числом, для типа float
|
* @brief Константа, представляющая значение, не являющееся числом, для типа float
|
||||||
@ -24,8 +25,8 @@ constexpr double kDoubleNAN { std::numeric_limits< double >::quiet_NaN() };
|
|||||||
*/
|
*/
|
||||||
constexpr double kLongDoubleNAN { std::numeric_limits< long double >::quiet_NaN() };
|
constexpr double kLongDoubleNAN { std::numeric_limits< long double >::quiet_NaN() };
|
||||||
|
|
||||||
} // namespace base
|
} // namespace core
|
||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
#endif // MYX_BASE_LIMITS_HPP_
|
#endif // MYX_CORE_LIMITS_HPP_
|
@ -11,47 +11,15 @@ set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.hpp)
|
|||||||
set(TRGT_headers ${TRGT_hpp})
|
set(TRGT_headers ${TRGT_hpp})
|
||||||
# cmake-format: on
|
# cmake-format: on
|
||||||
|
|
||||||
add_library(${TRGT}-header-only INTERFACE)
|
#add_library(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||||
target_include_directories(
|
add_library(${TRGT} OBJECT ${TRGT_cpp} ${TRGT_headers})
|
||||||
${TRGT}-header-only SYSTEM INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME myx-${TRGT})
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
myx_cmake_common_target_properties(${TRGT})
|
||||||
|
myx_cmake_add_static_library(${TRGT})
|
||||||
|
myx_cmake_add_shared_library(${TRGT})
|
||||||
|
|
||||||
if(MYXLIB_BUILD_LIBRARIES)
|
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||||
|
|
||||||
add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers})
|
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||||
common_target_properties(${TRGT})
|
install(FILES ${TRGT_headers} COMPONENT dev
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT})
|
||||||
# Создание цели для проверки утилитой 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_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})
|
|
||||||
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})
|
|
||||||
|
|
||||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
|
||||||
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
|
|
||||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
#ifndef MYX_BASE_PATHS_CPP_
|
#ifndef MYX_CORE_PATHS_CPP_
|
||||||
#define MYX_BASE_PATHS_CPP_
|
#define MYX_CORE_PATHS_CPP_
|
||||||
|
|
||||||
#ifndef MYXLIB_HEADER_ONLY
|
#include <myx/core/config.hpp>
|
||||||
#include <myx/filesystem/paths.hpp>
|
#include <myx/filesystem/paths.hpp>
|
||||||
#else
|
|
||||||
#pragma once
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
|
||||||
|
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
|
|
||||||
@ -18,155 +13,9 @@ namespace myx {
|
|||||||
|
|
||||||
namespace filesystem {
|
namespace filesystem {
|
||||||
|
|
||||||
MYXLIB_INLINE Paths::Paths() = default;
|
MYXLIB_INLINE Paths::Paths() :
|
||||||
|
m_binDirRegex ( QStringLiteral( "/s*bin$" ) ),
|
||||||
|
m_unityBinDirRegex( QStringLiteral( "/bin/unity$" ) )
|
||||||
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() )
|
|
||||||
{
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType()
|
|
||||||
{
|
|
||||||
QRegExp binUnityRegexp( "/s*bin/unity$" );
|
|
||||||
auto binaryDir = m_executableDirectory;
|
|
||||||
|
|
||||||
if ( binUnityRegexp.indexIn( binaryDir ) >= 0 )
|
|
||||||
{
|
|
||||||
binaryDir.remove( binUnityRegexp );
|
|
||||||
setupSystemDirectories( binaryDir,
|
|
||||||
binaryDir + "/etc",
|
|
||||||
binaryDir + "/files/data",
|
|
||||||
binaryDir + "/files/lib",
|
|
||||||
binaryDir + "/files/log" );
|
|
||||||
|
|
||||||
return ( HierarchyType::kDevelopment );
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
m_systemLogDirectory = m_executableDirectory;
|
|
||||||
|
|
||||||
return ( HierarchyType::kFlat );
|
|
||||||
}
|
|
||||||
|
|
||||||
QRegExp optRegexp( "^/opt(/|/.+/)" + m_projectName + "/" );
|
|
||||||
if ( optRegexp.indexIn( binaryDir ) >= 0 )
|
|
||||||
{
|
|
||||||
binaryDir.remove( binRegexp );
|
|
||||||
setupSystemDirectories( binaryDir,
|
|
||||||
binaryDir + "/etc",
|
|
||||||
binaryDir + "/files/data",
|
|
||||||
binaryDir + "/files/lib",
|
|
||||||
binaryDir + "/files/log" );
|
|
||||||
|
|
||||||
return ( HierarchyType::kOpt );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( binaryDir.startsWith( QStringLiteral( "/usr/local" ) ) )
|
|
||||||
{
|
|
||||||
setupSystemDirectories( "/usr/local",
|
|
||||||
"/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" ) ) )
|
|
||||||
{
|
|
||||||
setupSystemDirectories( "/usr",
|
|
||||||
"/etc/" + m_projectName,
|
|
||||||
"/usr/share/" + m_projectName,
|
|
||||||
"/var/lib/" + m_projectName,
|
|
||||||
"/var/log/" + m_projectName );
|
|
||||||
|
|
||||||
return ( HierarchyType::kUsr );
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
m_systemLogDirectory = m_userLogDirectory;
|
|
||||||
|
|
||||||
return( HierarchyType::kHome );
|
|
||||||
}
|
|
||||||
|
|
||||||
binaryDir.remove( binRegexp );
|
|
||||||
setupSystemDirectories( binaryDir,
|
|
||||||
binaryDir + "/etc",
|
|
||||||
binaryDir + "/files/data",
|
|
||||||
binaryDir + "/files/lib",
|
|
||||||
binaryDir + "/files/log" );
|
|
||||||
|
|
||||||
return ( HierarchyType::kDevelopment );
|
|
||||||
} // Paths::getHierarchyType
|
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& configFileExtension )
|
|
||||||
{
|
{
|
||||||
QFileInfo procSelfExe( QStringLiteral( "/proc/self/exe" ) );
|
QFileInfo procSelfExe( QStringLiteral( "/proc/self/exe" ) );
|
||||||
QFileInfo currentExecutable = procSelfExe.canonicalFilePath();
|
QFileInfo currentExecutable = procSelfExe.canonicalFilePath();
|
||||||
@ -174,77 +23,324 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config
|
|||||||
m_executableFilePath = currentExecutable.absoluteFilePath();
|
m_executableFilePath = currentExecutable.absoluteFilePath();
|
||||||
m_executableDirectory = currentExecutable.absolutePath();
|
m_executableDirectory = currentExecutable.absolutePath();
|
||||||
|
|
||||||
m_projectName = projectDir.isEmpty() ? m_executableName
|
// Инициализация значениями по умолчанию
|
||||||
: projectDir;
|
init();
|
||||||
m_configFileExtension = configFileExtension.isEmpty() ? QStringLiteral( "conf" )
|
}
|
||||||
: configFileExtension;
|
|
||||||
m_configFileName = m_projectName + "." + m_configFileExtension;
|
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE bool Paths::init( bool autodetect )
|
||||||
|
{
|
||||||
|
m_autodetect = autodetect;
|
||||||
m_homeDirectory = QDir::homePath();
|
m_homeDirectory = QDir::homePath();
|
||||||
m_tempDirectory = QDir::tempPath();
|
m_tempDirectory = QDir::tempPath();
|
||||||
|
|
||||||
auto configHome = QString::fromLocal8Bit( qgetenv( "XDG_CONFIG_HOME" ) );
|
m_configDirectory = QString::fromLocal8Bit( qgetenv( "XDG_CONFIG_HOME" ) );
|
||||||
if ( configHome.isEmpty() )
|
if ( m_configDirectory.isEmpty() )
|
||||||
{
|
{
|
||||||
configHome = m_homeDirectory + "/.config";
|
m_configDirectory = m_homeDirectory + "/.config";
|
||||||
}
|
}
|
||||||
m_userConfigDirectory = configHome + "/" + m_projectName;
|
|
||||||
|
|
||||||
auto dataHome = QString::fromLocal8Bit( qgetenv( "XDG_DATA_HOME" ) );
|
m_dataDirectory = QString::fromLocal8Bit( qgetenv( "XDG_DATA_HOME" ) );
|
||||||
if ( dataHome.isEmpty() )
|
if ( m_dataDirectory.isEmpty() )
|
||||||
{
|
{
|
||||||
dataHome = m_homeDirectory + "/.local/share";
|
m_dataDirectory = m_homeDirectory + "/.local/share";
|
||||||
}
|
}
|
||||||
dataHome += "/" + m_projectName;
|
|
||||||
m_userConstDataDirectory = dataHome + "/data";
|
|
||||||
m_userVarDataDirectory = dataHome + "/lib";
|
|
||||||
m_userLogDirectory = dataHome + "/log";
|
|
||||||
|
|
||||||
|
if ( m_projectName.isEmpty() )
|
||||||
|
{
|
||||||
|
m_projectName = m_executableName;
|
||||||
|
}
|
||||||
m_hierarchyType = getHierarchyType();
|
m_hierarchyType = getHierarchyType();
|
||||||
|
calculatePaths( m_hierarchyType );
|
||||||
m_configFilePath = m_systemConfigDirectory + "/" + m_configFileName;
|
|
||||||
|
|
||||||
return( true );
|
return( true );
|
||||||
} // Paths::updatePaths
|
} // Paths::init
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE bool Paths::makeDefaultDirectories()
|
MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& projectDir,
|
||||||
|
const QString& etcDir,
|
||||||
|
const QString& constDataDir,
|
||||||
|
const QString& varDataDir,
|
||||||
|
const QString& logDir )
|
||||||
|
{
|
||||||
|
QFileInfo prefixDirInfo { projectDir };
|
||||||
|
if ( prefixDirInfo.isDir() && prefixDirInfo.isReadable() )
|
||||||
|
{
|
||||||
|
m_projectDirectory = projectDir;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_projectDirectory = QStringLiteral( "." );
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileInfo etcDirInfo { etcDir };
|
||||||
|
if ( etcDirInfo.isDir() && etcDirInfo.isReadable() )
|
||||||
|
{
|
||||||
|
m_systemConfigDirectory = etcDir;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_systemConfigDirectory = m_userConfigDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileInfo constDataDirInfo { constDataDir };
|
||||||
|
if ( constDataDirInfo.isDir() && constDataDirInfo.isReadable() )
|
||||||
|
{
|
||||||
|
m_systemConstDataDirectory = constDataDir;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_systemConstDataDirectory = m_userConstDataDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileInfo varDataDirInfo { varDataDir };
|
||||||
|
if ( varDataDirInfo.isDir() && varDataDirInfo.isWritable() )
|
||||||
|
{
|
||||||
|
m_systemVarDataDirectory = varDataDir;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_systemVarDataDirectory = m_userVarDataDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileInfo logDirInfo { logDir };
|
||||||
|
if ( logDirInfo.isDir() && logDirInfo.isWritable() )
|
||||||
|
{
|
||||||
|
m_systemLogDirectory = logDir;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_systemLogDirectory = m_userLogDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_organizationName.isEmpty() && !m_themeName.isEmpty() )
|
||||||
|
{
|
||||||
|
m_systemThemeDirectory = "/opt/" + m_organizationName + "-" + m_themeName;
|
||||||
|
}
|
||||||
|
} // Paths::setupSystemDirectories
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE void Paths::setupUserDirectories()
|
||||||
|
{
|
||||||
|
QString prefix;
|
||||||
|
if ( !m_organizationName.isEmpty() )
|
||||||
|
{
|
||||||
|
prefix = "/" + m_organizationName;
|
||||||
|
if ( !m_themeName.isEmpty() )
|
||||||
|
{
|
||||||
|
prefix.append( "-" + m_themeName );
|
||||||
|
m_userThemeDirectory = m_dataDirectory + prefix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prefix.append( "/" + m_projectName );
|
||||||
|
m_userConfigDirectory = m_configDirectory + prefix;
|
||||||
|
m_userConstDataDirectory = m_dataDirectory + prefix + "/share";
|
||||||
|
m_userVarDataDirectory = m_dataDirectory + prefix + "/var";
|
||||||
|
m_userLogDirectory = m_dataDirectory + prefix + "/log";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType()
|
||||||
|
{
|
||||||
|
if ( m_unityBinDirRegex.match( m_executableDirectory ).hasMatch() )
|
||||||
|
{
|
||||||
|
return ( HierarchyType::kDevelopment );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_binDirRegex.match( m_executableDirectory ).hasMatch() )
|
||||||
|
{
|
||||||
|
return ( HierarchyType::kFlat );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_executableDirectory.startsWith( QStringLiteral( "/opt/" ) ) )
|
||||||
|
{
|
||||||
|
return ( HierarchyType::kOpt );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_executableDirectory.startsWith( QStringLiteral( "/usr/local/bin/" ) ) )
|
||||||
|
{
|
||||||
|
return ( HierarchyType::kUsrLocal );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_executableDirectory.startsWith( QStringLiteral( "/usr/local/" ) ) )
|
||||||
|
{
|
||||||
|
return ( HierarchyType::kUsrLocalOrg );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_executableDirectory.startsWith( QStringLiteral( "/usr/bin/" ) ) )
|
||||||
|
{
|
||||||
|
return ( HierarchyType::kUsr );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_executableDirectory.startsWith( m_homeDirectory + "/.local/bin/" ) ||
|
||||||
|
m_executableDirectory.startsWith( m_homeDirectory + "/bin/" ) )
|
||||||
|
{
|
||||||
|
return( HierarchyType::kHome );
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( HierarchyType::kDevelopment );
|
||||||
|
} // Paths::getHierarchyType
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
|
||||||
|
{
|
||||||
|
auto directory = m_executableDirectory;
|
||||||
|
setupUserDirectories();
|
||||||
|
|
||||||
|
switch ( hType )
|
||||||
|
{
|
||||||
|
case HierarchyType::kFlat:
|
||||||
|
setupSystemDirectories( directory, directory, directory, directory, directory );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HierarchyType::kOpt:
|
||||||
|
processOptHierarhy();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HierarchyType::kUsr:
|
||||||
|
setupSystemDirectories( QStringLiteral( "/usr" ),
|
||||||
|
"/etc/" + m_projectName,
|
||||||
|
"/usr/share/" + m_projectName,
|
||||||
|
"/var/lib/" + m_projectName,
|
||||||
|
"/var/log/" + m_projectName );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HierarchyType::kUsrLocal:
|
||||||
|
setupSystemDirectories( QStringLiteral( "/usr/local" ),
|
||||||
|
"/usr/local/etc/" + m_projectName,
|
||||||
|
"/usr/local/share/" + m_projectName,
|
||||||
|
"/var/lib/" + m_projectName,
|
||||||
|
"/var/log/" + m_projectName );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HierarchyType::kUsrLocalOrg:
|
||||||
|
directory.remove( m_binDirRegex );
|
||||||
|
setupSystemDirectories( directory,
|
||||||
|
directory + "/etc",
|
||||||
|
directory + "/share",
|
||||||
|
directory + "/var",
|
||||||
|
directory + "/log" );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HierarchyType::kHome:
|
||||||
|
setupSystemDirectories( m_homeDirectory,
|
||||||
|
m_userConfigDirectory,
|
||||||
|
m_userConstDataDirectory,
|
||||||
|
m_userVarDataDirectory,
|
||||||
|
m_userLogDirectory );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HierarchyType::kDevelopment:
|
||||||
|
directory.remove( m_unityBinDirRegex );
|
||||||
|
directory.remove( m_binDirRegex );
|
||||||
|
setupSystemDirectories( directory,
|
||||||
|
directory + "/etc",
|
||||||
|
directory + "/share",
|
||||||
|
directory + "/var",
|
||||||
|
directory + "/log" );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HierarchyType::kUndefined:
|
||||||
|
;
|
||||||
|
} // switch
|
||||||
|
setupUserDirectories();
|
||||||
|
} // Paths::calculatePaths
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE void Paths::processOptHierarhy()
|
||||||
|
{
|
||||||
|
auto directory = m_executableDirectory;
|
||||||
|
|
||||||
|
if ( m_autodetect )
|
||||||
|
{
|
||||||
|
QRegularExpression regex( QStringLiteral( "^/opt/(.+?)/(.+?)/" ) );
|
||||||
|
QRegularExpressionMatch match = regex.match( m_executableDirectory );
|
||||||
|
|
||||||
|
if ( match.hasMatch() )
|
||||||
|
{
|
||||||
|
m_organizationName = match.captured( 1 );
|
||||||
|
m_projectName = match.captured( 2 );
|
||||||
|
|
||||||
|
QRegularExpression themeRegex( QStringLiteral( "(.+?)-(.+)" ) );
|
||||||
|
QRegularExpressionMatch themeMatch = themeRegex.match( m_organizationName );
|
||||||
|
if ( themeMatch.hasMatch() )
|
||||||
|
{
|
||||||
|
m_themeName = themeMatch.captured( 2 );
|
||||||
|
m_organizationName = themeMatch.captured( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
QRegularExpression versionRegex( QStringLiteral( "(.+?)\\.(.+)" ) );
|
||||||
|
QRegularExpressionMatch versionMatch = versionRegex.match( m_projectName );
|
||||||
|
if ( versionMatch.hasMatch() )
|
||||||
|
{
|
||||||
|
m_projectName = versionMatch.captured( 1 );
|
||||||
|
m_version = versionMatch.captured( 2 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
directory.remove( m_binDirRegex );
|
||||||
|
setupSystemDirectories( directory,
|
||||||
|
directory + "/etc",
|
||||||
|
directory + "/share",
|
||||||
|
directory + "/var",
|
||||||
|
directory + "/log" );
|
||||||
|
setupUserDirectories();
|
||||||
|
} // Paths::processOptHierarhy
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE bool Paths::makeDefaultSystemDirectories()
|
||||||
{
|
{
|
||||||
bool status = true;
|
bool status = true;
|
||||||
QDir dir;
|
QDir dir;
|
||||||
|
|
||||||
if ( dir.mkpath( m_userConfigDirectory ) ) { status = false; }
|
if ( !dir.mkpath( m_systemConstDataDirectory ) ) { status = false; }
|
||||||
if ( dir.mkpath( m_userVarDataDirectory ) ) { status = false; }
|
if ( !dir.mkpath( m_systemLogDirectory ) ) { status = false; }
|
||||||
if ( dir.mkpath( m_userConstDataDirectory ) ) { status = false; }
|
if ( !dir.mkpath( m_systemConfigDirectory ) ) { status = false; }
|
||||||
if ( dir.mkpath( m_userLogDirectory ) ) { status = false; }
|
if ( !dir.mkpath( m_systemVarDataDirectory ) ) { 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 );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE QString Paths::findConfigFile( const QString& defaultConfigFile )
|
MYXLIB_INLINE bool Paths::makeDefaultUserDirectories()
|
||||||
{
|
{
|
||||||
if ( !defaultConfigFile.isEmpty() && QFileInfo( defaultConfigFile ).isReadable() )
|
bool status = true;
|
||||||
|
QDir dir;
|
||||||
|
|
||||||
|
if ( !dir.mkpath( m_userConstDataDirectory ) ) { status = false; }
|
||||||
|
if ( !dir.mkpath( m_userLogDirectory ) ) { status = false; }
|
||||||
|
if ( !dir.mkpath( m_userConfigDirectory ) ) { status = false; }
|
||||||
|
if ( !dir.mkpath( m_userVarDataDirectory ) ) { status = false; }
|
||||||
|
|
||||||
|
return( status );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE bool Paths::makeDefaultDirectories()
|
||||||
|
{
|
||||||
|
return ( makeDefaultSystemDirectories() && makeDefaultUserDirectories() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE QString Paths::findConfigFile( const QString& configFileName )
|
||||||
|
{
|
||||||
|
if ( !configFileName.isEmpty() && QFileInfo( configFileName ).isReadable() )
|
||||||
{
|
{
|
||||||
m_configFilePath = defaultConfigFile;
|
return( configFileName );
|
||||||
return( defaultConfigFile );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fileName = QString::fromLocal8Bit( qgetenv( QCoreApplication::applicationName()
|
auto fileName = QString::fromLocal8Bit( qgetenv( QCoreApplication::applicationName()
|
||||||
.toUpper().toUtf8() + "_CONFIG" ) );
|
.toUpper().toUtf8() + "_CONFIG" ) );
|
||||||
if ( QFileInfo( fileName ).isReadable() )
|
if ( QFileInfo( fileName ).isReadable() )
|
||||||
{
|
{
|
||||||
m_configFilePath = fileName;
|
|
||||||
return( fileName );
|
return( fileName );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( QFileInfo( m_configFilePath ).isReadable() )
|
QString autoConfigFile = m_systemConfigDirectory + "/" + m_executableName;
|
||||||
|
if ( QFileInfo( autoConfigFile ).isReadable() )
|
||||||
{
|
{
|
||||||
return( m_configFilePath );
|
return( configFileName );
|
||||||
}
|
}
|
||||||
|
|
||||||
return( QString() );
|
return( QString() );
|
||||||
@ -263,21 +359,15 @@ MYXLIB_INLINE const QString& Paths::systemConfigDirectory() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QString& Paths::configFilePath() const
|
MYXLIB_INLINE const QString& Paths::userThemeDirectory() const
|
||||||
{
|
{
|
||||||
return( m_configFilePath );
|
return( m_userThemeDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QString& Paths::configFileName() const
|
MYXLIB_INLINE const QString& Paths::systemThemeDirectory() const
|
||||||
{
|
{
|
||||||
return( m_configFileName );
|
return( m_systemThemeDirectory );
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QString& Paths::configFileExtension() const
|
|
||||||
{
|
|
||||||
return( m_configFileExtension );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -335,6 +425,36 @@ MYXLIB_INLINE const QString& Paths::projectName() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE void Paths::setProjectName( const QString& name )
|
||||||
|
{
|
||||||
|
m_projectName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE const QString& Paths::organizationName() const
|
||||||
|
{
|
||||||
|
return( m_organizationName );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE void Paths::setOrganizationName( const QString& name )
|
||||||
|
{
|
||||||
|
m_organizationName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE const QString& Paths::themeName() const
|
||||||
|
{
|
||||||
|
return( m_themeName );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MYXLIB_INLINE void Paths::setThemeName( const QString& name )
|
||||||
|
{
|
||||||
|
m_themeName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QString& Paths::executableName() const
|
MYXLIB_INLINE const QString& Paths::executableName() const
|
||||||
{
|
{
|
||||||
return( m_executableName );
|
return( m_executableName );
|
||||||
@ -353,13 +473,13 @@ MYXLIB_INLINE const QString& Paths::executableDirectory() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYXLIB_INLINE const QString& Paths::prefixDirectory() const
|
MYXLIB_INLINE const QString& Paths::projectDirectory() const
|
||||||
{
|
{
|
||||||
return( m_prefixDirectory );
|
return( m_projectDirectory );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace filesystem
|
} // namespace filesystem
|
||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
#endif // MYX_BASE_PATHS_CPP_
|
#endif // MYX_CORE_PATHS_CPP_
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/**
|
/** @file paths.hpp
|
||||||
* @file paths.hpp
|
|
||||||
* @brief Стандартные пути к каталогам и файлам
|
* @brief Стандартные пути к каталогам и файлам
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -8,96 +7,44 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace myx {
|
namespace myx {
|
||||||
|
|
||||||
namespace filesystem {
|
namespace filesystem {
|
||||||
|
|
||||||
/// @brief Класс, предоставляющий методы для получения стандартных путей к каталогам и файлам
|
//* @brief Класс, предоставляющий методы для получения стандартных путей к каталогам и файлам
|
||||||
class Paths
|
class Paths
|
||||||
{
|
{
|
||||||
enum class HierarchyType : intptr_t
|
enum class HierarchyType : intptr_t
|
||||||
{
|
{
|
||||||
/// @brief Тип расположения файлов не определён
|
//* @brief Тип расположения файлов не определён
|
||||||
kUndefined = 0x00,
|
kUndefined = 0x00,
|
||||||
/// @brief Не определено ни одно из типовых размещений файлов
|
/** @brief Не определено ни одно из типовых размещений файлов
|
||||||
/// @details Если исполняемый файл не находится в каталоге bin или не найдены
|
* @details Если исполняемый файл не находится в каталоге bin или не найдены
|
||||||
/// необходимые сопутствующие каталоги, то предполается,
|
* необходимые сопутствующие каталоги, то предполается,
|
||||||
/// что все файлы находятся в одном каталоге с исполняемым файлом
|
* что все файлы находятся в одном каталоге с исполняемым файлом
|
||||||
|
*/
|
||||||
kFlat = 0x01,
|
kFlat = 0x01,
|
||||||
/// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /opt
|
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /opt
|
||||||
kOpt = 0x02,
|
kOpt = 0x02,
|
||||||
/// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr
|
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии / usr
|
||||||
kUsr = 0x04,
|
kUsr = 0x03,
|
||||||
/// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local
|
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local
|
||||||
kUsrLocal = 0x08,
|
kUsrLocal = 0x04,
|
||||||
/// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /home
|
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local/ORG (используется для работ в проекте Сирена)
|
||||||
kHome = 0x10,
|
kUsrLocalOrg = 0x05,
|
||||||
/// @brief Исполняемый файл и сопутствующие каталоги находятся в каталоге программного проекта
|
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /home
|
||||||
kDevelopment = 0x20
|
kHome = 0x06,
|
||||||
|
//* @brief Исполняемый файл и сопутствующие каталоги находятся в каталоге программного проекта
|
||||||
|
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:
|
public:
|
||||||
Paths( const Paths& ) = delete;
|
Paths( const Paths& ) = delete;
|
||||||
Paths& operator=( const Paths& ) = delete;
|
Paths& operator=( const Paths& ) = delete;
|
||||||
@ -114,124 +61,172 @@ public:
|
|||||||
return( sPaths );
|
return( sPaths );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//* @brief Обновление путей с учётом расположения исполняемого файла
|
||||||
|
bool init( bool autodetect = true );
|
||||||
|
|
||||||
/**
|
//* @brief Создание стандартных системных каталогов
|
||||||
* @brief Обновление путей с учётом расположения исполняемого файла
|
bool makeDefaultSystemDirectories();
|
||||||
*/
|
|
||||||
bool init( const QString& projectDir, const QString& configFileExtension = QStringLiteral("conf") );
|
|
||||||
|
|
||||||
/**
|
//* @brief Создание стандартных пользовательских каталогов
|
||||||
* @brief Создание стандартных каталогов
|
bool makeDefaultUserDirectories();
|
||||||
*/
|
|
||||||
|
//* @brief Создание стандартных каталогов
|
||||||
bool makeDefaultDirectories();
|
bool makeDefaultDirectories();
|
||||||
|
|
||||||
/**
|
/** @brief Поиск существующего файла настойки.
|
||||||
* @brief Поиск существующего файла настойки.
|
|
||||||
* Поиск выполняется до тех пор пока не будет найден файл в следующем порядке:
|
* Поиск выполняется до тех пор пока не будет найден файл в следующем порядке:
|
||||||
* 1. Имя файла, указанное в качестве параметра функции
|
* 1. Имя файла, указанное в качестве параметра функции
|
||||||
* 2. Имя файла, заданное переменной окружения вида PROJECT_NAME_CONFIG
|
* 2. Имя файла, заданное переменной окружения вида EXECUTABLE_NAME_CONFIG
|
||||||
* 3. Имя файла, полученное из внутренней переменной класса
|
* 3. Имя файла, полученное из имени каталога системных настроек и имени исполняемого файла
|
||||||
* Если файл настройки не будет найден, то будет возвращена пустая строка
|
* Если файл настройки не будет найден, то будет возвращена пустая строка
|
||||||
*/
|
*/
|
||||||
QString findConfigFile( const QString& defaultConfigFile = QLatin1String("") );
|
QString findConfigFile( const QString& configFileName = QLatin1String( "" ) );
|
||||||
|
|
||||||
/**
|
//* @brief Имя исполняемого файла
|
||||||
* @brief Полный путь к базовому каталогу
|
|
||||||
*/
|
|
||||||
const QString& prefixDirectory() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Имя исполняемого файла
|
|
||||||
*/
|
|
||||||
const QString& executableName() const;
|
const QString& executableName() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к исполняемому файлу
|
||||||
* @brief Полный путь к исполняемому файлу
|
|
||||||
*/
|
|
||||||
const QString& executableFilePath() const;
|
const QString& executableFilePath() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к каталогу с исполняемым файлом
|
||||||
* @brief Полный путь к каталогу с исполняемым файлом
|
|
||||||
*/
|
|
||||||
const QString& executableDirectory() const;
|
const QString& executableDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Путь к общему пользовательскому каталогу для файлов работы (темы)
|
||||||
* @brief Имя файла настройки
|
const QString& userThemeDirectory() const;
|
||||||
*/
|
|
||||||
const QString& configFileName() const;
|
|
||||||
|
|
||||||
/**
|
//* @brief Путь к общему системному каталогу для файлов работы (темы)
|
||||||
* @brief Расширение у файла настройки
|
const QString& systemThemeDirectory() const;
|
||||||
*/
|
|
||||||
const QString& configFileExtension() const;
|
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к пользовательскому каталогу с файлами настройки
|
||||||
* @brief Полный путь к файлу настройки
|
|
||||||
*/
|
|
||||||
const QString& configFilePath() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Полный путь к пользовательскому каталогу с файлами настройки
|
|
||||||
*/
|
|
||||||
const QString& userConfigDirectory() const;
|
const QString& userConfigDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к системному каталогу с файлами настройки
|
||||||
* @brief Полный путь к системному каталогу с файлами настройки
|
|
||||||
*/
|
|
||||||
const QString& systemConfigDirectory() const;
|
const QString& systemConfigDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к пользовательскому каталогу с изменяемыми файлами
|
||||||
* @brief Полный путь к пользовательскому каталогу с изменяемыми файлами
|
|
||||||
*/
|
|
||||||
const QString& userVarDataDirectory() const;
|
const QString& userVarDataDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к системному каталогу с изменяемыми файлами
|
||||||
* @brief Полный путь к системному каталогу с изменяемыми файлами
|
|
||||||
*/
|
|
||||||
const QString& systemVarDataDirectory() const;
|
const QString& systemVarDataDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к пользовательскому каталогу с неизменяемыми файлами
|
||||||
* @brief Полный путь к пользовательскому каталогу с неизменяемыми файлами
|
|
||||||
*/
|
|
||||||
const QString& userConstDataDirectory() const;
|
const QString& userConstDataDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к системному каталогу с неизменяемыми файлами
|
||||||
* @brief Полный путь к системному каталогу с неизменяемыми файлами
|
|
||||||
*/
|
|
||||||
const QString& systemConstDataDirectory() const;
|
const QString& systemConstDataDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к пользовательскому каталогу с журналами работы
|
||||||
* @brief Полный путь к пользовательскому каталогу с журналами работы
|
|
||||||
*/
|
|
||||||
const QString& userLogDirectory() const;
|
const QString& userLogDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к системному каталогу с журналами работы
|
||||||
* @brief Полный путь к системному каталогу с журналами работы
|
|
||||||
*/
|
|
||||||
const QString& systemLogDirectory() const;
|
const QString& systemLogDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к каталогу с временными файлами
|
||||||
* @brief Полный путь к каталогу с временными файлами
|
|
||||||
*/
|
|
||||||
const QString& tempDirectory() const;
|
const QString& tempDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Полный путь к домашнему каталогу текущего пользователя
|
||||||
* @brief Полный путь к домашнему каталогу текущего пользователя
|
|
||||||
*/
|
|
||||||
const QString& homeDirectory() const;
|
const QString& homeDirectory() const;
|
||||||
|
|
||||||
/**
|
//* @brief Имя каталога для проекта
|
||||||
* @brief Имя подкаталога для проекта
|
const QString& projectDirectory() const;
|
||||||
*/
|
|
||||||
|
//* @brief Название организации
|
||||||
|
const QString& organizationName() const;
|
||||||
|
void setOrganizationName( const QString& name );
|
||||||
|
|
||||||
|
//* @brief Название работы (темы)
|
||||||
|
const QString& themeName() const;
|
||||||
|
void setThemeName( const QString& name );
|
||||||
|
|
||||||
|
//* @brief Название программного проекта
|
||||||
const QString& projectName() const;
|
const QString& projectName() const;
|
||||||
|
void setProjectName( const QString& name );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Paths();
|
||||||
|
~Paths() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//* @brief Тип расположения файлов по каталогам
|
||||||
|
HierarchyType m_hierarchyType { HierarchyType::kFlat };
|
||||||
|
|
||||||
|
/** @brief Автоматически определять значения organizationName, themeName и projectName
|
||||||
|
* @details Если true, то пытаться автоматически определять значения переменных
|
||||||
|
* на основании полного пути к исполняемому файлу.
|
||||||
|
* Иначе использовать значения переменных, указанные пользователем.
|
||||||
|
*/
|
||||||
|
bool m_autodetect { true };
|
||||||
|
|
||||||
|
//* @brief Название организации
|
||||||
|
QString m_organizationName;
|
||||||
|
|
||||||
|
//* @brief Название работы (темы)
|
||||||
|
QString m_themeName;
|
||||||
|
|
||||||
|
//* @brief Номер версии установленного пакета
|
||||||
|
QString m_version;
|
||||||
|
|
||||||
|
//* @brief Имя проекта, которое используется при формировании имён файлов и каталогов
|
||||||
|
QString m_projectName;
|
||||||
|
|
||||||
|
QString m_executableName;
|
||||||
|
QString m_executableFilePath;
|
||||||
|
QString m_executableDirectory;
|
||||||
|
|
||||||
|
//* @brief Общий каталог для файлов проекта
|
||||||
|
QString m_projectDirectory;
|
||||||
|
|
||||||
|
//* @brief Путь к каталогу с временными файлами
|
||||||
|
QString m_tempDirectory;
|
||||||
|
//* @brief Путь к домашнему каталогу текущего пользователя
|
||||||
|
QString m_homeDirectory;
|
||||||
|
//* @brief Путь к общему пользовательскому каталогу настроек
|
||||||
|
QString m_configDirectory;
|
||||||
|
//* @brief Путь к общему пользовательскому каталогу данных
|
||||||
|
QString m_dataDirectory;
|
||||||
|
|
||||||
|
//* @brief Путь к общему пользовательскому каталогу для файлов работы (темы)
|
||||||
|
QString m_userThemeDirectory;
|
||||||
|
//* @brief Путь к общему системному каталогу для файлов работы (темы)
|
||||||
|
QString m_systemThemeDirectory;
|
||||||
|
|
||||||
|
//* @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;
|
||||||
|
|
||||||
|
QRegularExpression m_binDirRegex;
|
||||||
|
QRegularExpression m_unityBinDirRegex;
|
||||||
|
|
||||||
|
void setupSystemDirectories( const QString& projectDir,
|
||||||
|
const QString& etcDir,
|
||||||
|
const QString& constDataDir,
|
||||||
|
const QString& varDataDir,
|
||||||
|
const QString& logDir );
|
||||||
|
void setupUserDirectories();
|
||||||
|
|
||||||
|
HierarchyType getHierarchyType();
|
||||||
|
void calculatePaths( HierarchyType hType );
|
||||||
|
void processOptHierarhy();
|
||||||
}; // class Paths
|
}; // class Paths
|
||||||
|
|
||||||
} // namespace filesystem
|
} // namespace filesystem
|
||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
#ifdef MYXLIB_HEADER_ONLY
|
|
||||||
#include "paths.cpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MYX_FILESYSTEM_PATHS_HPP_
|
#endif // MYX_FILESYSTEM_PATHS_HPP_
|
||||||
|
@ -4,56 +4,42 @@ set(TRGT qt)
|
|||||||
# cmake-format: off
|
# cmake-format: off
|
||||||
# Список файлов исходных текстов
|
# Список файлов исходных текстов
|
||||||
set(TRGT_cpp
|
set(TRGT_cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp)
|
${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_default.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_handler.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_syslog.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
|
set(TRGT_hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/backports.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/translators.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/translators.hpp)
|
${CMAKE_CURRENT_SOURCE_DIR}/message_logger.hpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_default.hpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_handler.hpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_syslog.hpp
|
||||||
|
)
|
||||||
|
|
||||||
set(TRGT_headers ${TRGT_hpp})
|
set(TRGT_headers ${TRGT_moc_hpp} ${TRGT_hpp})
|
||||||
# cmake-format: on
|
# cmake-format: on
|
||||||
|
|
||||||
add_library(${TRGT}-header-only INTERFACE)
|
qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_private_hpp} ${TRGT_moc_hpp})
|
||||||
target_include_directories(
|
|
||||||
${TRGT}-header-only SYSTEM INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
|
||||||
|
|
||||||
if(MYXLIB_BUILD_LIBRARIES)
|
add_library(${TRGT} OBJECT ${TRGT_cpp} ${TRGT_moc_cpp} ${TRGT_moc_private_hpp} ${TRGT_headers})
|
||||||
add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers})
|
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME myx-${TRGT})
|
||||||
common_target_properties(${TRGT})
|
myx_cmake_common_target_properties(${TRGT})
|
||||||
|
myx_cmake_add_static_library(${TRGT})
|
||||||
|
myx_cmake_add_shared_library(${TRGT})
|
||||||
|
|
||||||
# Создание цели для проверки утилитой clang-tidy
|
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
|
||||||
|
|
||||||
# Создание цели для проверки утилитой clang-analyze
|
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
install(FILES ${TRGT_headers} COMPONENT dev
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT})
|
||||||
# Создание цели для проверки утилитой clazy
|
|
||||||
add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
|
||||||
|
|
||||||
# Создание цели для проверки утилитой pvs-studio
|
|
||||||
add_pvs_check(${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})
|
|
||||||
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})
|
|
||||||
|
|
||||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
|
||||||
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
|
|
||||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
||||||
|
44
src/myx/qt/message_logger.hpp
Normal file
44
src/myx/qt/message_logger.hpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef MYX_QT_MESSAGE_LOGGER_HPP_
|
||||||
|
#define MYX_QT_MESSAGE_LOGGER_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <myx/backports/qt/common.hpp>
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include <QMessageLogContext>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace qt {
|
||||||
|
|
||||||
|
class MessageLogger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~MessageLogger() noexcept ( true ) = default;
|
||||||
|
|
||||||
|
virtual void debug( const QMessageLogContext& context, const QString& ) = 0;
|
||||||
|
virtual void info( const QMessageLogContext& context, const QString& ) = 0;
|
||||||
|
virtual void warning( const QMessageLogContext& context, const QString& ) = 0;
|
||||||
|
virtual void critical( const QMessageLogContext& context, const QString& ) = 0;
|
||||||
|
virtual void fatal( const QMessageLogContext& context, const QString& ) = 0;
|
||||||
|
|
||||||
|
void setEnabled( bool v = true ) { m_enabled = v; }
|
||||||
|
bool isEnabled() { return( m_enabled ); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool m_enabled { true };
|
||||||
|
};
|
||||||
|
|
||||||
|
using MessageLoggersList = QList< QSharedPointer< MessageLogger > >;
|
||||||
|
extern MessageLoggersList messageLoggersList;
|
||||||
|
|
||||||
|
} // namespace qt
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
|
||||||
|
#endif // ifndef MYX_QT_MESSAGE_LOGGER_HPP_
|
46
src/myx/qt/message_logger_default.cpp
Normal file
46
src/myx/qt/message_logger_default.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include <myx/backports/qt/common.hpp>
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
|
#include <myx/qt/message_logger_default.hpp>
|
||||||
|
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace qt {
|
||||||
|
|
||||||
|
void MessageLoggerDefault::debug( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
fprintf( stderr, "D: %s\n", msg.toUtf8().data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageLoggerDefault::info( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
fprintf( stderr, "I: %s\n", msg.toUtf8().data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageLoggerDefault::warning( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
fprintf( stderr, "W: %s\n", msg.toUtf8().data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageLoggerDefault::critical( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageLoggerDefault::fatal( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace qt
|
||||||
|
|
||||||
|
} // namespace myx
|
31
src/myx/qt/message_logger_default.hpp
Normal file
31
src/myx/qt/message_logger_default.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef MYX_QT_MESSAGE_LOGGER_DEFAULT_HPP_
|
||||||
|
#define MYX_QT_MESSAGE_LOGGER_DEFAULT_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <myx/backports/qt/common.hpp>
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
#include <myx/qt/message_logger.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace qt {
|
||||||
|
|
||||||
|
class MessageLoggerDefault : public MessageLogger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~MessageLoggerDefault() noexcept ( true ) = default;
|
||||||
|
|
||||||
|
void debug( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
void info( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
void warning( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
void critical( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
void fatal( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace qt
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
|
||||||
|
#endif // ifndef MYX_QT_MESSAGE_LOGGER_DEFAULT_HPP_
|
81
src/myx/qt/message_logger_handler.cpp
Normal file
81
src/myx/qt/message_logger_handler.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#include <myx/backports/qt/common.hpp>
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
|
#include <myx/qt/message_logger.hpp>
|
||||||
|
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace qt {
|
||||||
|
|
||||||
|
MessageLoggersList messageLoggersList;
|
||||||
|
|
||||||
|
void message_logger_handler( QtMsgType type, const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
if ( messageLoggersList.isEmpty() )
|
||||||
|
{
|
||||||
|
QByteArray localMsg = msg.toLocal8Bit();
|
||||||
|
const char* file = context.file != nullptr ? context.file : "";
|
||||||
|
const char* function = context.function != nullptr ? context.function : "";
|
||||||
|
switch ( type )
|
||||||
|
{
|
||||||
|
case QtDebugMsg:
|
||||||
|
#ifndef QT_NO_DEBUG_OUTPUT
|
||||||
|
// fprintf( stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||||
|
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case QtInfoMsg:
|
||||||
|
#ifndef QT_NO_INFO_OUTPUT
|
||||||
|
// fprintf( stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||||
|
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case QtWarningMsg:
|
||||||
|
#ifndef QT_NO_WARNING_OUTPUT
|
||||||
|
// fprintf( stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||||
|
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case QtCriticalMsg:
|
||||||
|
// fprintf( stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||||
|
// fprintf( stderr, "%s\n", localMsg.constData() );
|
||||||
|
// break;
|
||||||
|
case QtFatalMsg:
|
||||||
|
// fprintf( stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||||
|
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||||
|
break;
|
||||||
|
} // switch
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch ( type )
|
||||||
|
{
|
||||||
|
case QtDebugMsg:
|
||||||
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||||
|
{ if ( m->isEnabled() ) { m->debug( context, msg ); } }
|
||||||
|
break;
|
||||||
|
case QtInfoMsg:
|
||||||
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||||
|
{ if ( m->isEnabled() ) { m->info( context, msg ); } }
|
||||||
|
break;
|
||||||
|
case QtWarningMsg:
|
||||||
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||||
|
{ if ( m->isEnabled() ) { m->warning( context, msg ); } }
|
||||||
|
break;
|
||||||
|
case QtCriticalMsg:
|
||||||
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||||
|
{ if ( m->isEnabled() ) { m->critical( context, msg ); } }
|
||||||
|
break;
|
||||||
|
case QtFatalMsg:
|
||||||
|
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||||
|
{ if ( m->isEnabled() ) { m->fatal( context, msg ); } }
|
||||||
|
break;
|
||||||
|
} // switch
|
||||||
|
}
|
||||||
|
} // message_logger_handler
|
||||||
|
|
||||||
|
} // namespace qt
|
||||||
|
|
||||||
|
} // namespace myx
|
20
src/myx/qt/message_logger_handler.hpp
Normal file
20
src/myx/qt/message_logger_handler.hpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef MYX_QT_MESSAGE_LOGGER_HANDLER_HPP_
|
||||||
|
#define MYX_QT_MESSAGE_LOGGER_HANDLER_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <myx/backports/qt/common.hpp>
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
#include <myx/qt/message_logger.hpp>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace qt {
|
||||||
|
|
||||||
|
void message_logger_handler( QtMsgType type, const QMessageLogContext& context, const QString& msg );
|
||||||
|
|
||||||
|
} // namespace qt
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
|
||||||
|
#endif // ifndef MYX_QT_MESSAGE_LOGGER_HANDLER_HPP_
|
61
src/myx/qt/message_logger_syslog.cpp
Normal file
61
src/myx/qt/message_logger_syslog.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include <myx/backports/qt/common.hpp>
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
|
#include <myx/qt/message_logger_syslog.hpp>
|
||||||
|
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace qt {
|
||||||
|
|
||||||
|
MessageLoggerSyslog::MessageLoggerSyslog() :
|
||||||
|
MessageLogger()
|
||||||
|
{
|
||||||
|
// openlog( nullptr, LOG_ODELAY, LOG_USER );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MessageLoggerSyslog::~MessageLoggerSyslog() noexcept ( true )
|
||||||
|
{
|
||||||
|
closelog();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageLoggerSyslog::debug( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
syslog( LOG_DEBUG, "%s\n", msg.toUtf8().data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageLoggerSyslog::info( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
syslog( LOG_INFO, "%s\n", msg.toUtf8().data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageLoggerSyslog::warning( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
syslog( LOG_WARNING, "%s\n", msg.toUtf8().data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageLoggerSyslog::critical( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
syslog( LOG_CRIT, "%s\n", msg.toUtf8().data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MessageLoggerSyslog::fatal( const QMessageLogContext& context, const QString& msg )
|
||||||
|
{
|
||||||
|
Q_UNUSED( context )
|
||||||
|
syslog( LOG_EMERG, "%s\n", msg.toUtf8().data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace qt
|
||||||
|
|
||||||
|
} // namespace myx
|
32
src/myx/qt/message_logger_syslog.hpp
Normal file
32
src/myx/qt/message_logger_syslog.hpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef MYX_QT_MESSAGE_LOGGER_SYSLOG_HPP_
|
||||||
|
#define MYX_QT_MESSAGE_LOGGER_SYSLOG_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <myx/backports/qt/common.hpp>
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
#include <myx/qt/message_logger.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace qt {
|
||||||
|
|
||||||
|
class MessageLoggerSyslog : public MessageLogger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MessageLoggerSyslog();
|
||||||
|
virtual ~MessageLoggerSyslog() noexcept ( true );
|
||||||
|
|
||||||
|
void debug( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
void info( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
void warning( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
void critical( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
void fatal( const QMessageLogContext& context, const QString& msg ) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace qt
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
|
||||||
|
#endif // ifndef MYX_QT_MESSAGE_LOGGER_SYSLOG_HPP_
|
131
src/myx/qt/posix_signal_watcher.cpp
Normal file
131
src/myx/qt/posix_signal_watcher.cpp
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#ifndef MYX_QT_POSIX_SIGNAL_WATCHER_CPP_
|
||||||
|
#define MYX_QT_POSIX_SIGNAL_WATCHER_CPP_
|
||||||
|
|
||||||
|
#include <myx/backports/cpp/helpers.hpp>
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
|
#include <myx/qt/posix_signal_watcher.hpp>
|
||||||
|
#include <myx/qt/posix_signal_watcher_p.hpp>
|
||||||
|
|
||||||
|
namespace myx {
|
||||||
|
|
||||||
|
namespace qt {
|
||||||
|
|
||||||
|
std::array< int, 2 > PosixSignalWatcherPrivate::mSockpair { { 0, 0 } }; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
|
||||||
|
PosixSignalWatcherPrivate::~PosixSignalWatcherPrivate() = default;
|
||||||
|
|
||||||
|
PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) :
|
||||||
|
q_ptr( q )
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_UNIX
|
||||||
|
// Create socket pair
|
||||||
|
if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, mSockpair.data() ) != 0 )
|
||||||
|
{
|
||||||
|
qDebug() << "PosixSignalWatcher: socketpair: " << ::strerror( errno );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Create a notifier for the read end of the pair
|
||||||
|
// 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.
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal )
|
||||||
|
{
|
||||||
|
if ( m_watchedSignals.contains( signal ) )
|
||||||
|
{
|
||||||
|
qDebug() << "Already watching for signal " << signal;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_UNIX
|
||||||
|
// Register a sigaction which will write to the socket pair
|
||||||
|
struct sigaction sigact; //NOLINT
|
||||||
|
sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; //NOLINT
|
||||||
|
sigact.sa_flags = 0;
|
||||||
|
sigemptyset( &sigact.sa_mask );
|
||||||
|
sigact.sa_flags |= SA_RESTART;
|
||||||
|
sigact.sa_restorer = nullptr;
|
||||||
|
if ( ::sigaction( signal, &sigact, nullptr ) != 0 )
|
||||||
|
{
|
||||||
|
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( mSockpair[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 ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* 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_
|
49
src/myx/qt/posix_signal_watcher.hpp
Normal file
49
src/myx/qt/posix_signal_watcher.hpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef MYX_QT_POSIX_SIGNAL_WATCHER_HPP_
|
||||||
|
#define MYX_QT_POSIX_SIGNAL_WATCHER_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
void watchForSignal( int signal );
|
||||||
|
Q_SIGNAL void posixSignal( int signal );
|
||||||
|
|
||||||
|
private:
|
||||||
|
PosixSignalWatcherPrivate* const d_ptr = nullptr;
|
||||||
|
Q_DECLARE_PRIVATE( PosixSignalWatcher ) //NOLINT
|
||||||
|
}; // class PosixSignalWatcher
|
||||||
|
|
||||||
|
} // namespace qt
|
||||||
|
|
||||||
|
} // namespace myx
|
||||||
|
|
||||||
|
#endif // ifndef MYX_QT_POSIX_SIGNAL_WATCHER_HPP_
|
58
src/myx/qt/posix_signal_watcher_p.hpp
Normal file
58
src/myx/qt/posix_signal_watcher_p.hpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#ifndef MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_
|
||||||
|
#define MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
#include <myx/qt/posix_signal_watcher.hpp>
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSocketNotifier>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#ifdef Q_OS_UNIX
|
||||||
|
#include <cerrno>
|
||||||
|
#include <csignal>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#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:
|
||||||
|
explicit PosixSignalWatcherPrivate( PosixSignalWatcher* q );
|
||||||
|
~PosixSignalWatcherPrivate();
|
||||||
|
|
||||||
|
void watchForSignal( int signal );
|
||||||
|
static void signalHandler( int signal );
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DECLARE_PUBLIC( PosixSignalWatcher )
|
||||||
|
|
||||||
|
PosixSignalWatcher* const q_ptr = nullptr;
|
||||||
|
static std::array< int, 2 > mSockpair;
|
||||||
|
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_
|
@ -1,13 +1,10 @@
|
|||||||
#ifndef MYX_QT_TRANSLATORS_CPP_
|
#ifndef MYX_QT_TRANSLATORS_CPP_
|
||||||
#define MYX_QT_TRANSLATORS_CPP_
|
#define MYX_QT_TRANSLATORS_CPP_
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
#include <myx/backports/qt/common.hpp>
|
||||||
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
#ifndef MYXLIB_HEADER_ONLY
|
|
||||||
#include <myx/qt/translators.hpp>
|
#include <myx/qt/translators.hpp>
|
||||||
#else
|
|
||||||
#pragma once
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
@ -54,7 +51,7 @@ MYXLIB_INLINE void append_translators( QTranslatorsList& translators, const QStr
|
|||||||
translator->deleteLater();
|
translator->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( auto* i : qAsConst( translators ) )
|
for ( auto* i: qAsConst( translators ) )
|
||||||
{
|
{
|
||||||
qApp->installTranslator( i );
|
qApp->installTranslator( i );
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <myx/base/config.hpp>
|
#include <myx/backports/qt/common.hpp>
|
||||||
#include <myx/qt/backports.hpp>
|
#include <myx/core/config.hpp>
|
||||||
|
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
|
||||||
@ -20,8 +20,4 @@ void append_translators( QTranslatorsList& translators, const QString& appName )
|
|||||||
|
|
||||||
} // namespace myx
|
} // namespace myx
|
||||||
|
|
||||||
#ifdef MYXLIB_HEADER_ONLY
|
|
||||||
#include "translators.cpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // ifndef MYX_QT_TRANSLATORS_HPP_
|
#endif // ifndef MYX_QT_TRANSLATORS_HPP_
|
||||||
|
Reference in New Issue
Block a user