Compare commits
	
		
			94 Commits
		
	
	
		
			a4d00ed80b
			...
			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 | 
| @@ -18,6 +18,8 @@ portability-*, | ||||
| -readability-else-after-return, | ||||
| -modernize-use-trailing-return-type, | ||||
| -modernize-avoid-c-arrays, | ||||
| -modernize-use-nodiscard, | ||||
| -modernize-concat-nested-namespaces, | ||||
| -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 | ||||
|  | ||||
| # Каталог для тестирования установки | ||||
| _output | ||||
| @@ -13,6 +14,8 @@ files/etc/*.conf | ||||
| files/lib/* | ||||
| files/log/* | ||||
|  | ||||
| !.gitkeep | ||||
| !.gitignore | ||||
|  | ||||
| ### | ||||
| ### Общие настройки для C, C++, Fortran, Qt, CMake, Ninja, LaTeX и редакторов | ||||
| @@ -43,6 +46,8 @@ files/log/* | ||||
| [._]ss[a-gi-z] | ||||
| [._]sw[a-p] | ||||
|  | ||||
| # Project | ||||
| .vimprj | ||||
| # Temporary | ||||
| .netrwhist | ||||
| *~ | ||||
| @@ -106,6 +111,10 @@ compile_commands.json | ||||
| CTestTestfile.cmake | ||||
| _deps | ||||
|  | ||||
| ### CMake Patch ### | ||||
| # External projects | ||||
| *-prefix/ | ||||
|  | ||||
|  | ||||
| ### | ||||
| ### Ninja | ||||
| @@ -162,6 +171,38 @@ target_wrapper.* | ||||
| *_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 | ||||
| ### | ||||
| @@ -173,6 +214,7 @@ target_wrapper.* | ||||
| *.blg | ||||
| *.dvi | ||||
| *.fdb_latexmk | ||||
| *.fls | ||||
| *.glg | ||||
| *.glo | ||||
| *.gls | ||||
| @@ -195,6 +237,7 @@ target_wrapper.* | ||||
| *.synctex.gz | ||||
| *.toc | ||||
| *.vrb | ||||
| *.xdv | ||||
| *.xdy | ||||
| *.tdo | ||||
|  | ||||
|   | ||||
| @@ -18,3 +18,7 @@ focal-nightly: | ||||
| elbrus-nightly: | ||||
|   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) | ||||
|  | ||||
| # Название проекта | ||||
| 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) | ||||
|   list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/cmlib) | ||||
| else() | ||||
|   message(FATAL_ERROR "CMake library directory not exists") | ||||
| endif() | ||||
| list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/find) | ||||
| # Обязательные переменные | ||||
| set(MYX_CMAKE_ORGANIZATION_NAME "ECS5" CACHE STRING "") | ||||
| set(MYX_CMAKE_AUTHOR_NAME "Андрей Астафьев" CACHE STRING "") | ||||
| set(MYX_CMAKE_AUTHOR_EMAIL "dev@246060.ru" CACHE STRING "") | ||||
| set(MYX_CMAKE_DESCRIPTION "Разные функции" CACHE STRING "") | ||||
|  | ||||
| if(NOT DEFINED MYXLIB_MASTER_PROJECT) | ||||
|   if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) | ||||
| @@ -21,8 +19,9 @@ if(NOT DEFINED MYXLIB_MASTER_PROJECT) | ||||
|   endif() | ||||
| endif() | ||||
|  | ||||
| include(CMLibCommon) | ||||
| find_package(MyxCMake 0.4.5 REQUIRED) | ||||
|  | ||||
| #cmlib_set_cxx_standard(11) | ||||
| option(MYXLIB_BUILD_EXAMPLES "Build examples" OFF) | ||||
|  | ||||
| # Поиск библиотек с помощью pkgconfig | ||||
| @@ -35,19 +34,28 @@ find_package(Threads REQUIRED) | ||||
| # Qt5 | ||||
| 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/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) | ||||
|   add_subdirectory(examples/base) | ||||
|   add_subdirectory(examples/core) | ||||
|   add_subdirectory(examples/filesystem) | ||||
|   add_subdirectory(examples/qt) | ||||
|   add_custom_target(examples example-base-endian example-filesystem-paths example-qt-tranlators | ||||
|   add_custom_target(examples example-core-endian example-filesystem-paths example-qt-tranlators | ||||
|                              example-qt-posix-signal-watcher) | ||||
| endif() | ||||
|  | ||||
| # Документация | ||||
| add_subdirectory(cmake/doc) | ||||
| myx_cmake_doc_doxygen(LATEX YES HTML YES) | ||||
| myx_cmake_doc_breathe() | ||||
|   | ||||
 Submodule cmake/cmlib deleted from 186d67c4bb
									
								
							 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 7424dcf8eb
									
								
							 Submodule cmake/find deleted from 00bbf686cd
									
								
							 Submodule cmake/generators deleted from 74d499b9cb
									
								
							| @@ -1,52 +0,0 @@ | ||||
| # Название основной цели в текущем каталоге | ||||
| set(TRGT example-base-endian) | ||||
|  | ||||
| # Список файлов исходных текстов | ||||
| 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() | ||||
| @@ -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,8 +1,9 @@ | ||||
| #include <myx/base/config.hpp> | ||||
| #include <myx/base/endian_types.hpp> | ||||
| #include <myx/core/config.hpp> | ||||
| #include <myx/core/endian_types.hpp> | ||||
| 
 | ||||
| #include <QDebug> | ||||
| 
 | ||||
| //NOLINTNEXTLINE
 | ||||
| #define CMLIB_PROJECT_NAME "myxlib" | ||||
| 
 | ||||
| 
 | ||||
| @@ -12,11 +13,11 @@ int main( int argc, char** argv ) | ||||
| 	(void)argv; | ||||
| 
 | ||||
| 	beint64 bi  = 1; | ||||
| 	int64_t bii = reinterpret_cast< int64_t* >( &bi )[0]; | ||||
| 	int64_t bii = reinterpret_cast< int64_t* >( &bi )[0]; //NOLINT
 | ||||
| 	qDebug() << hex << bi << bii; | ||||
| 
 | ||||
| 	leint64 li  = 1; | ||||
| 	int64_t lii = reinterpret_cast< int64_t* >( &li )[0]; | ||||
| 	int64_t lii = reinterpret_cast< int64_t* >( &li )[0]; //NOLINT
 | ||||
| 	qDebug() << hex << li << lii; | ||||
| 
 | ||||
| 	return( 0 ); | ||||
							
								
								
									
										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) | ||||
| @@ -5,48 +5,18 @@ set(TRGT example-filesystem-paths) | ||||
| set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.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) | ||||
|   myx_cmake_common_target_properties(${TRGT}) | ||||
|  | ||||
|   # Имя выходного файла для цели | ||||
|   set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME filesystem-minimal) | ||||
|  | ||||
|   add_sanitizers(${TRGT}) | ||||
|   # Qt5 | ||||
|   target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) | ||||
|   add_dependencies(${TRGT} core filesystem) | ||||
|  | ||||
|   cotire(${TRGT}) | ||||
|  | ||||
|   add_dependencies(${TRGT} create_auxilary_symlinks) | ||||
|  | ||||
|   # Правила для установки | ||||
|   install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||||
|   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 <QCoreApplication> | ||||
| #include <QDebug> | ||||
|  | ||||
| //NOLINTNEXTLINE | ||||
| #define CMLIB_PROJECT_NAME "myxlib" | ||||
|  | ||||
| namespace MF = myx::filesystem; | ||||
| @@ -17,22 +18,19 @@ int main( int argc, char** argv ) | ||||
| 	QCoreApplication::setApplicationName( QStringLiteral( CMLIB_PROJECT_NAME ) ); | ||||
| 	MF::Paths& paths = MF::Paths::instance(); | ||||
|  | ||||
| 	paths.init( QStringLiteral( CMLIB_PROJECT_NAME ), QStringLiteral( "conf" ) ); | ||||
|  | ||||
| 	qDebug() << "prefixDirectory           : " << paths.prefixDirectory(); | ||||
| 	qDebug() << "prefixDirectory           : " << paths.projectDirectory(); | ||||
|  | ||||
| 	qDebug() << "executableName            : " << paths.executableName(); | ||||
| 	qDebug() << "executableFilePath        : " << paths.executableFilePath(); | ||||
| 	qDebug() << "executableDirectory       : " << paths.executableDirectory(); | ||||
|  | ||||
| 	qDebug() << "configFileName            : " << paths.configFileName(); | ||||
| 	qDebug() << "configFilePath            : " << paths.configFilePath(); | ||||
| 	qDebug() << "executableDirectory       : " << paths.executableDirectory() << endl; | ||||
|  | ||||
| 	qDebug() << "systemThemeDirectory      : " << paths.systemThemeDirectory(); | ||||
| 	qDebug() << "systemConfigDirectory     : " << paths.systemConfigDirectory(); | ||||
| 	qDebug() << "systemConstDataDirectory  : " << paths.systemConstDataDirectory(); | ||||
| 	qDebug() << "systemVarDataDirectory    : " << paths.systemVarDataDirectory(); | ||||
| 	qDebug() << "systemLogDirectory        : " << paths.systemLogDirectory(); | ||||
| 	qDebug() << "systemLogDirectory        : " << paths.systemLogDirectory() << endl; | ||||
|  | ||||
| 	qDebug() << "userThemeDirectory        : " << paths.userThemeDirectory(); | ||||
| 	qDebug() << "userConfigDirectory       : " << paths.userConfigDirectory(); | ||||
| 	qDebug() << "userConstDataDirectory    : " << paths.userConstDataDirectory(); | ||||
| 	qDebug() << "userVarDataDirectory      : " << paths.userVarDataDirectory(); | ||||
|   | ||||
| @@ -4,56 +4,26 @@ set(TRGT example-qt-translators) | ||||
| # Список файлов исходных текстов | ||||
| set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp) | ||||
|  | ||||
| qt5_translation( | ||||
| myx_cmake_qt5_translation( | ||||
|   TRGT_qrc | ||||
|   OUTPUT_DIR ${CMAKE_SOURCE_DIR}/l10n | ||||
|   BASE_NAME ${TRGT} | ||||
|   LANGUAGES ru_RU) | ||||
|  | ||||
| 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 qt) | ||||
|  | ||||
|   target_link_libraries(${TRGT} base_static qt_static) | ||||
|  | ||||
|   target_link_libraries(${TRGT} Qt5::Core) | ||||
|   target_link_libraries(${TRGT} Threads::Threads) | ||||
|   myx_cmake_common_target_properties(${TRGT}) | ||||
|  | ||||
|   # Имя выходного файла для цели | ||||
|   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) | ||||
|  | ||||
|   # Правила для установки | ||||
|   install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||||
|   target_link_libraries(${TRGT} Qt5::Core) | ||||
|   target_link_libraries(${TRGT} Threads::Threads) | ||||
| endif() | ||||
|   | ||||
| @@ -5,49 +5,19 @@ set(TRGT example-qt-posix-signal-watcher) | ||||
| set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher.cpp) | ||||
|  | ||||
| if(MYXLIB_BUILD_EXAMPLES) | ||||
|   # Путь поиска библиотек внутри проекта | ||||
|   link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) | ||||
|  | ||||
|   # Цель для создания исполняемого файла | ||||
|   add_executable(${TRGT} ${TRGT_cpp}) | ||||
|   common_target_properties(${TRGT}) | ||||
|  | ||||
|   # Создание цели для проверки утилитой clang-tidy | ||||
|   add_clang_tidy_check(${TRGT} ${TRGT_cpp}) | ||||
|  | ||||
|   # Создание цели для проверки утилитой clang-analyze | ||||
|   add_clang_analyze_check(${TRGT} ${TRGT_cpp}) | ||||
|  | ||||
|   # Создание цели для проверки утилитой clazy | ||||
|   add_clazy_check(${TRGT} ${TRGT_cpp}) | ||||
|  | ||||
|   # Создание цели для проверки утилитой pvs-studio | ||||
|   add_pvs_check(${TRGT}) | ||||
|  | ||||
|   # Создание цели для автоматического форматирования кода | ||||
|   add_format_sources(${TRGT} ${TRGT_cpp}) | ||||
|  | ||||
|   # Qt5 | ||||
|   target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src) | ||||
|   target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) | ||||
|  | ||||
|   target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) | ||||
|   add_dependencies(${TRGT} base qt) | ||||
|  | ||||
|   target_link_libraries(${TRGT} base_static qt_static) | ||||
|  | ||||
|   target_link_libraries(${TRGT} Qt5::Core) | ||||
|   target_link_libraries(${TRGT} Threads::Threads) | ||||
|   myx_cmake_common_target_properties(${TRGT}) | ||||
|  | ||||
|   # Имя выходного файла для цели | ||||
|   set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME qt-posix-signal-watcher) | ||||
|  | ||||
|   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) | ||||
|  | ||||
|   # Правила для установки | ||||
|   install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||||
|   target_link_libraries(${TRGT} Qt5::Core) | ||||
|   target_link_libraries(${TRGT} Threads::Threads) | ||||
| endif() | ||||
|   | ||||
| @@ -15,7 +15,7 @@ int main( int argc, char* argv[] ) | ||||
| 	sigwatch.watchForSignal( SIGTERM ); | ||||
| 	QObject::connect( &sigwatch, &MQ::PosixSignalWatcher::posixSignal, &app, &QCoreApplication::quit ); | ||||
|  | ||||
| 	int exitcode = app.exec(); | ||||
| 	int exitcode = QCoreApplication::exec(); | ||||
| 	qDebug() << "Goodbye"; | ||||
| 	return( exitcode ); | ||||
| } | ||||
|   | ||||
							
								
								
									
										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,2 +1,3 @@ | ||||
| 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,23 +7,28 @@ | ||||
| // Official repository: https://github.com/boostorg/beast
 | ||||
| //
 | ||||
| 
 | ||||
| #ifndef MYX_BASE_SPAN_HPP_ | ||||
| #define MYX_BASE_SPAN_HPP_ | ||||
| #ifndef MYX_BACKPORTS_CPP_SPAN_HPP_ | ||||
| #define MYX_BACKPORTS_CPP_SPAN_HPP_ | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #if ( __cplusplus > 201703L ) | ||||
| 
 | ||||
| #include <span> | ||||
| 
 | ||||
| #else | ||||
| 
 | ||||
| #include <myx/backports/cpp/helpers.hpp> | ||||
| 
 | ||||
| #include <algorithm> | ||||
| #include <iterator> | ||||
| #include <string> | ||||
| #include <type_traits> | ||||
| 
 | ||||
| namespace myx { | ||||
| 
 | ||||
| namespace base { | ||||
| 
 | ||||
| template< typename ... Ts > struct make_void { typedef void type;};           // NOLINT
 | ||||
| template< typename ... Ts > using void_t = typename make_void< Ts... >::type; // NOLINT
 | ||||
| namespace std { //-V1061
 | ||||
| 
 | ||||
| template< class T, class E, class = void > | ||||
| struct is_contiguous_container : std::false_type {};                          // NOLINT
 | ||||
| struct is_contiguous_container : std::false_type {}; // NOLINT
 | ||||
| 
 | ||||
| template< class T, class E > | ||||
| struct is_contiguous_container< T, E, void_t< | ||||
| @@ -52,38 +57,38 @@ struct is_contiguous_container< T, E, void_t< | ||||
|     @tparam T The type pointed to by span iterators | ||||
| */ | ||||
| template< class T > | ||||
| class span                                                                    // NOLINT
 | ||||
| class span                                           // NOLINT
 | ||||
| { | ||||
| 	T*          m_data = nullptr; | ||||
| 	std::size_t m_size = 0; | ||||
| 
 | ||||
| public: | ||||
| 	/// The type of value, including cv qualifiers
 | ||||
| 	using element_type = T; | ||||
| 	using ElementType = T; | ||||
| 
 | ||||
| 	/// The type of value of each span element
 | ||||
| 	using value_type = typename std::remove_const< T >::type; | ||||
| 	using ValueType = typename std::remove_const< T >::type; | ||||
| 
 | ||||
| 	/// The type of integer used to index the span
 | ||||
| 	using index_type = std::ptrdiff_t; | ||||
| 	using IndexType = std::ptrdiff_t; | ||||
| 
 | ||||
| 	/// A pointer to a span element
 | ||||
| 	using pointer = T*; | ||||
| 	using Pointer = T*; | ||||
| 
 | ||||
| 	/// A reference to a span element
 | ||||
| 	using reference = T&; | ||||
| 	using Reference = T&; | ||||
| 
 | ||||
| 	/// The iterator used by the container
 | ||||
| 	using iterator = pointer; | ||||
| 	using Iterator = Pointer; | ||||
| 
 | ||||
| 	/// The const pointer used by the container
 | ||||
| 	using const_pointer = T const*; | ||||
| 	using ConstPointer = T const*; | ||||
| 
 | ||||
| 	/// The const reference used by the container
 | ||||
| 	using const_reference = T const&; | ||||
| 	using ConstReference = T const&; | ||||
| 
 | ||||
| 	/// The const iterator used by the container
 | ||||
| 	using const_iterator = const_pointer; | ||||
| 	using ConstIterator = ConstPointer; | ||||
| 
 | ||||
| 	/// Constructor
 | ||||
| 	span() = default; | ||||
| @@ -95,22 +100,18 @@ public: | ||||
| 	span& operator=( span const& ) = default; | ||||
| 
 | ||||
| 	/** Constructor
 | ||||
| 
 | ||||
| 		@param data A pointer to the beginning of the range of elements | ||||
| 
 | ||||
| 		@param size The number of elements pointed to by `data` | ||||
| 	*/ | ||||
| 	 *  @param data A pointer to the beginning of the range of elements | ||||
| 	 *  @param size The number of elements pointed to by `data` | ||||
| 	 */ | ||||
| 	span( T* data, std::size_t size ) : | ||||
| 		m_data( data ), | ||||
| 		m_size( size ) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** Constructor
 | ||||
| 
 | ||||
| 		@param container The container to construct from | ||||
| 	*/ | ||||
| 	 *  @param container The container to construct from | ||||
| 	 */ | ||||
| 	template< class ContiguousContainer, | ||||
| 	          class = typename std::enable_if< | ||||
| 			  is_contiguous_container< | ||||
| @@ -123,7 +124,6 @@ public: | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	template< class CharT, class Traits, class Allocator > | ||||
| 	explicit | ||||
| 	span( std::basic_string< CharT, Traits, Allocator >& s ) : | ||||
| @@ -132,7 +132,6 @@ public: | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	template< class CharT, class Traits, class Allocator > | ||||
| 	explicit | ||||
| 	span( std::basic_string< CharT, Traits, Allocator > const& s ) : | ||||
| @@ -141,13 +140,11 @@ public: | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** Assignment
 | ||||
| 
 | ||||
| 		@param container The container to assign from | ||||
| 	*/ | ||||
| 	 *  @param container The container to assign from | ||||
| 	 */ | ||||
| 	template< class ContiguousContainer > | ||||
| 	typename std::enable_if< is_contiguous_container< | ||||
| 	typename std::enable_if< is_contiguous_container< //NOLINT
 | ||||
| 					 ContiguousContainer, T >::value, | ||||
| 	                         span& >::type | ||||
| 	operator=( ContiguousContainer&& container ) | ||||
| @@ -157,7 +154,6 @@ public: | ||||
| 		return( *this ); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	template< class CharT, class Traits, class Allocator > | ||||
| 	span& | ||||
| 	operator=( std::basic_string< | ||||
| @@ -168,7 +164,6 @@ public: | ||||
| 		return( *this ); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	template< class CharT, class Traits, class Allocator > | ||||
| 	span& | ||||
| 	operator=( std::basic_string< | ||||
| @@ -179,7 +174,6 @@ public: | ||||
| 		return( *this ); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/// Returns `true` if the span is empty
 | ||||
| 	bool | ||||
| 	empty() const | ||||
| @@ -187,7 +181,6 @@ public: | ||||
| 		return( m_size == 0 ); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/// Returns a pointer to the beginning of the span
 | ||||
| 	T* | ||||
| 	data() const | ||||
| @@ -195,7 +188,6 @@ public: | ||||
| 		return( m_data ); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/// Returns the number of elements in the span
 | ||||
| 	std::size_t | ||||
| 	size() const | ||||
| @@ -203,41 +195,37 @@ public: | ||||
| 		return( m_size ); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/// Returns an iterator to the beginning of the span
 | ||||
| 	iterator | ||||
| 	Iterator | ||||
| 	begin() const | ||||
| 	{ | ||||
| 		return( m_data ); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/// Returns an iterator to the beginning of the span
 | ||||
| 	const_iterator | ||||
| 	ConstIterator | ||||
| 	cbegin() const | ||||
| 	{ | ||||
| 		return( m_data ); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/// Returns an iterator to one past the end of the span
 | ||||
| 	iterator | ||||
| 	Iterator | ||||
| 	end() const | ||||
| 	{ | ||||
| 		return( m_data + m_size ); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/// Returns an iterator to one past the end of the span
 | ||||
| 	const_iterator | ||||
| 	ConstIterator | ||||
| 	cend() const | ||||
| 	{ | ||||
| 		return( m_data + m_size ); | ||||
| 	} | ||||
| }; // class span
 | ||||
| 
 | ||||
| } // namespace base
 | ||||
| } // namespace std
 | ||||
| 
 | ||||
| } // namespace myx
 | ||||
| #endif // if ( __cplusplus > 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_ | ||||
| #define MYX_QT_BACKPORTS_HPP_ | ||||
| #ifndef MYX_BACKPORTS_QT_COMMON_HPP_ | ||||
| #define MYX_BACKPORTS_QT_COMMON_HPP_ | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #if ( defined ( TARGET_LSB_ID_AstraLinuxSE ) && defined ( TARGET_LSB_CODENAME_smolensk ) ) | ||||
| 
 | ||||
| #define override | ||||
| 
 | ||||
| #if QT_VERSION <= 0x050700 | ||||
| #if !defined( QT_VERSION ) | ||||
| #include <QtGlobal> | ||||
| #endif | ||||
| 
 | ||||
| #if ( QT_VERSION <= 0x050700 ) | ||||
| template< typename ... Args > | ||||
| struct QOverload | ||||
| { | ||||
| @@ -31,8 +30,6 @@ Q_DECL_CONSTEXPR typename std::add_const< T >::type& qAsConst( T& t ) noexcept | ||||
| template < typename T > | ||||
| void qAsConst( const T&& ) = delete; | ||||
| 
 | ||||
| 
 | ||||
| #endif // if QT_VERSION <= 0x050700
 | ||||
| #endif // if ( defined ( TARGET_LSB_ID_AstraLinuxSE ) && defined ( TARGET_LSB_CODENAME_smolensk ) )
 | ||||
| 
 | ||||
| #endif // MYX_QT_BACKPORTS_HPP_
 | ||||
| #endif // MYX_BACKPORTS_QT_COMMON_HPP_
 | ||||
| @@ -1,51 +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_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_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() | ||||
|  | ||||
| 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 +0,0 @@ | ||||
| #include <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 k_i = 1; | ||||
| 		return( ( reinterpret_cast< const char& >( k_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 k_i = 1; | ||||
| 		return( ( reinterpret_cast< const char& >( k_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}) | ||||
| @@ -1,5 +1,5 @@ | ||||
| #ifndef MYX_BASE_CONFIG_HPP_ | ||||
| #define MYX_BASE_CONFIG_HPP_ | ||||
| #ifndef MYX_CORE_CONFIG_HPP_ | ||||
| #define MYX_CORE_CONFIG_HPP_ | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| @@ -14,4 +14,4 @@ | ||||
| #endif | ||||
| #define MYXLIB_INLINE | ||||
| 
 | ||||
| #endif // MYX_BASE_CONFIG_HPP_
 | ||||
| #endif // MYX_CORE_CONFIG_HPP_
 | ||||
							
								
								
									
										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_ | ||||
| #define MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_ | ||||
| #ifndef MYX_CORE_ENUM_BITWISE_OPERATIONS_HPP_ | ||||
| #define MYX_CORE_ENUM_BITWISE_OPERATIONS_HPP_ | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| @@ -7,7 +7,7 @@ | ||||
| 
 | ||||
| namespace myx { | ||||
| 
 | ||||
| namespace base { | ||||
| namespace core { | ||||
| 
 | ||||
| template< typename Enum > | ||||
| struct EnableBitMaskOperators | ||||
| @@ -17,7 +17,7 @@ struct EnableBitMaskOperators | ||||
| 
 | ||||
| template< typename Enum > | ||||
| typename std::enable_if< EnableBitMaskOperators< Enum >::kEnable, Enum >::type | ||||
| operator ~( Enum e ) | ||||
| operator~( Enum e ) | ||||
| { | ||||
| 	using Underlying = typename std::underlying_type< Enum >::type; | ||||
| 	return( static_cast< Enum >( ~static_cast< Underlying >( e ) ) ); | ||||
| @@ -26,7 +26,7 @@ operator ~( Enum e ) | ||||
| 
 | ||||
| template< typename Enum > | ||||
| 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; | ||||
| 	return( static_cast< Enum >( static_cast< Underlying >( lhs ) | static_cast< Underlying >( rhs ) ) ); | ||||
| @@ -35,7 +35,7 @@ operator |( Enum lhs, Enum rhs ) | ||||
| 
 | ||||
| template< typename Enum > | ||||
| 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; | ||||
| 	lhs              = static_cast< Enum >( static_cast< Underlying >( lhs ) | static_cast< Underlying >( rhs ) ); | ||||
| @@ -45,7 +45,7 @@ operator |=( Enum& lhs, Enum rhs ) | ||||
| 
 | ||||
| template< typename Enum > | ||||
| 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; | ||||
| 	return( static_cast< Enum >( static_cast< Underlying >( lhs ) & static_cast< Underlying >( rhs ) ) ); | ||||
| @@ -54,14 +54,14 @@ operator &( Enum lhs, Enum rhs ) | ||||
| 
 | ||||
| template< typename Enum > | ||||
| 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; | ||||
| 	lhs              = static_cast< Enum >( static_cast< Underlying >( lhs ) & static_cast< Underlying >( rhs ) ); | ||||
| 	return( lhs ); | ||||
| } | ||||
| 
 | ||||
| } // namespace base
 | ||||
| } // namespace core
 | ||||
| 
 | ||||
| } // namespace myx
 | ||||
| 
 | ||||
| @@ -85,9 +85,9 @@ operator &=( Enum& lhs, Enum rhs ) | ||||
| // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
 | ||||
| #define ENABLE_BITMASK_OPERATORS( x ) \ | ||||
| 	template<> \ | ||||
| 	struct myx::base::EnableBitMaskOperators< x > \ | ||||
| 	struct myx::core::EnableBitMaskOperators< x > \ | ||||
| 	{ \ | ||||
| 		static const bool kEnable = true; \ | ||||
| 	}; | ||||
| 
 | ||||
| #endif // ifndef MYX_BASE_ENUM_BITWISE_OPERATIONS_HPP_
 | ||||
| #endif // ifndef MYX_CORE_ENUM_BITWISE_OPERATIONS_HPP_
 | ||||
| @@ -1,5 +1,6 @@ | ||||
| #ifndef MYX_BASE_LIMITS_HPP_ | ||||
| #define MYX_BASE_LIMITS_HPP_ | ||||
| #ifndef MYX_CORE_LIMITS_HPP_ | ||||
| #define MYX_CORE_LIMITS_HPP_ | ||||
| 
 | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| @@ -7,7 +8,7 @@ | ||||
| 
 | ||||
| namespace myx { | ||||
| 
 | ||||
| namespace base { | ||||
| namespace core { | ||||
| 
 | ||||
| /**
 | ||||
|  * @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() }; | ||||
| 
 | ||||
| } // namespace base
 | ||||
| } // namespace core
 | ||||
| 
 | ||||
| } // namespace myx
 | ||||
| 
 | ||||
| #endif // MYX_BASE_LIMITS_HPP_
 | ||||
| #endif // MYX_CORE_LIMITS_HPP_
 | ||||
| @@ -11,37 +11,15 @@ set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.hpp) | ||||
| set(TRGT_headers ${TRGT_hpp}) | ||||
| # cmake-format: on | ||||
|  | ||||
| add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) | ||||
| common_target_properties(${TRGT}) | ||||
|  | ||||
| # Создание цели для проверки утилитой 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}) | ||||
| #add_library(${TRGT} ${TRGT_cpp} ${TRGT_headers}) | ||||
| add_library(${TRGT} OBJECT ${TRGT_cpp} ${TRGT_headers}) | ||||
| set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME myx-${TRGT}) | ||||
| myx_cmake_common_target_properties(${TRGT}) | ||||
| myx_cmake_add_static_library(${TRGT}) | ||||
| myx_cmake_add_shared_library(${TRGT}) | ||||
|  | ||||
| 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() | ||||
|  | ||||
| generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES}) | ||||
| install(FILES ${TRGT_headers} COMPONENT base-dev | ||||
| 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}) | ||||
|  | ||||
| # Цель, используемая только для установки заголовочных файлов без компиляции проекта | ||||
| add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P | ||||
|                                                   "${CMAKE_BINARY_DIR}/cmake_install.cmake") | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| #ifndef MYX_BASE_PATHS_CPP_ | ||||
| #define MYX_BASE_PATHS_CPP_ | ||||
| #ifndef MYX_CORE_PATHS_CPP_ | ||||
| #define MYX_CORE_PATHS_CPP_ | ||||
|  | ||||
| #include <myx/base/config.hpp> | ||||
| #include <myx/core/config.hpp> | ||||
| #include <myx/filesystem/paths.hpp> | ||||
|  | ||||
| #include <paths.h> | ||||
| @@ -13,166 +13,9 @@ namespace myx { | ||||
|  | ||||
| namespace filesystem { | ||||
|  | ||||
| MYXLIB_INLINE Paths::Paths() = default; | ||||
|  | ||||
|  | ||||
| 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/rtis" ) ) ) | ||||
| 	{ | ||||
| 		setupSystemDirectories( "/usr/local/rtis", | ||||
| 		                        "/usr/local/rtis/etc/" + m_projectName, | ||||
| 		                        "/usr/local/rtis/share/" + m_projectName, | ||||
| 		                        "/usr/local/rtis/lib/" + m_projectName, | ||||
| 		                        "/usr/local/rtis/log/" + m_projectName ); | ||||
|  | ||||
| 		return ( HierarchyType::kUsrLocalRtis ); | ||||
| 	} | ||||
|  | ||||
| 	if ( binaryDir.startsWith( QStringLiteral( "/usr/local" ) ) ) | ||||
| 	{ | ||||
| 		setupSystemDirectories( "/usr/local", | ||||
| 		                        "/usr/local/etc/" + m_projectName, | ||||
| 		                        "/usr/local/share/" + m_projectName, | ||||
| 		                        "/var/lib/" + m_projectName, | ||||
| 		                        "/var/log/" + m_projectName ); | ||||
|  | ||||
| 		return ( HierarchyType::kUsrLocal ); | ||||
| 	} | ||||
|  | ||||
| 	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 ) | ||||
| MYXLIB_INLINE Paths::Paths() : | ||||
| 	m_binDirRegex     ( QStringLiteral( "/s*bin$" ) ), | ||||
| 	m_unityBinDirRegex( QStringLiteral( "/bin/unity$" ) ) | ||||
| { | ||||
| 	QFileInfo procSelfExe( QStringLiteral( "/proc/self/exe" ) ); | ||||
| 	QFileInfo currentExecutable = procSelfExe.canonicalFilePath(); | ||||
| @@ -180,77 +23,324 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config | ||||
| 	m_executableFilePath  = currentExecutable.absoluteFilePath(); | ||||
| 	m_executableDirectory = currentExecutable.absolutePath(); | ||||
|  | ||||
| 	m_projectName = projectDir.isEmpty() ? m_executableName | ||||
| 	                                     : projectDir; | ||||
| 	m_configFileExtension = configFileExtension.isEmpty() ? QStringLiteral( "conf" ) | ||||
| 	                                                      : configFileExtension; | ||||
| 	m_configFileName = m_projectName + "." + m_configFileExtension; | ||||
| 	// Инициализация значениями по умолчанию | ||||
| 	init(); | ||||
| } | ||||
|  | ||||
|  | ||||
| MYXLIB_INLINE bool Paths::init( bool autodetect ) | ||||
| { | ||||
| 	m_autodetect    = autodetect; | ||||
| 	m_homeDirectory = QDir::homePath(); | ||||
| 	m_tempDirectory = QDir::tempPath(); | ||||
|  | ||||
| 	auto configHome = QString::fromLocal8Bit( qgetenv( "XDG_CONFIG_HOME" ) ); | ||||
| 	if ( configHome.isEmpty() ) | ||||
| 	m_configDirectory = QString::fromLocal8Bit( qgetenv( "XDG_CONFIG_HOME" ) ); | ||||
| 	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" ) ); | ||||
| 	if ( dataHome.isEmpty() ) | ||||
| 	m_dataDirectory = QString::fromLocal8Bit( qgetenv( "XDG_DATA_HOME" ) ); | ||||
| 	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_configFilePath = m_systemConfigDirectory + "/" + m_configFileName; | ||||
| 	calculatePaths( m_hierarchyType ); | ||||
|  | ||||
| 	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; | ||||
| 	QDir dir; | ||||
|  | ||||
| 	if ( dir.mkpath( m_userConfigDirectory ) ) { status = false; } | ||||
| 	if ( dir.mkpath( m_userVarDataDirectory ) ) { status = false; } | ||||
| 	if ( dir.mkpath( m_userConstDataDirectory ) ) { status = false; } | ||||
| 	if ( dir.mkpath( m_userLogDirectory ) ) { status = false; } | ||||
| 	if ( dir.mkpath( m_systemConfigDirectory ) ) { status = false; } | ||||
| 	if ( dir.mkpath( m_systemVarDataDirectory ) ) { status = false; } | ||||
| 	if ( dir.mkpath( m_systemConstDataDirectory ) ) { status = false; } | ||||
| 	if ( dir.mkpath( m_systemLogDirectory ) ) { status = false; } | ||||
| 	if ( !dir.mkpath( m_systemConstDataDirectory ) ) { status = false; } | ||||
| 	if ( !dir.mkpath( m_systemLogDirectory ) ) { status = false; } | ||||
| 	if ( !dir.mkpath( m_systemConfigDirectory ) ) { status = false; } | ||||
| 	if ( !dir.mkpath( m_systemVarDataDirectory ) ) { status = false; } | ||||
|  | ||||
| 	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( defaultConfigFile ); | ||||
| 		return( configFileName ); | ||||
| 	} | ||||
|  | ||||
| 	auto fileName = QString::fromLocal8Bit( qgetenv( QCoreApplication::applicationName() | ||||
| 	                                                 .toUpper().toUtf8() + "_CONFIG" ) ); | ||||
| 	if ( QFileInfo( fileName ).isReadable() ) | ||||
| 	{ | ||||
| 		m_configFilePath = 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() ); | ||||
| @@ -269,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 ); | ||||
| } | ||||
|  | ||||
|  | ||||
| MYXLIB_INLINE const QString& Paths::configFileExtension() const | ||||
| { | ||||
| 	return( m_configFileExtension ); | ||||
| 	return( m_systemThemeDirectory ); | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -341,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 | ||||
| { | ||||
| 	return( m_executableName ); | ||||
| @@ -359,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 myx | ||||
|  | ||||
| #endif // MYX_BASE_PATHS_CPP_ | ||||
| #endif // MYX_CORE_PATHS_CPP_ | ||||
|   | ||||
| @@ -1,105 +1,50 @@ | ||||
| /** | ||||
|   * @file paths.hpp | ||||
|   * @brief Стандартные пути к каталогам и файлам | ||||
|   */ | ||||
| /** @file paths.hpp | ||||
|  *  @brief Стандартные пути к каталогам и файлам | ||||
|  */ | ||||
|  | ||||
| #ifndef MYX_FILESYSTEM_PATHS_HPP_ | ||||
| #define MYX_FILESYSTEM_PATHS_HPP_ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <myx/base/config.hpp> | ||||
| #include <myx/core/config.hpp> | ||||
|  | ||||
| #include <QDir> | ||||
| #include <QFileInfo> | ||||
| #include <QRegularExpression> | ||||
| #include <QString> | ||||
|  | ||||
| namespace myx { | ||||
|  | ||||
| namespace filesystem { | ||||
|  | ||||
| /// @brief Класс, предоставляющий методы для получения стандартных путей к каталогам и файлам | ||||
| //* @brief Класс, предоставляющий методы для получения стандартных путей к каталогам и файлам | ||||
| class Paths | ||||
| { | ||||
| 	enum class HierarchyType : intptr_t | ||||
| 	{ | ||||
| 		/// @brief Тип расположения файлов не определён | ||||
| 		//* @brief Тип расположения файлов не определён | ||||
| 		kUndefined = 0x00, | ||||
| 		/// @brief Не определено ни одно из типовых размещений файлов | ||||
| 		/// @details Если исполняемый файл не находится в каталоге bin или не найдены | ||||
| 		///          необходимые сопутствующие каталоги, то предполается, | ||||
| 		///          что все файлы находятся в одном каталоге с исполняемым файлом | ||||
| 		/** @brief Не определено ни одно из типовых размещений файлов | ||||
| 		 *  @details Если исполняемый файл не находится в каталоге bin или не найдены | ||||
| 		 *           необходимые сопутствующие каталоги, то предполается, | ||||
| 		 *           что все файлы находятся в одном каталоге с исполняемым файлом | ||||
| 		 */ | ||||
| 		kFlat = 0x01, | ||||
| 		/// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /opt | ||||
| 		//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /opt | ||||
| 		kOpt = 0x02, | ||||
| 		/// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr | ||||
| 		//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии / usr | ||||
| 		kUsr = 0x03, | ||||
| 		/// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local | ||||
| 		//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local | ||||
| 		kUsrLocal = 0x04, | ||||
| 		/// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local/rtis (используется для работ в проекте Сирена) | ||||
| 		kUsrLocalRtis = 0x05, | ||||
| 		/// @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /home | ||||
| 		//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local/ORG (используется для работ в проекте Сирена) | ||||
| 		kUsrLocalOrg = 0x05, | ||||
| 		//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /home | ||||
| 		kHome = 0x06, | ||||
| 		/// @brief Исполняемый файл и сопутствующие каталоги находятся в каталоге программного проекта | ||||
| 		//* @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: | ||||
| 	Paths( const Paths& ) = delete; | ||||
| 	Paths& operator=( const Paths& ) = delete; | ||||
| @@ -116,116 +61,168 @@ public: | ||||
| 		return( sPaths ); | ||||
| 	} | ||||
|  | ||||
| 	//* @brief Обновление путей с учётом расположения исполняемого файла | ||||
| 	bool init( bool autodetect = true ); | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Обновление путей с учётом расположения исполняемого файла | ||||
| 	 */ | ||||
| 	bool init( const QString& projectDir, const QString& configFileExtension = QStringLiteral("conf") ); | ||||
| 	//* @brief Создание стандартных системных каталогов | ||||
| 	bool makeDefaultSystemDirectories(); | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Создание стандартных каталогов | ||||
| 	 */ | ||||
| 	//* @brief Создание стандартных пользовательских каталогов | ||||
| 	bool makeDefaultUserDirectories(); | ||||
|  | ||||
| 	//* @brief Создание стандартных каталогов | ||||
| 	bool makeDefaultDirectories(); | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Поиск существующего файла настойки. | ||||
| 	 * Поиск выполняется до тех пор пока не будет найден файл в следующем порядке: | ||||
| 	 * 1. Имя файла, указанное в качестве параметра функции | ||||
| 	 * 2. Имя файла, заданное переменной окружения вида PROJECT_NAME_CONFIG | ||||
| 	 * 3. Имя файла, полученное из внутренней переменной класса | ||||
| 	 * Если файл настройки не будет найден, то будет возвращена пустая строка | ||||
| 	/** @brief Поиск существующего файла настойки. | ||||
| 	 *  Поиск выполняется до тех пор пока не будет найден файл в следующем порядке: | ||||
| 	 *  1. Имя файла, указанное в качестве параметра функции | ||||
| 	 *  2. Имя файла, заданное переменной окружения вида EXECUTABLE_NAME_CONFIG | ||||
| 	 *  3. Имя файла, полученное из имени каталога системных настроек и имени исполняемого файла | ||||
| 	 *  Если файл настройки не будет найден, то будет возвращена пустая строка | ||||
| 	 */ | ||||
| 	QString findConfigFile( const QString& defaultConfigFile = QLatin1String("") ); | ||||
| 	QString findConfigFile( const QString& configFileName = QLatin1String( "" ) ); | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к базовому каталогу | ||||
| 	 */ | ||||
| 	const QString& prefixDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Имя исполняемого файла | ||||
| 	 */ | ||||
| 	//* @brief Имя исполняемого файла | ||||
| 	const QString& executableName() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к исполняемому файлу | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к исполняемому файлу | ||||
| 	const QString& executableFilePath() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к каталогу с исполняемым файлом | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к каталогу с исполняемым файлом | ||||
| 	const QString& executableDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Имя файла настройки | ||||
| 	 */ | ||||
| 	const QString& configFileName() const; | ||||
| 	//* @brief Путь к общему пользовательскому каталогу для файлов работы (темы) | ||||
| 	const QString& userThemeDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Расширение у файла настройки | ||||
| 	 */ | ||||
| 	const QString& configFileExtension() const; | ||||
| 	//* @brief Путь к общему системному каталогу для файлов работы (темы) | ||||
| 	const QString& systemThemeDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к файлу настройки | ||||
| 	 */ | ||||
| 	const QString& configFilePath() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к пользовательскому каталогу с файлами настройки | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к пользовательскому каталогу с файлами настройки | ||||
| 	const QString& userConfigDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к системному каталогу с файлами настройки | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к системному каталогу с файлами настройки | ||||
| 	const QString& systemConfigDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к пользовательскому каталогу с изменяемыми файлами | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к пользовательскому каталогу с изменяемыми файлами | ||||
| 	const QString& userVarDataDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к системному каталогу с изменяемыми файлами | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к системному каталогу с изменяемыми файлами | ||||
| 	const QString& systemVarDataDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к пользовательскому каталогу с неизменяемыми файлами | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к пользовательскому каталогу с неизменяемыми файлами | ||||
| 	const QString& userConstDataDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к системному каталогу с неизменяемыми файлами | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к системному каталогу с неизменяемыми файлами | ||||
| 	const QString& systemConstDataDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к пользовательскому каталогу с журналами работы | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к пользовательскому каталогу с журналами работы | ||||
| 	const QString& userLogDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к системному каталогу с журналами работы | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к системному каталогу с журналами работы | ||||
| 	const QString& systemLogDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к каталогу с временными файлами | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к каталогу с временными файлами | ||||
| 	const QString& tempDirectory() const; | ||||
|  | ||||
| 	/** | ||||
| 	 * @brief Полный путь к домашнему каталогу текущего пользователя | ||||
| 	 */ | ||||
| 	//* @brief Полный путь к домашнему каталогу текущего пользователя | ||||
| 	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; | ||||
| 	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 | ||||
|  | ||||
| } // namespace filesystem | ||||
|   | ||||
| @@ -6,6 +6,9 @@ set(TRGT qt) | ||||
| set(TRGT_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 | ||||
| @@ -17,8 +20,11 @@ set(TRGT_moc_private_hpp | ||||
|   ) | ||||
|  | ||||
| set(TRGT_hpp | ||||
|     ${CMAKE_CURRENT_SOURCE_DIR}/backports.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_moc_hpp} ${TRGT_hpp}) | ||||
| @@ -26,39 +32,14 @@ set(TRGT_headers ${TRGT_moc_hpp} ${TRGT_hpp}) | ||||
|  | ||||
| qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_private_hpp} ${TRGT_moc_hpp}) | ||||
|  | ||||
| add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_moc_cpp} | ||||
|                                                            ${TRGT_moc_private_hpp} ${TRGT_headers}) | ||||
| common_target_properties(${TRGT}) | ||||
|  | ||||
| # Создание цели для проверки утилитой clang-tidy | ||||
| add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) | ||||
|  | ||||
| # Создание цели для проверки утилитой clang-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} ${TRGT_moc_private_hpp}) | ||||
| add_library(${TRGT} OBJECT ${TRGT_cpp} ${TRGT_moc_cpp} ${TRGT_moc_private_hpp} ${TRGT_headers}) | ||||
| set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME myx-${TRGT}) | ||||
| myx_cmake_common_target_properties(${TRGT}) | ||||
| myx_cmake_add_static_library(${TRGT}) | ||||
| myx_cmake_add_shared_library(${TRGT}) | ||||
|  | ||||
| target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) | ||||
| target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) | ||||
| target_include_directories(${TRGT} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) | ||||
| cotire(${TRGT}) | ||||
|  | ||||
| install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||||
| if(BUILD_SHARED_LIBS) | ||||
|   install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||||
| endif() | ||||
|  | ||||
| generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES}) | ||||
| install(FILES ${TRGT_headers} COMPONENT base-dev | ||||
| 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}) | ||||
|  | ||||
| # Цель, используемая только для установки заголовочных файлов без компиляции проекта | ||||
| 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_ | ||||
| @@ -1,7 +1,8 @@ | ||||
| #ifndef MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ | ||||
| #define MYX_QT_POSIX_SIGNAL_WATCHER_CPP_ | ||||
|  | ||||
| #include <myx/base/config.hpp> | ||||
| #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> | ||||
| @@ -10,15 +11,15 @@ namespace myx { | ||||
|  | ||||
| namespace qt { | ||||
|  | ||||
| std::array< int, 2 > PosixSignalWatcherPrivate::mSockpair = { 0, 0 }; | ||||
| 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 ) | ||||
| { | ||||
| 	#if MYX_QT_HAS_POSIX_SIGNALS | ||||
| 	// Create socket pair | ||||
|     #ifdef Q_OS_UNIX | ||||
|     // Create socket pair | ||||
| 	if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, mSockpair.data() ) != 0 ) | ||||
| 	{ | ||||
| 		qDebug() << "PosixSignalWatcher: socketpair: " << ::strerror( errno ); | ||||
| @@ -27,8 +28,8 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : | ||||
| 	#endif | ||||
|  | ||||
| 	// Create a notifier for the read end of the pair | ||||
| 	m_notifier.reset( new QSocketNotifier( mSockpair[1], QSocketNotifier::Read ) ); | ||||
|  | ||||
| 	// m_notifier.reset( new QSocketNotifier( mSockpair[1], QSocketNotifier::Read ) ); | ||||
| 	m_notifier = std::make_unique< QSocketNotifier >( mSockpair[1], QSocketNotifier::Read ); | ||||
|  | ||||
| 	// Called when the signal handler has written to the socket pair. | ||||
| 	// Emits the Posix signal as a Qt signal. | ||||
| @@ -60,13 +61,14 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	#if MYX_QT_HAS_POSIX_SIGNALS | ||||
| 	// Register a sigaction which will write to the socket pair | ||||
| 	struct sigaction sigact {}; | ||||
| 	sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; | ||||
|     #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_flags   |= SA_RESTART; | ||||
| 	sigact.sa_restorer = nullptr; | ||||
| 	if ( ::sigaction( signal, &sigact, nullptr ) != 0 ) | ||||
| 	{ | ||||
| 		qDebug() << "PosixSignalWatcher: sigaction: " << ::strerror( errno ); | ||||
| @@ -98,8 +100,6 @@ MYXLIB_INLINE PosixSignalWatcher::PosixSignalWatcher( QObject* parent ) : | ||||
| } | ||||
|  | ||||
|  | ||||
| MYXLIB_INLINE PosixSignalWatcher::~PosixSignalWatcher() = default; | ||||
|  | ||||
| /*! | ||||
|  * Register a signal handler for the given \a signal. | ||||
|  * | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <myx/base/config.hpp> | ||||
| #include <myx/core/config.hpp> | ||||
|  | ||||
| #include <QObject> | ||||
|  | ||||
| @@ -33,14 +33,13 @@ class PosixSignalWatcher : public QObject | ||||
|  | ||||
| public: | ||||
| 	explicit PosixSignalWatcher( QObject* parent = nullptr ); | ||||
| 	~PosixSignalWatcher() override; | ||||
|  | ||||
| 	void watchForSignal( int signal ); | ||||
| 	Q_SIGNAL void posixSignal( int signal ); | ||||
|  | ||||
| private: | ||||
| 	PosixSignalWatcherPrivate* const d_ptr = nullptr; | ||||
| 	Q_DECLARE_PRIVATE( PosixSignalWatcher ) | ||||
| 	Q_DECLARE_PRIVATE( PosixSignalWatcher ) //NOLINT | ||||
| }; // class PosixSignalWatcher | ||||
|  | ||||
| } // namespace qt | ||||
|   | ||||
| @@ -3,27 +3,22 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <myx/base/config.hpp> | ||||
| #include <myx/core/config.hpp> | ||||
| #include <myx/qt/posix_signal_watcher.hpp> | ||||
|  | ||||
| #include <QObject> | ||||
| #include <QMap> | ||||
| #include <QObject> | ||||
| #include <QSocketNotifier> | ||||
| #include <QtDebug> | ||||
|  | ||||
| #include <array> | ||||
| #include <memory> | ||||
|  | ||||
| #ifdef Q_OS_WIN | ||||
| #define MYX_QT_HAS_POSIX_SIGNALS 0 | ||||
| #else | ||||
| #define MYX_QT_HAS_POSIX_SIGNALS 1 | ||||
| #endif | ||||
|  | ||||
| #if MYX_QT_HAS_POSIX_SIGNALS | ||||
| #ifdef Q_OS_UNIX | ||||
| #include <cerrno> | ||||
| #include <csignal> | ||||
| #include <sys/socket.h> | ||||
| #include <unistd.h> | ||||
| #include <cerrno> | ||||
| #endif | ||||
|  | ||||
| namespace myx { | ||||
| @@ -41,7 +36,7 @@ class PosixSignalWatcherPrivate : public QObject | ||||
| 	Q_OBJECT | ||||
|  | ||||
| public: | ||||
| 	PosixSignalWatcherPrivate( PosixSignalWatcher* q ); | ||||
| 	explicit PosixSignalWatcherPrivate( PosixSignalWatcher* q ); | ||||
| 	~PosixSignalWatcherPrivate(); | ||||
|  | ||||
| 	void watchForSignal( int signal ); | ||||
|   | ||||
| @@ -1,7 +1,9 @@ | ||||
| #ifndef 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> | ||||
|  | ||||
| #include <myx/qt/translators.hpp> | ||||
|  | ||||
| #include <QCoreApplication> | ||||
| @@ -49,7 +51,7 @@ MYXLIB_INLINE void append_translators( QTranslatorsList& translators, const QStr | ||||
| 		translator->deleteLater(); | ||||
| 	} | ||||
|  | ||||
| 	for ( auto* i : qAsConst( translators ) ) | ||||
| 	for ( auto* i: qAsConst( translators ) ) | ||||
| 	{ | ||||
| 		qApp->installTranslator( i ); | ||||
| 	} | ||||
|   | ||||
| @@ -3,8 +3,8 @@ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include <myx/base/config.hpp> | ||||
| #include <myx/qt/backports.hpp> | ||||
| #include <myx/backports/qt/common.hpp> | ||||
| #include <myx/core/config.hpp> | ||||
|  | ||||
| #include <QTranslator> | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user