##// END OF EJS Templates
Ajout des règles vera++
perrinel -
r24:31a39fecd50d
parent child
Show More
@@ -0,0 +1,3
1 # On ignore toutes les règles vera++ pour le fichier spimpl
2 Common/spimpl\.h:\d+:.*
3
@@ -0,0 +1,4
1 # On ignore toutes les règles vera++ pour le fichier spimpl
2
3 .*IPSIS_S04_METHOD.*found: Q_DECLARE_LOGGING_CATEGORY.*
4 .*IPSIS_S04_VARIABLE.*found: impl.*
@@ -1,37 +1,40
1 #
1 #
2 # Sciqlop_modules.cmake
2 # Sciqlop_modules.cmake
3 #
3 #
4 # Set ouptut directories
4 # Set ouptut directories
5 #
5 #
6 SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/${CMAKE_BUILD_TYPE})
6 SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/${CMAKE_BUILD_TYPE})
7 SET (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/${CMAKE_BUILD_TYPE})
7 SET (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/${CMAKE_BUILD_TYPE})
8
8
9
9
10 #
10 #
11 # Compile the diffents modules
11 # Compile the diffents modules
12 #
12 #
13 set(sciqlop-core_DIR "${CMAKE_SOURCE_DIR}/core/cmake")
13 set(sciqlop-core_DIR "${CMAKE_SOURCE_DIR}/core/cmake")
14 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-core_DIR}")
14 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-core_DIR}")
15 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/core")
15 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/core")
16
16
17 set(sciqlop-gui_DIR "${CMAKE_SOURCE_DIR}/gui/cmake")
17 set(sciqlop-gui_DIR "${CMAKE_SOURCE_DIR}/gui/cmake")
18 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-gui_DIR}")
18 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-gui_DIR}")
19 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/gui")
19 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/gui")
20
20
21 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/app")
21 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/app")
22
22
23 #
23 #
24 # Code formatting
24 # Code formatting
25 #
25 #
26 # Vera++ exclusion files
27 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/formatting/vera-exclusions/exclusions.txt)
28 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
26 INCLUDE ("cmake/sciqlop_formatting.cmake")
29 INCLUDE ("cmake/sciqlop_formatting.cmake")
27
30
28 #
31 #
29 # Documentation generation
32 # Documentation generation
30 #
33 #
31 INCLUDE ("cmake/sciqlop_doxygen.cmake")
34 INCLUDE ("cmake/sciqlop_doxygen.cmake")
32
35
33 #
36 #
34 # Source code analysis
37 # Source code analysis
35 #
38 #
36 INCLUDE ("cmake/sciqlop_code_analysis.cmake")
39 INCLUDE ("cmake/sciqlop_code_analysis.cmake")
37 INCLUDE ("cmake/sciqlop_code_cppcheck.cmake")
40 INCLUDE ("cmake/sciqlop_code_cppcheck.cmake")
@@ -1,53 +1,55
1 #
1 #
2 # sciqlop_formatting.cmake
2 # sciqlop_formatting.cmake
3 #
3 #
4 # Launch code formatting tools. Can be activated with ENABLE_FORMATTING and
4 # Launch code formatting tools. Can be activated with ENABLE_FORMATTING and
5 # ENABLE_CHECKSTYLE options.
5 # ENABLE_CHECKSTYLE options.
6 #
6 #
7 # The following variables are used (must be set by the cmake file calling this
7 # The following variables are used (must be set by the cmake file calling this
8 # one):
8 # one):
9 # * FORMATTING_INPUT_FILES: list of files to format;
9 # * FORMATTING_INPUT_FILES: list of files to format;
10 # * CHECKSTYLE_INPUT_FILES: list of files to check for style;
10 # * CHECKSTYLE_INPUT_FILES: list of files to check for style;
11 # * CHECKSTYLE_EXCLUSION_FILES: list of vera++ exclusion files.
11 # * CHECKSTYLE_EXCLUSION_FILES: list of vera++ exclusion files.
12 #
12 #
13
13
14 OPTION (ENABLE_FORMATTING "Format the source code while compiling" ON)
14 OPTION (ENABLE_FORMATTING "Format the source code while compiling" ON)
15 OPTION (ENABLE_CHECKSTYLE "Analyse the style of the code while compiling" ON)
15 OPTION (ENABLE_CHECKSTYLE "Analyse the style of the code while compiling" ON)
16
16
17 IF (ENABLE_FORMATTING)
17 IF (ENABLE_FORMATTING)
18 IF (CLANGFORMAT_FOUND)
18 IF (CLANGFORMAT_FOUND)
19 INCLUDE(${CLANGFORMAT_USE_FILE})
19 INCLUDE(${CLANGFORMAT_USE_FILE})
20
20
21 ADD_CLANGFORMAT_TARGETS(${FORMATTING_INPUT_FILES}
21 ADD_CLANGFORMAT_TARGETS(${FORMATTING_INPUT_FILES}
22 ADD_TO_ALL)
22 ADD_TO_ALL)
23 ELSE()
23 ELSE()
24 MESSAGE (STATUS "Source code will not be formatted - clang-format not found")
24 MESSAGE (STATUS "Source code will not be formatted - clang-format not found")
25 ENDIF()
25 ENDIF()
26 ENDIF()
26 ENDIF()
27
27
28 IF (ENABLE_CHECKSTYLE)
28 IF (ENABLE_CHECKSTYLE)
29 IF (VERA++_FOUND)
29 IF (VERA++_FOUND)
30 INCLUDE(${VERA++_USE_FILE})
30 INCLUDE(${VERA++_USE_FILE})
31
31
32 SET(EXCLUSIONS)
32 SET(EXCLUSIONS)
33 FOREACH (e ${CHECKSTYLE_EXCLUSION_FILES})
33 FOREACH (e ${CHECKSTYLE_EXCLUSION_FILES})
34 LIST(APPEND EXCLUSIONS EXCLUSION ${e})
34 LIST(APPEND EXCLUSIONS EXCLUSION ${e})
35 ENDFOREACH()
35 ENDFOREACH()
36
36
37 message("Exclusions de vera++: ${EXCLUSIONS}")
38
37 ADD_VERA_TARGETS(${CHECKSTYLE_INPUT_FILES}
39 ADD_VERA_TARGETS(${CHECKSTYLE_INPUT_FILES}
38 ADD_TO_ALL
40 ADD_TO_ALL
39 PROFILE "sciqlop"
41 PROFILE "sciqlop"
40 ROOT "${CMAKE_SOURCE_DIR}/formatting/vera-root"
42 ROOT "${CMAKE_SOURCE_DIR}/formatting/vera-root"
41 PARAMETER "project-name=${PROJECT_NAME}"
43 PARAMETER "project-name=${PROJECT_NAME}"
42 ${EXCLUSIONS})
44 ${EXCLUSIONS})
43
45
44 ADD_VERA_CHECKSTYLE_TARGET(${CHECKSTYLE_INPUT_FILES}
46 ADD_VERA_CHECKSTYLE_TARGET(${CHECKSTYLE_INPUT_FILES}
45 PROFILE "sciqlop"
47 PROFILE "sciqlop"
46 ROOT "${CMAKE_SOURCE_DIR}/formatting/vera-root"
48 ROOT "${CMAKE_SOURCE_DIR}/formatting/vera-root"
47 PARAMETER "project-name=${PROJECT_NAME}"
49 PARAMETER "project-name=${PROJECT_NAME}"
48 ${EXCLUSIONS})
50 ${EXCLUSIONS})
49
51
50 ELSE()
52 ELSE()
51 MESSAGE (STATUS "Source code will not be checkstyled - vera++ not found")
53 MESSAGE (STATUS "Source code will not be checkstyled - vera++ not found")
52 ENDIF()
54 ENDIF()
53 ENDIF()
55 ENDIF()
@@ -1,128 +1,128
1
1
2 ## core - CMakeLists.txt
2 ## core - CMakeLists.txt
3 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
3 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
4 SET(SQPCORE_LIBRARY_NAME "${LIBRARY_PREFFIX}_core${DEBUG_SUFFIX}")
4 SET(SQPCORE_LIBRARY_NAME "${LIBRARY_PREFFIX}_core${DEBUG_SUFFIX}")
5 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/")
5 SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/")
6 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/")
6 SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/")
7
7
8 # Include core directory
8 # Include core directory
9 include_directories("${INCLUDES_DIR}")
9 include_directories("${INCLUDES_DIR}")
10
10
11 # Set a variable to display a warning in the version files.
11 # Set a variable to display a warning in the version files.
12 SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.")
12 SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.")
13 # Generate the version file from the cmake version variables. The version
13 # Generate the version file from the cmake version variables. The version
14 # variables are defined in the cmake/sciqlop_version.cmake file.
14 # variables are defined in the cmake/sciqlop_version.cmake file.
15 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.h.in"
15 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.h.in"
16 "${INCLUDES_DIR}/Version.h")
16 "${INCLUDES_DIR}/Version.h")
17 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.cpp.in"
17 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/resources/Version.cpp.in"
18 "${SOURCES_DIR}/Version.cpp")
18 "${SOURCES_DIR}/Version.cpp")
19
19
20 #
20 #
21 # Find Qt modules
21 # Find Qt modules
22 #
22 #
23 SCIQLOP_FIND_QT(Core)
23 SCIQLOP_FIND_QT(Core)
24
24
25 #
25 #
26 # Compile the library library
26 # Compile the library library
27 #
27 #
28 FILE (GLOB_RECURSE MODULE_SOURCES
28 FILE (GLOB_RECURSE MODULE_SOURCES
29 ${INCLUDES_DIR}/*.h
29 ${INCLUDES_DIR}/*.h
30 ${SOURCES_DIR}/*.c
30 ${SOURCES_DIR}/*.c
31 ${SOURCES_DIR}/*.cpp
31 ${SOURCES_DIR}/*.cpp
32 ${SOURCES_DIR}/*.h)
32 ${SOURCES_DIR}/*.h)
33
33
34 ADD_LIBRARY(${SQPCORE_LIBRARY_NAME} ${MODULE_SOURCES})
34 ADD_LIBRARY(${SQPCORE_LIBRARY_NAME} ${MODULE_SOURCES})
35 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
35 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
36 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
36 set_property(TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
37 TARGET_LINK_LIBRARIES(${SQPCORE_LIBRARY_NAME})
37 TARGET_LINK_LIBRARIES(${SQPCORE_LIBRARY_NAME})
38 qt5_use_modules(${SQPCORE_LIBRARY_NAME} Core)
38 qt5_use_modules(${SQPCORE_LIBRARY_NAME} Core)
39
39
40 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
40 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
41 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
41 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
42 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
42 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
43 IF(BUILD_SHARED_LIBS)
43 IF(BUILD_SHARED_LIBS)
44 SET_TARGET_PROPERTIES(${SQPCORE_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
44 SET_TARGET_PROPERTIES(${SQPCORE_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
45 ELSE()
45 ELSE()
46 TARGET_COMPILE_DEFINITIONS(${SQPCORE_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
46 TARGET_COMPILE_DEFINITIONS(${SQPCORE_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
47 ENDIF()
47 ENDIF()
48
48
49 # Set the variable to parent scope so that the other projects can copy the
49 # Set the variable to parent scope so that the other projects can copy the
50 # dependent shared libraries
50 # dependent shared libraries
51 SCIQLOP_SET_TO_PARENT_SCOPE(SQPCORE_LIBRARY_NAME)
51 SCIQLOP_SET_TO_PARENT_SCOPE(SQPCORE_LIBRARY_NAME)
52
52
53 # Copy extern shared libraries to the lib folder
53 # Copy extern shared libraries to the lib folder
54 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPCORE_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES})
54 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPCORE_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES})
55
55
56 # Add the files to the list of files to be analyzed
56 # Add the files to the list of files to be analyzed
57 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
57 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
58 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
58 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
59 # Vera++ exclusion files
59 # Vera++ exclusion files
60 #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/path/to/exclusionFiles.tcl)
60 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
61 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
61 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
62
62
63 #
63 #
64 # Compile the tests
64 # Compile the tests
65 #
65 #
66 IF(BUILD_TESTS)
66 IF(BUILD_TESTS)
67 INCLUDE_DIRECTORIES(${SOURCES_DIR})
67 INCLUDE_DIRECTORIES(${SOURCES_DIR})
68 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
68 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
69 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
69 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
70 SET( TEST_LIBRARIES ${SQPCORE_LIBRARY_NAME})
70 SET( TEST_LIBRARIES ${SQPCORE_LIBRARY_NAME})
71
71
72 FOREACH( testFile ${TESTS_SOURCES} )
72 FOREACH( testFile ${TESTS_SOURCES} )
73 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
73 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
74 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
74 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
75
75
76 # Add to the list of sources files all the sources in the same
76 # Add to the list of sources files all the sources in the same
77 # directory that aren't another test
77 # directory that aren't another test
78 FILE (GLOB currentTestSources
78 FILE (GLOB currentTestSources
79 ${testDirectory}/*.c
79 ${testDirectory}/*.c
80 ${testDirectory}/*.cpp
80 ${testDirectory}/*.cpp
81 ${testDirectory}/*.h)
81 ${testDirectory}/*.h)
82 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
82 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
83 LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
83 LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
84
84
85 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
85 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
86 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
86 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
87 qt5_use_modules(${testName} Test)
87 qt5_use_modules(${testName} Test)
88
88
89 ADD_TEST( NAME ${testName} COMMAND ${testName} )
89 ADD_TEST( NAME ${testName} COMMAND ${testName} )
90
90
91 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
91 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
92 ENDFOREACH( testFile )
92 ENDFOREACH( testFile )
93
93
94 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
94 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
95 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
95 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
96 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
96 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
97 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
97 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
98 ENDIF(BUILD_TESTS)
98 ENDIF(BUILD_TESTS)
99
99
100 #
100 #
101 # Set the files that must be formatted by clang-format.
101 # Set the files that must be formatted by clang-format.
102 #
102 #
103 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
103 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
104 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
104 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
105
105
106 #
106 #
107 # Set the directories that doxygen must browse to generate the
107 # Set the directories that doxygen must browse to generate the
108 # documentation.
108 # documentation.
109 #
109 #
110 # Source directories:
110 # Source directories:
111 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
111 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
112 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
112 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
113 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
113 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
114 # Source directories to exclude from the documentation generation
114 # Source directories to exclude from the documentation generation
115 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
115 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
116 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
116 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
117
117
118 #
118 #
119 # Set the directories with the sources to analyze and propagate the
119 # Set the directories with the sources to analyze and propagate the
120 # modification to the parent scope
120 # modification to the parent scope
121 #
121 #
122 # Source directories to analyze:
122 # Source directories to analyze:
123 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
123 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
124 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
124 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
125 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
125 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
126 # Source directories to exclude from the analysis
126 # Source directories to exclude from the analysis
127 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
127 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
128 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
128 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
@@ -1,461 +1,460
1 /*
1 /*
2 ====================================================================
2 ====================================================================
3 A Smart Pointer to IMPLementation (i.e. Smart PIMPL or just SPIMPL).
3 A Smart Pointer to IMPLementation (i.e. Smart PIMPL or just SPIMPL).
4 ====================================================================
4 ====================================================================
5
5
6 Version: 1.1
6 Version: 1.1
7
7
8 Latest version:
8 Latest version:
9 https://github.com/oliora/samples/blob/master/spimpl.h
9 https://github.com/oliora/samples/blob/master/spimpl.h
10 Rationale and description:
10 Rationale and description:
11 http://oliora.github.io/2015/12/29/pimpl-and-rule-of-zero.html
11 http://oliora.github.io/2015/12/29/pimpl-and-rule-of-zero.html
12
12
13 Copyright (c) 2015 Andrey Upadyshev (oliora@gmail.com)
13 Copyright (c) 2015 Andrey Upadyshev (oliora@gmail.com)
14
14
15 Distributed under the Boost Software License, Version 1.0.
15 Distributed under the Boost Software License, Version 1.0.
16 See http://www.boost.org/LICENSE_1_0.txt
16 See http://www.boost.org/LICENSE_1_0.txt
17
17
18 Changes history
18 Changes history
19 ---------------
19 ---------------
20 v1.1:
20 v1.1:
21 - auto_ptr support is disabled by default for C++17 compatibility
21 - auto_ptr support is disabled by default for C++17 compatibility
22 v1.0:
22 v1.0:
23 - Released
23 - Released
24 */
24 */
25
25
26 #ifndef SPIMPL_H_
26 #ifndef SPIMPL_H_
27 #define SPIMPL_H_
27 #define SPIMPL_H_
28
28
29 #include <cassert>
29 #include <cassert>
30 #include <memory>
30 #include <memory>
31 #include <type_traits>
31 #include <type_traits>
32
32
33
34 #if defined _MSC_VER && _MSC_VER < 1900 // MS Visual Studio before VS2015
33 #if defined _MSC_VER && _MSC_VER < 1900 // MS Visual Studio before VS2015
35 #define SPIMPL_NO_CPP11_NOEXCEPT
34 #define SPIMPL_NO_CPP11_NOEXCEPT
36 #define SPIMPL_NO_CPP11_CONSTEXPR
35 #define SPIMPL_NO_CPP11_CONSTEXPR
37 #define SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
36 #define SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
38 #endif
37 #endif
39
38
40 #if !defined SPIMPL_NO_CPP11_NOEXCEPT
39 #if !defined SPIMPL_NO_CPP11_NOEXCEPT
41 #define SPIMPL_NOEXCEPT noexcept
40 #define SPIMPL_NOEXCEPT noexcept
42 #else
41 #else
43 #define SPIMPL_NOEXCEPT
42 #define SPIMPL_NOEXCEPT
44 #endif
43 #endif
45
44
46 #if !defined SPIMPL_NO_CPP11_CONSTEXPR
45 #if !defined SPIMPL_NO_CPP11_CONSTEXPR
47 #define SPIMPL_CONSTEXPR constexpr
46 #define SPIMPL_CONSTEXPR constexpr
48 #else
47 #else
49 #define SPIMPL_CONSTEXPR
48 #define SPIMPL_CONSTEXPR
50 #endif
49 #endif
51
50
52 // define SPIMPL_HAS_AUTO_PTR to enable constructor and assignment operator that accept
51 // define SPIMPL_HAS_AUTO_PTR to enable constructor and assignment operator that accept
53 // std::auto_ptr
52 // std::auto_ptr
54 // TODO: auto detect std::auto_ptr support
53 // TODO: auto detect std::auto_ptr support
55
54
56
55
57 namespace spimpl {
56 namespace spimpl {
58 namespace details {
57 namespace details {
59 template <class T>
58 template <class T>
60 T *default_copy(T *src)
59 T *default_copy(T *src)
61 {
60 {
62 static_assert(sizeof(T) > 0, "default_copy cannot copy incomplete type");
61 static_assert(sizeof(T) > 0, "default_copy cannot copy incomplete type");
63 static_assert(!std::is_void<T>::value, "default_copy cannot copy incomplete type");
62 static_assert(!std::is_void<T>::value, "default_copy cannot copy incomplete type");
64 return new T(*src);
63 return new T(*src);
65 }
64 }
66
65
67 template <class T>
66 template <class T>
68 void default_delete(T *p) SPIMPL_NOEXCEPT
67 void default_delete(T *p) SPIMPL_NOEXCEPT
69 {
68 {
70 static_assert(sizeof(T) > 0, "default_delete cannot delete incomplete type");
69 static_assert(sizeof(T) > 0, "default_delete cannot delete incomplete type");
71 static_assert(!std::is_void<T>::value, "default_delete cannot delete incomplete type");
70 static_assert(!std::is_void<T>::value, "default_delete cannot delete incomplete type");
72 delete p;
71 delete p;
73 }
72 }
74
73
75 template <class T>
74 template <class T>
76 struct default_deleter {
75 struct default_deleter {
77 using type = void (*)(T *);
76 using type = void (*)(T *);
78 };
77 };
79
78
80 template <class T>
79 template <class T>
81 using default_deleter_t = typename default_deleter<T>::type;
80 using default_deleter_t = typename default_deleter<T>::type;
82
81
83 template <class T>
82 template <class T>
84 struct default_copier {
83 struct default_copier {
85 using type = T *(*)(T *);
84 using type = T *(*)(T *);
86 };
85 };
87
86
88 template <class T>
87 template <class T>
89 using default_copier_t = typename default_copier<T>::type;
88 using default_copier_t = typename default_copier<T>::type;
90
89
91 template <class T, class D, class C>
90 template <class T, class D, class C>
92 struct is_default_manageable
91 struct is_default_manageable
93 : public std::integral_constant<bool, std::is_same<D, default_deleter_t<T> >::value
92 : public std::integral_constant<bool, std::is_same<D, default_deleter_t<T> >::value
94 && std::is_same<C, default_copier_t<T> >::value> {
93 && std::is_same<C, default_copier_t<T> >::value> {
95 };
94 };
96 }
95 }
97
96
98
97
99 template <class T, class Deleter = details::default_deleter_t<T>,
98 template <class T, class Deleter = details::default_deleter_t<T>,
100 class Copier = details::default_copier_t<T> >
99 class Copier = details::default_copier_t<T> >
101 class impl_ptr {
100 class impl_ptr {
102 private:
101 private:
103 static_assert(!std::is_array<T>::value,
102 static_assert(!std::is_array<T>::value,
104 "impl_ptr specialization for arrays is not implemented");
103 "impl_ptr specialization for arrays is not implemented");
105 struct dummy_t_ {
104 struct dummy_t_ {
106 int dummy__;
105 int dummy__;
107 };
106 };
108
107
109 public:
108 public:
110 using pointer = T *;
109 using pointer = T *;
111 using element_type = T;
110 using element_type = T;
112 using copier_type = typename std::decay<Copier>::type;
111 using copier_type = typename std::decay<Copier>::type;
113 using deleter_type = typename std::decay<Deleter>::type;
112 using deleter_type = typename std::decay<Deleter>::type;
114 using unique_ptr_type = std::unique_ptr<T, deleter_type>;
113 using unique_ptr_type = std::unique_ptr<T, deleter_type>;
115 using is_default_manageable = details::is_default_manageable<T, deleter_type, copier_type>;
114 using is_default_manageable = details::is_default_manageable<T, deleter_type, copier_type>;
116
115
117 SPIMPL_CONSTEXPR impl_ptr() SPIMPL_NOEXCEPT : ptr_(nullptr, deleter_type{}),
116 SPIMPL_CONSTEXPR impl_ptr() SPIMPL_NOEXCEPT : ptr_(nullptr, deleter_type{}),
118 copier_(copier_type{})
117 copier_(copier_type{})
119 {
118 {
120 }
119 }
121
120
122 SPIMPL_CONSTEXPR impl_ptr(std::nullptr_t) SPIMPL_NOEXCEPT : impl_ptr() {}
121 SPIMPL_CONSTEXPR impl_ptr(std::nullptr_t) SPIMPL_NOEXCEPT : impl_ptr() {}
123
122
124 template <class D, class C>
123 template <class D, class C>
125 impl_ptr(pointer p, D &&d, C &&c,
124 impl_ptr(pointer p, D &&d, C &&c,
126 typename std::enable_if<std::is_convertible<D, deleter_type>::value
125 typename std::enable_if<std::is_convertible<D, deleter_type>::value
127 && std::is_convertible<C, copier_type>::value,
126 && std::is_convertible<C, copier_type>::value,
128 dummy_t_>::type
127 dummy_t_>::type
129 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(p), std::forward<D>(d)),
128 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(p), std::forward<D>(d)),
130 copier_(std::forward<C>(c))
129 copier_(std::forward<C>(c))
131 {
130 {
132 }
131 }
133
132
134 template <class U>
133 template <class U>
135 impl_ptr(U *u, typename std::enable_if<std::is_convertible<U *, pointer>::value
134 impl_ptr(U *u, typename std::enable_if<std::is_convertible<U *, pointer>::value
136 && is_default_manageable::value,
135 && is_default_manageable::value,
137 dummy_t_>::type
136 dummy_t_>::type
138 = dummy_t_()) SPIMPL_NOEXCEPT
137 = dummy_t_()) SPIMPL_NOEXCEPT
139 : impl_ptr(u, &details::default_delete<T>, &details::default_copy<T>)
138 : impl_ptr(u, &details::default_delete<T>, &details::default_copy<T>)
140 {
139 {
141 }
140 }
142
141
143 impl_ptr(const impl_ptr &r) : impl_ptr(r.clone()) {}
142 impl_ptr(const impl_ptr &r) : impl_ptr(r.clone()) {}
144
143
145 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
144 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
146 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
145 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
147 #else
146 #else
148 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT : ptr_(std::move(r.ptr_)), copier_(std::move(r.copier_))
147 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT : ptr_(std::move(r.ptr_)), copier_(std::move(r.copier_))
149 {
148 {
150 }
149 }
151 #endif
150 #endif
152
151
153 #ifdef SPIMPL_HAS_AUTO_PTR
152 #ifdef SPIMPL_HAS_AUTO_PTR
154 template <class U>
153 template <class U>
155 impl_ptr(std::auto_ptr<U> &&u, typename std::enable_if<std::is_convertible<U *, pointer>::value
154 impl_ptr(std::auto_ptr<U> &&u, typename std::enable_if<std::is_convertible<U *, pointer>::value
156 && is_default_manageable::value,
155 && is_default_manageable::value,
157 dummy_t_>::type
156 dummy_t_>::type
158 = dummy_t_()) SPIMPL_NOEXCEPT
157 = dummy_t_()) SPIMPL_NOEXCEPT
159 : ptr_(u.release(), &details::default_delete<T>),
158 : ptr_(u.release(), &details::default_delete<T>),
160 copier_(&details::default_copy<T>)
159 copier_(&details::default_copy<T>)
161 {
160 {
162 }
161 }
163 #endif
162 #endif
164
163
165 template <class U>
164 template <class U>
166 impl_ptr(std::unique_ptr<U> &&u,
165 impl_ptr(std::unique_ptr<U> &&u,
167 typename std::enable_if<std::is_convertible<U *, pointer>::value
166 typename std::enable_if<std::is_convertible<U *, pointer>::value
168 && is_default_manageable::value,
167 && is_default_manageable::value,
169 dummy_t_>::type
168 dummy_t_>::type
170 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(u.release(), &details::default_delete<T>),
169 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(u.release(), &details::default_delete<T>),
171 copier_(&details::default_copy<T>)
170 copier_(&details::default_copy<T>)
172 {
171 {
173 }
172 }
174
173
175 template <class U, class D, class C>
174 template <class U, class D, class C>
176 impl_ptr(std::unique_ptr<U, D> &&u, C &&c,
175 impl_ptr(std::unique_ptr<U, D> &&u, C &&c,
177 typename std::enable_if<std::is_convertible<U *, pointer>::value
176 typename std::enable_if<std::is_convertible<U *, pointer>::value
178 && std::is_convertible<D, deleter_type>::value
177 && std::is_convertible<D, deleter_type>::value
179 && std::is_convertible<C, copier_type>::value,
178 && std::is_convertible<C, copier_type>::value,
180 dummy_t_>::type
179 dummy_t_>::type
181 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u)),
180 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u)),
182 copier_(std::forward<C>(c))
181 copier_(std::forward<C>(c))
183 {
182 {
184 }
183 }
185
184
186 template <class U, class D, class C>
185 template <class U, class D, class C>
187 impl_ptr(impl_ptr<U, D, C> &&u,
186 impl_ptr(impl_ptr<U, D, C> &&u,
188 typename std::enable_if<std::is_convertible<U *, pointer>::value
187 typename std::enable_if<std::is_convertible<U *, pointer>::value
189 && std::is_convertible<D, deleter_type>::value
188 && std::is_convertible<D, deleter_type>::value
190 && std::is_convertible<C, copier_type>::value,
189 && std::is_convertible<C, copier_type>::value,
191 dummy_t_>::type
190 dummy_t_>::type
192 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u.ptr_)),
191 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u.ptr_)),
193 copier_(std::move(u.copier_))
192 copier_(std::move(u.copier_))
194 {
193 {
195 }
194 }
196
195
197 impl_ptr &operator=(const impl_ptr &r)
196 impl_ptr &operator=(const impl_ptr &r)
198 {
197 {
199 if (this == &r)
198 if (this == &r)
200 return *this;
199 return *this;
201
200
202 return operator=(r.clone());
201 return operator=(r.clone());
203 }
202 }
204
203
205 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
204 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
206 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
205 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
207 #else
206 #else
208 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT
207 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT
209 {
208 {
210 ptr_ = std::move(r.ptr_);
209 ptr_ = std::move(r.ptr_);
211 copier_ = std::move(r.copier_);
210 copier_ = std::move(r.copier_);
212 return *this;
211 return *this;
213 }
212 }
214 #endif
213 #endif
215
214
216 template <class U, class D, class C>
215 template <class U, class D, class C>
217 typename std::enable_if<std::is_convertible<U *, pointer>::value
216 typename std::enable_if<std::is_convertible<U *, pointer>::value
218 && std::is_convertible<D, deleter_type>::value
217 && std::is_convertible<D, deleter_type>::value
219 && std::is_convertible<C, copier_type>::value,
218 && std::is_convertible<C, copier_type>::value,
220 impl_ptr &>::type
219 impl_ptr &>::type
221 operator=(impl_ptr<U, D, C> &&u) SPIMPL_NOEXCEPT
220 operator=(impl_ptr<U, D, C> &&u) SPIMPL_NOEXCEPT
222 {
221 {
223 ptr_ = std::move(u.ptr_);
222 ptr_ = std::move(u.ptr_);
224 copier_ = std::move(u.copier_);
223 copier_ = std::move(u.copier_);
225 return *this;
224 return *this;
226 }
225 }
227
226
228 template <class U, class D, class C>
227 template <class U, class D, class C>
229 typename std::enable_if<std::is_convertible<U *, pointer>::value
228 typename std::enable_if<std::is_convertible<U *, pointer>::value
230 && std::is_convertible<D, deleter_type>::value
229 && std::is_convertible<D, deleter_type>::value
231 && std::is_convertible<C, copier_type>::value,
230 && std::is_convertible<C, copier_type>::value,
232 impl_ptr &>::type
231 impl_ptr &>::type
233 operator=(const impl_ptr<U, D, C> &u)
232 operator=(const impl_ptr<U, D, C> &u)
234 {
233 {
235 return operator=(u.clone());
234 return operator=(u.clone());
236 }
235 }
237
236
238 //
237 //
239
238
240 #ifdef SPIMPL_HAS_AUTO_PTR
239 #ifdef SPIMPL_HAS_AUTO_PTR
241 template <class U>
240 template <class U>
242 typename std::enable_if<std::is_convertible<U *, pointer>::value
241 typename std::enable_if<std::is_convertible<U *, pointer>::value
243 && is_default_manageable::value,
242 && is_default_manageable::value,
244 impl_ptr &>::type
243 impl_ptr &>::type
245 operator=(std::auto_ptr<U> &&u) SPIMPL_NOEXCEPT
244 operator=(std::auto_ptr<U> &&u) SPIMPL_NOEXCEPT
246 {
245 {
247 return operator=(impl_ptr(std::move(u)));
246 return operator=(impl_ptr(std::move(u)));
248 }
247 }
249 #endif
248 #endif
250
249
251 template <class U>
250 template <class U>
252 typename std::enable_if<std::is_convertible<U *, pointer>::value
251 typename std::enable_if<std::is_convertible<U *, pointer>::value
253 && is_default_manageable::value,
252 && is_default_manageable::value,
254 impl_ptr &>::type
253 impl_ptr &>::type
255 operator=(std::unique_ptr<U> &&u) SPIMPL_NOEXCEPT
254 operator=(std::unique_ptr<U> &&u) SPIMPL_NOEXCEPT
256 {
255 {
257 return operator=(impl_ptr(std::move(u)));
256 return operator=(impl_ptr(std::move(u)));
258 }
257 }
259
258
260 impl_ptr clone() const
259 impl_ptr clone() const
261 {
260 {
262 return impl_ptr(ptr_ ? copier_(ptr_.get()) : nullptr, ptr_.get_deleter(), copier_);
261 return impl_ptr(ptr_ ? copier_(ptr_.get()) : nullptr, ptr_.get_deleter(), copier_);
263 }
262 }
264
263
265 typename std::remove_reference<T>::type &operator*() const { return *ptr_; }
264 typename std::remove_reference<T>::type &operator*() const { return *ptr_; }
266 pointer operator->() const SPIMPL_NOEXCEPT { return get(); }
265 pointer operator->() const SPIMPL_NOEXCEPT { return get(); }
267 pointer get() const SPIMPL_NOEXCEPT { return ptr_.get(); }
266 pointer get() const SPIMPL_NOEXCEPT { return ptr_.get(); }
268
267
269 void swap(impl_ptr &u) SPIMPL_NOEXCEPT
268 void swap(impl_ptr &u) SPIMPL_NOEXCEPT
270 {
269 {
271 using std::swap;
270 using std::swap;
272 ptr_.swap(u.ptr_);
271 ptr_.swap(u.ptr_);
273 swap(copier_, u.copier_);
272 swap(copier_, u.copier_);
274 }
273 }
275
274
276 pointer release() SPIMPL_NOEXCEPT { return ptr_.release(); }
275 pointer release() SPIMPL_NOEXCEPT { return ptr_.release(); }
277
276
278 unique_ptr_type release_unique() SPIMPL_NOEXCEPT { return std::move(ptr_); }
277 unique_ptr_type release_unique() SPIMPL_NOEXCEPT { return std::move(ptr_); }
279
278
280 explicit operator bool() const SPIMPL_NOEXCEPT { return static_cast<bool>(ptr_); }
279 explicit operator bool() const SPIMPL_NOEXCEPT { return static_cast<bool>(ptr_); }
281
280
282 typename std::remove_reference<deleter_type>::type &get_deleter() SPIMPL_NOEXCEPT
281 typename std::remove_reference<deleter_type>::type &get_deleter() SPIMPL_NOEXCEPT
283 {
282 {
284 return ptr_.get_deleter();
283 return ptr_.get_deleter();
285 }
284 }
286 const typename std::remove_reference<deleter_type>::type &get_deleter() const SPIMPL_NOEXCEPT
285 const typename std::remove_reference<deleter_type>::type &get_deleter() const SPIMPL_NOEXCEPT
287 {
286 {
288 return ptr_.get_deleter();
287 return ptr_.get_deleter();
289 }
288 }
290
289
291 typename std::remove_reference<copier_type>::type &get_copier() SPIMPL_NOEXCEPT
290 typename std::remove_reference<copier_type>::type &get_copier() SPIMPL_NOEXCEPT
292 {
291 {
293 return copier_;
292 return copier_;
294 }
293 }
295 const typename std::remove_reference<copier_type>::type &get_copier() const SPIMPL_NOEXCEPT
294 const typename std::remove_reference<copier_type>::type &get_copier() const SPIMPL_NOEXCEPT
296 {
295 {
297 return copier_;
296 return copier_;
298 }
297 }
299
298
300 private:
299 private:
301 unique_ptr_type ptr_;
300 unique_ptr_type ptr_;
302 copier_type copier_;
301 copier_type copier_;
303 };
302 };
304
303
305
304
306 template <class T, class D, class C>
305 template <class T, class D, class C>
307 inline void swap(impl_ptr<T, D, C> &l, impl_ptr<T, D, C> &r) SPIMPL_NOEXCEPT
306 inline void swap(impl_ptr<T, D, C> &l, impl_ptr<T, D, C> &r) SPIMPL_NOEXCEPT
308 {
307 {
309 l.swap(r);
308 l.swap(r);
310 }
309 }
311
310
312
311
313 template <class T1, class D1, class C1, class T2, class D2, class C2>
312 template <class T1, class D1, class C1, class T2, class D2, class C2>
314 inline bool operator==(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
313 inline bool operator==(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
315 {
314 {
316 return l.get() == r.get();
315 return l.get() == r.get();
317 }
316 }
318
317
319 template <class T1, class D1, class C1, class T2, class D2, class C2>
318 template <class T1, class D1, class C1, class T2, class D2, class C2>
320 inline bool operator!=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
319 inline bool operator!=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
321 {
320 {
322 return !(l == r);
321 return !(l == r);
323 }
322 }
324
323
325 template <class T1, class D1, class C1, class T2, class D2, class C2>
324 template <class T1, class D1, class C1, class T2, class D2, class C2>
326 inline bool operator<(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
325 inline bool operator<(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
327 {
326 {
328 using P1 = typename impl_ptr<T1, D1, C1>::pointer;
327 using P1 = typename impl_ptr<T1, D1, C1>::pointer;
329 using P2 = typename impl_ptr<T2, D2, C2>::pointer;
328 using P2 = typename impl_ptr<T2, D2, C2>::pointer;
330 using CT = typename std::common_type<P1, P2>::type;
329 using CT = typename std::common_type<P1, P2>::type;
331 return std::less<CT>()(l.get(), r.get());
330 return std::less<CT>()(l.get(), r.get());
332 }
331 }
333
332
334 template <class T1, class D1, class C1, class T2, class D2, class C2>
333 template <class T1, class D1, class C1, class T2, class D2, class C2>
335 inline bool operator>(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
334 inline bool operator>(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
336 {
335 {
337 return r < l;
336 return r < l;
338 }
337 }
339
338
340 template <class T1, class D1, class C1, class T2, class D2, class C2>
339 template <class T1, class D1, class C1, class T2, class D2, class C2>
341 inline bool operator<=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
340 inline bool operator<=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
342 {
341 {
343 return !(r < l);
342 return !(r < l);
344 }
343 }
345
344
346 template <class T1, class D1, class C1, class T2, class D2, class C2>
345 template <class T1, class D1, class C1, class T2, class D2, class C2>
347 inline bool operator>=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
346 inline bool operator>=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
348 {
347 {
349 return !(l < r);
348 return !(l < r);
350 }
349 }
351
350
352 template <class T, class D, class C>
351 template <class T, class D, class C>
353 inline bool operator==(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
352 inline bool operator==(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
354 {
353 {
355 return !p;
354 return !p;
356 }
355 }
357
356
358 template <class T, class D, class C>
357 template <class T, class D, class C>
359 inline bool operator==(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
358 inline bool operator==(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
360 {
359 {
361 return !p;
360 return !p;
362 }
361 }
363
362
364 template <class T, class D, class C>
363 template <class T, class D, class C>
365 inline bool operator!=(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
364 inline bool operator!=(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
366 {
365 {
367 return static_cast<bool>(p);
366 return static_cast<bool>(p);
368 }
367 }
369
368
370 template <class T, class D, class C>
369 template <class T, class D, class C>
371 inline bool operator!=(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
370 inline bool operator!=(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
372 {
371 {
373 return static_cast<bool>(p);
372 return static_cast<bool>(p);
374 }
373 }
375
374
376 template <class T, class D, class C>
375 template <class T, class D, class C>
377 inline bool operator<(const impl_ptr<T, D, C> &l, std::nullptr_t)
376 inline bool operator<(const impl_ptr<T, D, C> &l, std::nullptr_t)
378 {
377 {
379 using P = typename impl_ptr<T, D, C>::pointer;
378 using P = typename impl_ptr<T, D, C>::pointer;
380 return std::less<P>()(l.get(), nullptr);
379 return std::less<P>()(l.get(), nullptr);
381 }
380 }
382
381
383 template <class T, class D, class C>
382 template <class T, class D, class C>
384 inline bool operator<(std::nullptr_t, const impl_ptr<T, D, C> &p)
383 inline bool operator<(std::nullptr_t, const impl_ptr<T, D, C> &p)
385 {
384 {
386 using P = typename impl_ptr<T, D, C>::pointer;
385 using P = typename impl_ptr<T, D, C>::pointer;
387 return std::less<P>()(nullptr, p.get());
386 return std::less<P>()(nullptr, p.get());
388 }
387 }
389
388
390 template <class T, class D, class C>
389 template <class T, class D, class C>
391 inline bool operator>(const impl_ptr<T, D, C> &p, std::nullptr_t)
390 inline bool operator>(const impl_ptr<T, D, C> &p, std::nullptr_t)
392 {
391 {
393 return nullptr < p;
392 return nullptr < p;
394 }
393 }
395
394
396 template <class T, class D, class C>
395 template <class T, class D, class C>
397 inline bool operator>(std::nullptr_t, const impl_ptr<T, D, C> &p)
396 inline bool operator>(std::nullptr_t, const impl_ptr<T, D, C> &p)
398 {
397 {
399 return p < nullptr;
398 return p < nullptr;
400 }
399 }
401
400
402 template <class T, class D, class C>
401 template <class T, class D, class C>
403 inline bool operator<=(const impl_ptr<T, D, C> &p, std::nullptr_t)
402 inline bool operator<=(const impl_ptr<T, D, C> &p, std::nullptr_t)
404 {
403 {
405 return !(nullptr < p);
404 return !(nullptr < p);
406 }
405 }
407
406
408 template <class T, class D, class C>
407 template <class T, class D, class C>
409 inline bool operator<=(std::nullptr_t, const impl_ptr<T, D, C> &p)
408 inline bool operator<=(std::nullptr_t, const impl_ptr<T, D, C> &p)
410 {
409 {
411 return !(p < nullptr);
410 return !(p < nullptr);
412 }
411 }
413
412
414 template <class T, class D, class C>
413 template <class T, class D, class C>
415 inline bool operator>=(const impl_ptr<T, D, C> &p, std::nullptr_t)
414 inline bool operator>=(const impl_ptr<T, D, C> &p, std::nullptr_t)
416 {
415 {
417 return !(p < nullptr);
416 return !(p < nullptr);
418 }
417 }
419
418
420 template <class T, class D, class C>
419 template <class T, class D, class C>
421 inline bool operator>=(std::nullptr_t, const impl_ptr<T, D, C> &p)
420 inline bool operator>=(std::nullptr_t, const impl_ptr<T, D, C> &p)
422 {
421 {
423 return !(nullptr < p);
422 return !(nullptr < p);
424 }
423 }
425
424
426
425
427 template <class T, class... Args>
426 template <class T, class... Args>
428 inline impl_ptr<T> make_impl(Args &&... args)
427 inline impl_ptr<T> make_impl(Args &&... args)
429 {
428 {
430 return impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>,
429 return impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>,
431 &details::default_copy<T>);
430 &details::default_copy<T>);
432 }
431 }
433
432
434
433
435 // Helpers to manage unique impl, stored in std::unique_ptr
434 // Helpers to manage unique impl, stored in std::unique_ptr
436
435
437 template <class T, class Deleter = void (*)(T *)>
436 template <class T, class Deleter = void (*)(T *)>
438 using unique_impl_ptr = std::unique_ptr<T, Deleter>;
437 using unique_impl_ptr = std::unique_ptr<T, Deleter>;
439
438
440 template <class T, class... Args>
439 template <class T, class... Args>
441 inline unique_impl_ptr<T> make_unique_impl(Args &&... args)
440 inline unique_impl_ptr<T> make_unique_impl(Args &&... args)
442 {
441 {
443 static_assert(!std::is_array<T>::value, "unique_impl_ptr does not support arrays");
442 static_assert(!std::is_array<T>::value, "unique_impl_ptr does not support arrays");
444 return unique_impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>);
443 return unique_impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>);
445 }
444 }
446 }
445 }
447
446
448 namespace std {
447 namespace std {
449 template <class T, class D, class C>
448 template <class T, class D, class C>
450 struct hash<spimpl::impl_ptr<T, D, C> > {
449 struct hash<spimpl::impl_ptr<T, D, C> > {
451 using argument_type = spimpl::impl_ptr<T, D, C>;
450 using argument_type = spimpl::impl_ptr<T, D, C>;
452 using result_type = size_t;
451 using result_type = size_t;
453
452
454 result_type operator()(const argument_type &p) const SPIMPL_NOEXCEPT
453 result_type operator()(const argument_type &p) const SPIMPL_NOEXCEPT
455 {
454 {
456 return hash<typename argument_type::pointer>()(p.get());
455 return hash<typename argument_type::pointer>()(p.get());
457 }
456 }
458 };
457 };
459 }
458 }
460
459
461 #endif // SPIMPL_H_
460 #endif // SPIMPL_H_
@@ -1,33 +1,34
1 #ifndef SCIQLOP_SQPAPPLICATION_H
1 #ifndef SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
3
3
4 #include "SqpApplication.h"
4 #include "SqpApplication.h"
5
5
6 #include <QApplication>
6 #include <QApplication>
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8
8
9 #include <Common/spimpl.h>
9 #include <Common/spimpl.h>
10
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
12
12
13 /**
13 /**
14 * @brief The SqpApplication class aims to make the link between SciQlop
14 * @brief The SqpApplication class aims to make the link between SciQlop
15 * and its plugins. This is the intermediate class that SciQlop have to use
15 * and its plugins. This is the intermediate class that SciQlop have to use
16 * in the way to connect a data source. Please first use load method to intialize
16 * in the way to connect a data source. Please first use load method to intialize
17 * a plugin specified by its metadata name (JSON plugin source) then others specifics
17 * a plugin specified by its metadata name (JSON plugin source) then others specifics
18 * method will ba able to access it.
18 * method will ba able to access it.
19 * You can load a data source driver plugin then create a data source.
19 * You can load a data source driver plugin then create a data source.
20 */
20 */
21
21 class SqpApplication : public QApplication {
22 class SqpApplication : public QApplication {
22 Q_OBJECT
23 Q_OBJECT
23 public:
24 public:
24 explicit SqpApplication(int &argc, char **argv);
25 explicit SqpApplication(int &argc, char **argv);
25 virtual ~SqpApplication();
26 virtual ~SqpApplication();
26 void initialize();
27 void initialize();
27
28
28 private:
29 private:
29 class SqpApplicationPrivate;
30 class SqpApplicationPrivate;
30 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
31 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
31 };
32 };
32
33
33 #endif // SCIQLOP_SQPAPPLICATION_H
34 #endif // SCIQLOP_SQPAPPLICATION_H
@@ -1,46 +1,45
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <DataSource/DataSourceController.h>
3 #include <DataSource/DataSourceController.h>
4 #include <QThread>
4 #include <QThread>
5
5
6 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
6 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
7
7
8 class SqpApplication::SqpApplicationPrivate {
8 class SqpApplication::SqpApplicationPrivate {
9 public:
9 public:
10 SqpApplicationPrivate() {}
10 SqpApplicationPrivate() {}
11 ~SqpApplicationPrivate()
11 virtual ~SqpApplicationPrivate()
12 {
12 {
13 qCInfo(LOG_SqpApplication()) << tr("Desctruction du SqpApplicationPrivate");
13 qCInfo(LOG_SqpApplication()) << tr("Desctruction du SqpApplicationPrivate");
14 ;
15 m_DataSourceControllerThread.quit();
14 m_DataSourceControllerThread.quit();
16 m_DataSourceControllerThread.wait();
15 m_DataSourceControllerThread.wait();
17 }
16 }
18
17
19 std::unique_ptr<DataSourceController> m_DataSourceController;
18 std::unique_ptr<DataSourceController> m_DataSourceController;
20 QThread m_DataSourceControllerThread;
19 QThread m_DataSourceControllerThread;
21 };
20 };
22
21
23
22
24 SqpApplication::SqpApplication(int &argc, char **argv)
23 SqpApplication::SqpApplication(int &argc, char **argv)
25 : QApplication(argc, argv), impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
24 : QApplication(argc, argv), impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
26 {
25 {
27 qCInfo(LOG_SqpApplication()) << tr("Construction du SqpApplication");
26 qCInfo(LOG_SqpApplication()) << tr("Construction du SqpApplication");
28
27
29 impl->m_DataSourceController = std::make_unique<DataSourceController>();
28 impl->m_DataSourceController = std::make_unique<DataSourceController>();
30 impl->m_DataSourceController->moveToThread(&impl->m_DataSourceControllerThread);
29 impl->m_DataSourceController->moveToThread(&impl->m_DataSourceControllerThread);
31
30
32 connect(&impl->m_DataSourceControllerThread, &QThread::started,
31 connect(&impl->m_DataSourceControllerThread, &QThread::started,
33 impl->m_DataSourceController.get(), &DataSourceController::initialize);
32 impl->m_DataSourceController.get(), &DataSourceController::initialize);
34 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
33 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
35 impl->m_DataSourceController.get(), &DataSourceController::finalize);
34 impl->m_DataSourceController.get(), &DataSourceController::finalize);
36
35
37 impl->m_DataSourceControllerThread.start();
36 impl->m_DataSourceControllerThread.start();
38 }
37 }
39
38
40 SqpApplication::~SqpApplication()
39 SqpApplication::~SqpApplication()
41 {
40 {
42 }
41 }
43
42
44 void SqpApplication::initialize()
43 void SqpApplication::initialize()
45 {
44 {
46 }
45 }
General Comments 0
You need to be logged in to leave comments. Login now