##// END OF EJS Templates
Merge branch 'feature/CpackForWindows' into develop
perrinel -
r52:4b12b115f92f merge
parent child
Show More
@@ -1,17 +1,18
1 1 @echo off
2 2 echo Setting up environment for Qt usage...
3 3
4 4 set QT_QMAKE_PATH=C:\Qt\5.8\mingw53_32\bin
5 5 set QT_MINGW_PATH=C:\Qt\Tools\mingw530_32\bin
6 set NSIS_PATH=C:\Appli\NSIS
6 7 set LLVM_PATH=C:\Appli\LLVM\bin
7 8 set CMAKE_PATH=C:\Appli\CMake\bin
8 9 set NINJA_PATH=C:\Appli\Ninja
9 10
10 11 set PERL_SITE_PATH=C:\Perl64\site\bin
11 12 set PERL_PATH=C:\Perl64\bin
12 13 set PYTHON_PATH=C:\Appli\Python\Python36-32
13 14 set SCAN_BUILD_PATH=C:\Dev\CNRS-DEV\cfe\tools\scan-build\bin
14 15
15 16
16 set PATH=%QT_QMAKE_PATH%;%QT_MINGW_PATH%;%PERL_SITE_PATH%;%PERL_PATH%;%PYTHON_PATH%;%SCAN_BUILD_PATH%;%LLVM_PATH%;%CMAKE_PATH%;%NINJA_PATH%;%PATH%
17 set PATH=%QT_QMAKE_PATH%;%QT_MINGW_PATH%;%PERL_SITE_PATH%;%PERL_PATH%;%PYTHON_PATH%;%NSIS_PATH%;%SCAN_BUILD_PATH%;%LLVM_PATH%;%CMAKE_PATH%;%NINJA_PATH%;%PATH%
17 18 cd /D C:\Dev\CNRS-DEV\SciQlopInit
@@ -1,148 +1,149
1 1
2 2 ## sciqlop - CMakeLists.txt
3 3 SET(EXECUTABLE_NAME "sciqlop")
4 SCIQLOP_SET_TO_PARENT_SCOPE(EXECUTABLE_NAME)
4 5 SET(SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/)
5 6 SET(INCLUDE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/include)
6 7 SET(UI_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/src)
7 8 SET(RES_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/resources)
8 9
9 10 #
10 11 # Find Qt modules
11 12 #
12 13 SCIQLOP_FIND_QT(Core Widgets)
13 14
14 15 #
15 16 # Find dependent libraries
16 17 # ========================
17 18 find_package(sciqlop-gui)
18 19
19 20 SET(LIBRARIES ${SCIQLOP-GUI_LIBRARIES})
20 21 SET(EXTERN_SHARED_LIBRARIES)
21 22
22 23 INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR})
23 24
24 25 # Add sqpcore to the list of libraries to use
25 26 list(APPEND LIBRARIES ${SQPCORE_LIBRARY_NAME})
26 27
27 28 # Include core directory
28 29 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../core/include")
29 30
30 31 # Add dependent shared libraries
31 32 list(APPEND SHARED_LIBRARIES ${SQPCORE_SHARED_LIBRARIES})
32 33
33 34 # Retrieve the location of the dynamic library to copy it to the output path
34 35 #get_property(sqpcoreLocation TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY LOCATION)
35 36 list(APPEND SHARED_LIBRARIES_FROM_TARGETS ${sqpcoreLocation})
36 37
37 38 #
38 39 # Compile the application
39 40 #
40 41 FILE (GLOB_RECURSE APPLICATION_SOURCES
41 42 ${SOURCES_DIR}/*.c
42 43 ${SOURCES_DIR}/*.cpp
43 44 ${SOURCES_DIR}/*.h)
44 45
45 46 # Headers files (.h)
46 47 FILE (GLOB_RECURSE PROJECT_HEADERS ${INCLUDE_FOLDER}/*.h)
47 48
48 49 # Ui files
49 50 FILE (GLOB_RECURSE PROJECT_FORMS ${UI_FOLDER}/*.ui)
50 51
51 52 # Resources files
52 53 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RES_FOLDER}/*.qrc)
53 54
54 55 # Retrieve resources files
55 56 FILE (GLOB_RECURSE APPLICATION_RESOURCES ${RES_FOLDER}/*.qrc)
56 57
57 58 QT5_ADD_RESOURCES(RCC_HDRS ${APPLICATION_RESOURCES} )
58 59
59 60 QT5_WRAP_UI(UIS_HDRS
60 61 ${PROJECT_FORMS}
61 62 )
62 63
63 64
64 65 ADD_EXECUTABLE(${EXECUTABLE_NAME} ${APPLICATION_SOURCES} ${RCC_HDRS} ${UIS_HDRS})
65 66 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD 14)
66 67 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
67 68 target_link_libraries(${EXECUTABLE_NAME}
68 69 ${LIBRARIES})
69 70
70 71 # Link with Qt5 modules
71 72 qt5_use_modules(${EXECUTABLE_NAME} Core Widgets)
72 73
73 74
74 75 # Add the files to the list of files to be analyzed
75 76 LIST(APPEND CHECKSTYLE_INPUT_FILES ${APPLICATION_SOURCES})
76 77 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
77 78 # Vera++ exclusion files
78 79 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
79 80 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
80 81
81 82 #
82 83 # Compile the tests
83 84 #
84 85 IF(BUILD_TESTS)
85 86
86 87 INCLUDE_DIRECTORIES(${SOURCES_DIR})
87 88 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
88 89 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
89 90 SET( TEST_LIBRARIES ${LIBRARIES})
90 91
91 92 FOREACH( testFile ${TESTS_SOURCES} )
92 93 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
93 94 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
94 95
95 96 # Add to the list of sources files all the sources in the same
96 97 # directory that aren't another test
97 98 FILE (GLOB currentTestSources
98 99 ${testDirectory}/*.c
99 100 ${testDirectory}/*.cpp
100 101 ${testDirectory}/*.h)
101 102 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
102 103 LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
103 104
104 105 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
105 106 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES})
106 107 qt5_use_modules(${testName} Test)
107 108
108 109 ADD_TEST( NAME ${testName} COMMAND ${testName} )
109 110
110 111 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName})
111 112 ENDFOREACH( testFile )
112 113
113 114 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
114 115 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
115 116 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
116 117
117 118 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
118 119 ENDIF(BUILD_TESTS)
119 120
120 121 #
121 122 # Set the files that must be formatted by clang-format.
122 123 #
123 124 LIST (APPEND FORMATTING_INPUT_FILES ${APPLICATION_SOURCES})
124 125 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
125 126
126 127 #
127 128 # Set the directories that doxygen must browse to generate the
128 129 # documentation.
129 130 #
130 131 # Source directories:
131 132 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
132 133 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
133 134 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
134 135 # Source directories to exclude from the documentation generation
135 136 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
136 137 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
137 138
138 139 #
139 140 # Set the directories with the sources to analyze and propagate the
140 141 # modification to the parent scope
141 142 #
142 143 # Source directories to analyze:
143 144 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
144 145 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
145 146 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
146 147 # Source directories to exclude from the analysis
147 148 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
148 149 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
@@ -1,57 +1,56
1 1 #
2 2 # Sciqlop_modules.cmake
3 3 #
4 4 # Set ouptut directories
5 5 #
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})
6 SET (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist)
7 SET (LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist)
8 8 IF (UNIX)
9 9 SET (CONFIG_OUTPUT_PATH $ENV{HOME}/.config/QtProject)
10 10 ELSEIF(WIN32)
11 SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/${CMAKE_BUILD_TYPE}/app/QtProject)
11 SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/app/QtProject)
12 12 ELSE()
13 SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/${CMAKE_BUILD_TYPE})
13 SET (CONFIG_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist)
14 14 ENDIF()
15 15
16 INCLUDE ("cmake/sciqlop_code_coverage.cmake")
17
18 16 if(BUILD_TESTS)
17 INCLUDE ("cmake/sciqlop_code_coverage.cmake")
19 18 APPEND_COVERAGE_COMPILER_FLAGS()
20 19 endif(BUILD_TESTS)
21 20
22 21 #
23 22 # Compile the diffents modules
24 23 #
25 24 set(sciqlop-core_DIR "${CMAKE_SOURCE_DIR}/core/cmake")
26 25 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-core_DIR}")
27 26 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/core")
28 27
29 28 set(sciqlop-gui_DIR "${CMAKE_SOURCE_DIR}/gui/cmake")
30 29 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${sciqlop-gui_DIR}")
31 30 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/gui")
32 31
33 32 ADD_SUBDIRECTORY("${CMAKE_SOURCE_DIR}/app")
34 33
35 34 # LOGGER
36 35 set(QTLOGGING_INI_FILE "${CMAKE_SOURCE_DIR}/config/QtProject/qtlogging.ini")
37 36 FILE(COPY ${QTLOGGING_INI_FILE} DESTINATION ${CONFIG_OUTPUT_PATH})
38 37
39 38
40 39 #
41 40 # Code formatting
42 41 #
43 42 # Vera++ exclusion files
44 43 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/formatting/vera-exclusions/exclusions.txt)
45 44 #SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
46 45 INCLUDE ("cmake/sciqlop_formatting.cmake")
47 46
48 47 #
49 48 # Documentation generation
50 49 #
51 50 INCLUDE ("cmake/sciqlop_doxygen.cmake")
52 51
53 52 #
54 53 # Source code analysis
55 54 #
56 55 INCLUDE ("cmake/sciqlop_code_analysis.cmake")
57 56 INCLUDE ("cmake/sciqlop_code_cppcheck.cmake")
@@ -0,0 +1,60
1 #
2 # Generate the source package of SciqLop.
3 #
4
5 install(DIRECTORY
6 ${EXECUTABLE_OUTPUT_PATH}
7 DESTINATION "."
8 USE_SOURCE_PERMISSIONS
9 COMPONENT CORE
10 PATTERN "*.a" EXCLUDE
11 )
12
13 set(EXECUTABLEDOTEXTENSION)
14 if(WIN32)
15 set(EXECUTABLEDOTEXTENSION ".exe")
16 endif(WIN32)
17 set (SCIQLOP_EXE_LOCATION ${EXECUTABLE_OUTPUT_PATH}/${EXECUTABLE_NAME}${EXECUTABLEDOTEXTENSION})
18
19 if(WIN32)
20 include ("cmake/sciqlop_package_qt.cmake")
21 endif(WIN32)
22
23
24 SET (CPACK_PACKAGE_VENDOR "CNRS")
25 SET (CPACK_PACKAGE_VERSION_MAJOR "${SCIQLOP_VERSION_MAJOR}")
26 SET (CPACK_PACKAGE_VERSION_MINOR "${SCIQLOP_VERSION_MINOR}")
27 SET (CPACK_PACKAGE_VERSION_PATCH "${SCIQLOP_VERSION_PATCH}${SCIQLOP_VERSION_SUFFIX}")
28 SET (CPACK_PACKAGE_VERSION "${SCIQLOP_VERSION}")
29 SET (CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
30 SET (CPACK_PACKAGE_CONTACT "nicolas.aunai@lpp.polytechnique.fr")
31 SET(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
32 # SET(CPACK_RESOURCE_FILE_WELCOME ${CMAKE_CURRENT_SOURCE_DIR}/WARN.txt)
33 SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
34 # SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME}-${PROJECT_VERSION})
35 SET(FULLBUILD ON)
36
37 SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
38 SET(CPACK_GENERATOR "NSIS")
39 SET(CPACK_MONOLITHIC_INSTALL 1)
40 #SET(CPACK_COMPONENTS_ALL sciqlop qt)
41 SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-Setup")
42 SET(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_NAME})
43
44 set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
45 message("exepath" ${CPACK_PACKAGE_INSTALL_DIRECTORY})
46
47 if (WIN32)
48 SET(CPACK_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
49 SET(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
50 SET(CPACK_NSIS_COMPONENT_INSTALL ON)
51 SET(CPACK_SYSTEM_NAME "MinGW32")
52 SET(CPACK_PACKAGING_INSTALL_PREFIX "")
53 #SET(CPACK_GENERATOR "NSIS")
54 SET(CPACK_NSIS_DISPLAY_NAME ${PROJECT_NAME})
55 SET(CPACK_NSIS_MUI_FINISHPAGE_RUN ${SCIQLOP_EXECUTABLE_NAME})
56 SET(CPACK_NSIS_MUI_ICON ${SCIQLOP_EXECUTABLE_ICON_LOCATION})
57 SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\${SCIQLOP_EXECUTABLE_NAME}.exe")
58 endif (WIN32)
59
60 INCLUDE(CPack)
@@ -1,462 +1,458
1 1 /*
2 2 ====================================================================
3 3 A Smart Pointer to IMPLementation (i.e. Smart PIMPL or just SPIMPL).
4 4 ====================================================================
5 5
6 6 Version: 1.1
7 7
8 8 Latest version:
9 9 https://github.com/oliora/samples/blob/master/spimpl.h
10 10 Rationale and description:
11 11 http://oliora.github.io/2015/12/29/pimpl-and-rule-of-zero.html
12 12
13 13 Copyright (c) 2015 Andrey Upadyshev (oliora@gmail.com)
14 14
15 15 Distributed under the Boost Software License, Version 1.0.
16 16 See http://www.boost.org/LICENSE_1_0.txt
17 17
18 18 Changes history
19 19 ---------------
20 20 v1.1:
21 21 - auto_ptr support is disabled by default for C++17 compatibility
22 22 v1.0:
23 23 - Released
24 24 */
25 25
26 26 #ifndef SPIMPL_H_
27 27 #define SPIMPL_H_
28 28
29 29 #include <cassert>
30 30 #include <memory>
31 31 #include <type_traits>
32 32
33 33 #if defined _MSC_VER && _MSC_VER < 1900 // MS Visual Studio before VS2015
34 34 #define SPIMPL_NO_CPP11_NOEXCEPT
35 35 #define SPIMPL_NO_CPP11_CONSTEXPR
36 36 #define SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
37 37 #endif
38 38
39 39 #if !defined SPIMPL_NO_CPP11_NOEXCEPT
40 40 #define SPIMPL_NOEXCEPT noexcept
41 41 #else
42 42 #define SPIMPL_NOEXCEPT
43 43 #endif
44 44
45 45 #if !defined SPIMPL_NO_CPP11_CONSTEXPR
46 46 #define SPIMPL_CONSTEXPR constexpr
47 47 #else
48 48 #define SPIMPL_CONSTEXPR
49 49 #endif
50 50
51 51 // define SPIMPL_HAS_AUTO_PTR to enable constructor and assignment operator that accept
52 52 // std::auto_ptr
53 53 // TODO: auto detect std::auto_ptr support
54 54
55 55
56 56 namespace spimpl {
57 57 namespace details {
58 58 template <class T>
59 59 T *default_copy(T *src)
60 60 {
61 61 static_assert(sizeof(T) > 0, "default_copy cannot copy incomplete type");
62 62 static_assert(!std::is_void<T>::value, "default_copy cannot copy incomplete type");
63 63 return new T(*src);
64 64 }
65 65
66 66 template <class T>
67 67 void default_delete(T *p) SPIMPL_NOEXCEPT
68 68 {
69 69 static_assert(sizeof(T) > 0, "default_delete cannot delete incomplete type");
70 70 static_assert(!std::is_void<T>::value, "default_delete cannot delete incomplete type");
71 71 delete p;
72 72 }
73 73
74 74 template <class T>
75 75 struct default_deleter {
76 76 using type = void (*)(T *);
77 77 };
78 78
79 79 template <class T>
80 80 using default_deleter_t = typename default_deleter<T>::type;
81 81
82 82 template <class T>
83 83 struct default_copier {
84 84 using type = T *(*)(T *);
85 85 };
86 86
87 87 template <class T>
88 88 using default_copier_t = typename default_copier<T>::type;
89 89
90 90 template <class T, class D, class C>
91 91 struct is_default_manageable
92 : public std::integral_constant<bool,
93 std::is_same<D, default_deleter_t<T> >::value
94 && std::is_same<C, default_copier_t<T> >::value> {
92 : public std::integral_constant<bool, std::is_same<D, default_deleter_t<T> >::value
93 && std::is_same<C, default_copier_t<T> >::value> {
95 94 };
96 95 }
97 96
98 97
99 98 template <class T, class Deleter = details::default_deleter_t<T>,
100 99 class Copier = details::default_copier_t<T> >
101 100 class impl_ptr {
102 101 private:
103 102 static_assert(!std::is_array<T>::value,
104 103 "impl_ptr specialization for arrays is not implemented");
105 104 struct dummy_t_ {
106 105 int dummy__;
107 106 };
108 107
109 108 public:
110 109 using pointer = T *;
111 110 using element_type = T;
112 111 using copier_type = typename std::decay<Copier>::type;
113 112 using deleter_type = typename std::decay<Deleter>::type;
114 113 using unique_ptr_type = std::unique_ptr<T, deleter_type>;
115 114 using is_default_manageable = details::is_default_manageable<T, deleter_type, copier_type>;
116 115
117 116 SPIMPL_CONSTEXPR impl_ptr() SPIMPL_NOEXCEPT : ptr_(nullptr, deleter_type{}),
118 117 copier_(copier_type{})
119 118 {
120 119 }
121 120
122 121 SPIMPL_CONSTEXPR impl_ptr(std::nullptr_t) SPIMPL_NOEXCEPT : impl_ptr() {}
123 122
124 123 template <class D, class C>
125 124 impl_ptr(pointer p, D &&d, C &&c,
126 125 typename std::enable_if<std::is_convertible<D, deleter_type>::value
127 126 && std::is_convertible<C, copier_type>::value,
128 127 dummy_t_>::type
129 128 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(p), std::forward<D>(d)),
130 129 copier_(std::forward<C>(c))
131 130 {
132 131 }
133 132
134 133 template <class U>
135 impl_ptr(U *u,
136 typename std::enable_if<std::is_convertible<U *, pointer>::value
137 && is_default_manageable::value,
138 dummy_t_>::type
139 = dummy_t_()) SPIMPL_NOEXCEPT
134 impl_ptr(U *u, typename std::enable_if<std::is_convertible<U *, pointer>::value
135 && is_default_manageable::value,
136 dummy_t_>::type
137 = dummy_t_()) SPIMPL_NOEXCEPT
140 138 : impl_ptr(u, &details::default_delete<T>, &details::default_copy<T>)
141 139 {
142 140 }
143 141
144 142 impl_ptr(const impl_ptr &r) : impl_ptr(r.clone()) {}
145 143
146 144 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
147 145 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
148 146 #else
149 147 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT : ptr_(std::move(r.ptr_)), copier_(std::move(r.copier_))
150 148 {
151 149 }
152 150 #endif
153 151
154 152 #ifdef SPIMPL_HAS_AUTO_PTR
155 153 template <class U>
156 impl_ptr(std::auto_ptr<U> &&u,
157 typename std::enable_if<std::is_convertible<U *, pointer>::value
158 && is_default_manageable::value,
159 dummy_t_>::type
160 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(u.release(), &details::default_delete<T>),
161 copier_(&details::default_copy<T>)
154 impl_ptr(std::auto_ptr<U> &&u, typename std::enable_if<std::is_convertible<U *, pointer>::value
155 && is_default_manageable::value,
156 dummy_t_>::type
157 = dummy_t_()) SPIMPL_NOEXCEPT
158 : ptr_(u.release(), &details::default_delete<T>),
159 copier_(&details::default_copy<T>)
162 160 {
163 161 }
164 162 #endif
165 163
166 164 template <class U>
167 165 impl_ptr(std::unique_ptr<U> &&u,
168 166 typename std::enable_if<std::is_convertible<U *, pointer>::value
169 167 && is_default_manageable::value,
170 168 dummy_t_>::type
171 169 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(u.release(), &details::default_delete<T>),
172 170 copier_(&details::default_copy<T>)
173 171 {
174 172 }
175 173
176 174 template <class U, class D, class C>
177 175 impl_ptr(std::unique_ptr<U, D> &&u, C &&c,
178 176 typename std::enable_if<std::is_convertible<U *, pointer>::value
179 177 && std::is_convertible<D, deleter_type>::value
180 178 && std::is_convertible<C, copier_type>::value,
181 179 dummy_t_>::type
182 180 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u)),
183 181 copier_(std::forward<C>(c))
184 182 {
185 183 }
186 184
187 185 template <class U, class D, class C>
188 186 impl_ptr(impl_ptr<U, D, C> &&u,
189 187 typename std::enable_if<std::is_convertible<U *, pointer>::value
190 188 && std::is_convertible<D, deleter_type>::value
191 189 && std::is_convertible<C, copier_type>::value,
192 190 dummy_t_>::type
193 191 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u.ptr_)),
194 192 copier_(std::move(u.copier_))
195 193 {
196 194 }
197 195
198 196 impl_ptr &operator=(const impl_ptr &r)
199 197 {
200 198 if (this == &r)
201 199 return *this;
202 200
203 201 return operator=(r.clone());
204 202 }
205 203
206 204 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
207 205 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
208 206 #else
209 207 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT
210 208 {
211 209 ptr_ = std::move(r.ptr_);
212 210 copier_ = std::move(r.copier_);
213 211 return *this;
214 212 }
215 213 #endif
216 214
217 215 template <class U, class D, class C>
218 216 typename std::enable_if<std::is_convertible<U *, pointer>::value
219 217 && std::is_convertible<D, deleter_type>::value
220 218 && std::is_convertible<C, copier_type>::value,
221 219 impl_ptr &>::type
222 220 operator=(impl_ptr<U, D, C> &&u) SPIMPL_NOEXCEPT
223 221 {
224 222 ptr_ = std::move(u.ptr_);
225 223 copier_ = std::move(u.copier_);
226 224 return *this;
227 225 }
228 226
229 227 template <class U, class D, class C>
230 228 typename std::enable_if<std::is_convertible<U *, pointer>::value
231 229 && std::is_convertible<D, deleter_type>::value
232 230 && std::is_convertible<C, copier_type>::value,
233 231 impl_ptr &>::type
234 232 operator=(const impl_ptr<U, D, C> &u)
235 233 {
236 234 return operator=(u.clone());
237 235 }
238 236
239 237 //
240 238
241 239 #ifdef SPIMPL_HAS_AUTO_PTR
242 240 template <class U>
243 typename std::enable_if<std::is_convertible<U *, pointer>::value
244 && is_default_manageable::value,
245 impl_ptr &>::type
241 typename std::enable_if<
242 std::is_convertible<U *, pointer>::value && is_default_manageable::value, impl_ptr &>::type
246 243 operator=(std::auto_ptr<U> &&u) SPIMPL_NOEXCEPT
247 244 {
248 245 return operator=(impl_ptr(std::move(u)));
249 246 }
250 247 #endif
251 248
252 249 template <class U>
253 typename std::enable_if<std::is_convertible<U *, pointer>::value
254 && is_default_manageable::value,
255 impl_ptr &>::type
250 typename std::enable_if<
251 std::is_convertible<U *, pointer>::value && is_default_manageable::value, impl_ptr &>::type
256 252 operator=(std::unique_ptr<U> &&u) SPIMPL_NOEXCEPT
257 253 {
258 254 return operator=(impl_ptr(std::move(u)));
259 255 }
260 256
261 257 impl_ptr clone() const
262 258 {
263 259 return impl_ptr(ptr_ ? copier_(ptr_.get()) : nullptr, ptr_.get_deleter(), copier_);
264 260 }
265 261
266 262 typename std::remove_reference<T>::type &operator*() const { return *ptr_; }
267 263 pointer operator->() const SPIMPL_NOEXCEPT { return get(); }
268 264 pointer get() const SPIMPL_NOEXCEPT { return ptr_.get(); }
269 265
270 266 void swap(impl_ptr &u) SPIMPL_NOEXCEPT
271 267 {
272 268 using std::swap;
273 269 ptr_.swap(u.ptr_);
274 270 swap(copier_, u.copier_);
275 271 }
276 272
277 273 pointer release() SPIMPL_NOEXCEPT { return ptr_.release(); }
278 274
279 275 unique_ptr_type release_unique() SPIMPL_NOEXCEPT { return std::move(ptr_); }
280 276
281 277 explicit operator bool() const SPIMPL_NOEXCEPT { return static_cast<bool>(ptr_); }
282 278
283 279 typename std::remove_reference<deleter_type>::type &get_deleter() SPIMPL_NOEXCEPT
284 280 {
285 281 return ptr_.get_deleter();
286 282 }
287 283 const typename std::remove_reference<deleter_type>::type &get_deleter() const SPIMPL_NOEXCEPT
288 284 {
289 285 return ptr_.get_deleter();
290 286 }
291 287
292 288 typename std::remove_reference<copier_type>::type &get_copier() SPIMPL_NOEXCEPT
293 289 {
294 290 return copier_;
295 291 }
296 292 const typename std::remove_reference<copier_type>::type &get_copier() const SPIMPL_NOEXCEPT
297 293 {
298 294 return copier_;
299 295 }
300 296
301 297 private:
302 298 unique_ptr_type ptr_;
303 299 copier_type copier_;
304 300 };
305 301
306 302
307 303 template <class T, class D, class C>
308 304 inline void swap(impl_ptr<T, D, C> &l, impl_ptr<T, D, C> &r) SPIMPL_NOEXCEPT
309 305 {
310 306 l.swap(r);
311 307 }
312 308
313 309
314 310 template <class T1, class D1, class C1, class T2, class D2, class C2>
315 311 inline bool operator==(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
316 312 {
317 313 return l.get() == r.get();
318 314 }
319 315
320 316 template <class T1, class D1, class C1, class T2, class D2, class C2>
321 317 inline bool operator!=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
322 318 {
323 319 return !(l == r);
324 320 }
325 321
326 322 template <class T1, class D1, class C1, class T2, class D2, class C2>
327 323 inline bool operator<(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
328 324 {
329 325 using P1 = typename impl_ptr<T1, D1, C1>::pointer;
330 326 using P2 = typename impl_ptr<T2, D2, C2>::pointer;
331 327 using CT = typename std::common_type<P1, P2>::type;
332 328 return std::less<CT>()(l.get(), r.get());
333 329 }
334 330
335 331 template <class T1, class D1, class C1, class T2, class D2, class C2>
336 332 inline bool operator>(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
337 333 {
338 334 return r < l;
339 335 }
340 336
341 337 template <class T1, class D1, class C1, class T2, class D2, class C2>
342 338 inline bool operator<=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
343 339 {
344 340 return !(r < l);
345 341 }
346 342
347 343 template <class T1, class D1, class C1, class T2, class D2, class C2>
348 344 inline bool operator>=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
349 345 {
350 346 return !(l < r);
351 347 }
352 348
353 349 template <class T, class D, class C>
354 350 inline bool operator==(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
355 351 {
356 352 return !p;
357 353 }
358 354
359 355 template <class T, class D, class C>
360 356 inline bool operator==(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
361 357 {
362 358 return !p;
363 359 }
364 360
365 361 template <class T, class D, class C>
366 362 inline bool operator!=(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
367 363 {
368 364 return static_cast<bool>(p);
369 365 }
370 366
371 367 template <class T, class D, class C>
372 368 inline bool operator!=(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
373 369 {
374 370 return static_cast<bool>(p);
375 371 }
376 372
377 373 template <class T, class D, class C>
378 374 inline bool operator<(const impl_ptr<T, D, C> &l, std::nullptr_t)
379 375 {
380 376 using P = typename impl_ptr<T, D, C>::pointer;
381 377 return std::less<P>()(l.get(), nullptr);
382 378 }
383 379
384 380 template <class T, class D, class C>
385 381 inline bool operator<(std::nullptr_t, const impl_ptr<T, D, C> &p)
386 382 {
387 383 using P = typename impl_ptr<T, D, C>::pointer;
388 384 return std::less<P>()(nullptr, p.get());
389 385 }
390 386
391 387 template <class T, class D, class C>
392 388 inline bool operator>(const impl_ptr<T, D, C> &p, std::nullptr_t)
393 389 {
394 390 return nullptr < p;
395 391 }
396 392
397 393 template <class T, class D, class C>
398 394 inline bool operator>(std::nullptr_t, const impl_ptr<T, D, C> &p)
399 395 {
400 396 return p < nullptr;
401 397 }
402 398
403 399 template <class T, class D, class C>
404 400 inline bool operator<=(const impl_ptr<T, D, C> &p, std::nullptr_t)
405 401 {
406 402 return !(nullptr < p);
407 403 }
408 404
409 405 template <class T, class D, class C>
410 406 inline bool operator<=(std::nullptr_t, const impl_ptr<T, D, C> &p)
411 407 {
412 408 return !(p < nullptr);
413 409 }
414 410
415 411 template <class T, class D, class C>
416 412 inline bool operator>=(const impl_ptr<T, D, C> &p, std::nullptr_t)
417 413 {
418 414 return !(p < nullptr);
419 415 }
420 416
421 417 template <class T, class D, class C>
422 418 inline bool operator>=(std::nullptr_t, const impl_ptr<T, D, C> &p)
423 419 {
424 420 return !(nullptr < p);
425 421 }
426 422
427 423
428 424 template <class T, class... Args>
429 425 inline impl_ptr<T> make_impl(Args &&... args)
430 426 {
431 427 return impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>,
432 428 &details::default_copy<T>);
433 429 }
434 430
435 431
436 432 // Helpers to manage unique impl, stored in std::unique_ptr
437 433
438 434 template <class T, class Deleter = void (*)(T *)>
439 435 using unique_impl_ptr = std::unique_ptr<T, Deleter>;
440 436
441 437 template <class T, class... Args>
442 438 inline unique_impl_ptr<T> make_unique_impl(Args &&... args)
443 439 {
444 440 static_assert(!std::is_array<T>::value, "unique_impl_ptr does not support arrays");
445 441 return unique_impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>);
446 442 }
447 443 }
448 444
449 445 namespace std {
450 446 template <class T, class D, class C>
451 447 struct hash<spimpl::impl_ptr<T, D, C> > {
452 448 using argument_type = spimpl::impl_ptr<T, D, C>;
453 449 using result_type = size_t;
454 450
455 451 result_type operator()(const argument_type &p) const SPIMPL_NOEXCEPT
456 452 {
457 453 return hash<typename argument_type::pointer>()(p.get());
458 454 }
459 455 };
460 456 }
461 457
462 458 #endif // SPIMPL_H_
General Comments 0
You need to be logged in to leave comments. Login now