##// END OF EJS Templates
Merge branch 'feature/InitDataSource' into develop
Alexandre Leroux -
r40:59a87dfdf45b merge
parent child
Show More
@@ -0,0 +1,3
1 # Ignore false positive relative to sqpApp macro
2 SqpApplication\.h:\d+:.IPSIS_S03.*found: sqpApp
3 SqpApplication\.h:\d+:.IPSIS_S04_VARIABLE.*found: sqpApp
@@ -0,0 +1,52
1 #ifndef SCIQLOP_DATASOURCEITEM_H
2 #define SCIQLOP_DATASOURCEITEM_H
3
4 #include <Common/spimpl.h>
5
6 #include <QVariant>
7 #include <QVector>
8
9 /**
10 * @brief The DataSourceItem class aims to represent a structure element of a data source.
11 * A data source has a tree structure that is made up of a main DataSourceItem object (root)
12 * containing other DataSourceItem objects (children).
13 * For each DataSourceItem can be associated a set of data representing it.
14 */
15 class DataSourceItem {
16 public:
17 explicit DataSourceItem(QVector<QVariant> data = {});
18
19 /**
20 * Adds a child to the item. The item takes ownership of the child.
21 * @param child the child to add
22 */
23 void appendChild(std::unique_ptr<DataSourceItem> child) noexcept;
24
25 /**
26 * Returns the item's child associated to an index
27 * @param childIndex the index to search
28 * @return a pointer to the child if index is valid, nullptr otherwise
29 */
30 DataSourceItem *child(int childIndex) const noexcept;
31
32 int childCount() const noexcept;
33
34 /**
35 * Get the data associated to an index
36 * @param dataIndex the index to search
37 * @return the data found if index is valid, default QVariant otherwise
38 */
39 QVariant data(int dataIndex) const noexcept;
40
41 /**
42 * Get the item's parent
43 * @return a pointer to the parent if it exists, nullptr if the item is a root
44 */
45 DataSourceItem *parentItem() const noexcept;
46
47 private:
48 class DataSourceItemPrivate;
49 spimpl::unique_impl_ptr<DataSourceItemPrivate> impl;
50 };
51
52 #endif // SCIQLOP_DATASOURCEITEMMODEL_H
@@ -0,0 +1,50
1 #include <DataSource/DataSourceItem.h>
2
3 #include <QVector>
4
5 struct DataSourceItem::DataSourceItemPrivate {
6 explicit DataSourceItemPrivate(QVector<QVariant> data)
7 : m_Parent{nullptr}, m_Children{}, m_Data{std::move(data)}
8 {
9 }
10
11 DataSourceItem *m_Parent;
12 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
13 QVector<QVariant> m_Data;
14 };
15
16 DataSourceItem::DataSourceItem(QVector<QVariant> data)
17 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(data)}
18 {
19 }
20
21 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
22 {
23 child->impl->m_Parent = this;
24 impl->m_Children.push_back(std::move(child));
25 }
26
27 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
28 {
29 if (childIndex < 0 || childIndex >= childCount()) {
30 return nullptr;
31 }
32 else {
33 return impl->m_Children.at(childIndex).get();
34 }
35 }
36
37 int DataSourceItem::childCount() const noexcept
38 {
39 return impl->m_Children.size();
40 }
41
42 QVariant DataSourceItem::data(int dataIndex) const noexcept
43 {
44 return impl->m_Data.value(dataIndex);
45 }
46
47 DataSourceItem *DataSourceItem::parentItem() const noexcept
48 {
49 return impl->m_Parent;
50 }
@@ -0,0 +1,49
1 #include <DataSource/DataSourceController.h>
2 #include <DataSource/DataSourceItem.h>
3
4 #include <QObject>
5 #include <QtTest>
6
7 #include <memory>
8
9 class TestDataSourceController : public QObject {
10 Q_OBJECT
11 private slots:
12 void testRegisterDataSource();
13 void testSetDataSourceItem();
14 };
15
16 void TestDataSourceController::testRegisterDataSource()
17 {
18 DataSourceController dataSourceController{};
19
20 auto uid = dataSourceController.registerDataSource(QStringLiteral("Source1"));
21 QVERIFY(!uid.isNull());
22 }
23
24 void TestDataSourceController::testSetDataSourceItem()
25 {
26 DataSourceController dataSourceController{};
27
28 // Spy to test controllers' signals
29 QSignalSpy signalSpy{&dataSourceController, SIGNAL(dataSourceItemSet(const DataSourceItem &))};
30
31 // Create a data source item
32 auto source1Name = QStringLiteral("Source1");
33 auto source1Values = QVector<QVariant>{source1Name};
34 auto source1Item = std::make_unique<DataSourceItem>(std::move(source1Values));
35
36 // Add data source item to the controller and check that a signal has been emitted after setting
37 // data source item in the controller
38 auto source1Uid = dataSourceController.registerDataSource(source1Name);
39 dataSourceController.setDataSourceItem(source1Uid, std::move(source1Item));
40 QCOMPARE(signalSpy.count(), 1);
41
42 // Try to a data source item with an unregistered uid and check that no signal has been emitted
43 auto unregisteredUid = QUuid::createUuid();
44 dataSourceController.setDataSourceItem(unregisteredUid, std::make_unique<DataSourceItem>());
45 QCOMPARE(signalSpy.count(), 1);
46 }
47
48 QTEST_MAIN(TestDataSourceController)
49 #include "TestDataSourceController.moc"
@@ -1,3 +1,5
1 build/
1 build/
2 CMakeLists.txt.user
2 CMakeLists.txt.user
3 /.project
3 /.project
4 core/src/Version.cpp
5 core/include/Version.h
@@ -1,146 +1,146
1
1
2 ## sciqlop - CMakeLists.txt
2 ## sciqlop - CMakeLists.txt
3 SET(EXECUTABLE_NAME "sciqlop")
3 SET(EXECUTABLE_NAME "sciqlop")
4 SET(SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/)
4 SET(SOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/)
5 SET(INCLUDE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/include)
5 SET(INCLUDE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/include)
6 SET(UI_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/src)
6 SET(UI_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/src)
7 SET(RES_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/resources)
7 SET(RES_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/resources)
8
8
9 #
9 #
10 # Find Qt modules
10 # Find Qt modules
11 #
11 #
12 SCIQLOP_FIND_QT(Core Widgets)
12 SCIQLOP_FIND_QT(Core Widgets)
13
13
14 #
14 #
15 # Find dependent libraries
15 # Find dependent libraries
16 # ========================
16 # ========================
17 find_package(sciqlop-gui)
17 find_package(sciqlop-gui)
18
18
19 SET(LIBRARIES ${SCIQLOP-GUI_LIBRARIES})
19 SET(LIBRARIES ${SCIQLOP-GUI_LIBRARIES})
20 SET(EXTERN_SHARED_LIBRARIES)
20 SET(EXTERN_SHARED_LIBRARIES)
21
21
22 INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR})
22 INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR})
23
23
24 # Add sqpcore to the list of libraries to use
24 # Add sqpcore to the list of libraries to use
25 list(APPEND LIBRARIES ${SQPCORE_LIBRARY_NAME})
25 list(APPEND LIBRARIES ${SQPCORE_LIBRARY_NAME})
26
26
27 # Include core directory
27 # Include core directory
28 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../core/include")
28 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../core/include")
29
29
30 # Add dependent shared libraries
30 # Add dependent shared libraries
31 list(APPEND SHARED_LIBRARIES ${SQPCORE_SHARED_LIBRARIES})
31 list(APPEND SHARED_LIBRARIES ${SQPCORE_SHARED_LIBRARIES})
32
32
33 # Retrieve the location of the dynamic library to copy it to the output path
33 # Retrieve the location of the dynamic library to copy it to the output path
34 #get_property(sqpcoreLocation TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY LOCATION)
34 #get_property(sqpcoreLocation TARGET ${SQPCORE_LIBRARY_NAME} PROPERTY LOCATION)
35 list(APPEND SHARED_LIBRARIES_FROM_TARGETS ${sqpcoreLocation})
35 list(APPEND SHARED_LIBRARIES_FROM_TARGETS ${sqpcoreLocation})
36
36
37 #
37 #
38 # Compile the application
38 # Compile the application
39 #
39 #
40 FILE (GLOB_RECURSE APPLICATION_SOURCES
40 FILE (GLOB_RECURSE APPLICATION_SOURCES
41 ${SOURCES_DIR}/*.c
41 ${SOURCES_DIR}/*.c
42 ${SOURCES_DIR}/*.cpp
42 ${SOURCES_DIR}/*.cpp
43 ${SOURCES_DIR}/*.h)
43 ${SOURCES_DIR}/*.h)
44
44
45 # Headers files (.h)
45 # Headers files (.h)
46 FILE (GLOB_RECURSE PROJECT_HEADERS ${INCLUDE_FOLDER}/*.h)
46 FILE (GLOB_RECURSE PROJECT_HEADERS ${INCLUDE_FOLDER}/*.h)
47
47
48 # Ui files
48 # Ui files
49 FILE (GLOB_RECURSE PROJECT_FORMS ${UI_FOLDER}/*.ui)
49 FILE (GLOB_RECURSE PROJECT_FORMS ${UI_FOLDER}/*.ui)
50
50
51 # Resources files
51 # Resources files
52 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RES_FOLDER}/*.qrc)
52 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RES_FOLDER}/*.qrc)
53
53
54 # Retrieve resources files
54 # Retrieve resources files
55 FILE (GLOB_RECURSE APPLICATION_RESOURCES ${RES_FOLDER}/*.qrc)
55 FILE (GLOB_RECURSE APPLICATION_RESOURCES ${RES_FOLDER}/*.qrc)
56
56
57 QT5_ADD_RESOURCES(RCC_HDRS ${APPLICATION_RESOURCES} )
57 QT5_ADD_RESOURCES(RCC_HDRS ${APPLICATION_RESOURCES} )
58
58
59 QT5_WRAP_UI(UIS_HDRS
59 QT5_WRAP_UI(UIS_HDRS
60 ${PROJECT_FORMS}
60 ${PROJECT_FORMS}
61 )
61 )
62
62
63
63
64 ADD_EXECUTABLE(${EXECUTABLE_NAME} ${APPLICATION_SOURCES} ${RCC_HDRS} ${UIS_HDRS})
64 ADD_EXECUTABLE(${EXECUTABLE_NAME} ${APPLICATION_SOURCES} ${RCC_HDRS} ${UIS_HDRS})
65 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD 14)
65 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD 14)
66 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
66 set_property(TARGET ${EXECUTABLE_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
67 target_link_libraries(${EXECUTABLE_NAME}
67 target_link_libraries(${EXECUTABLE_NAME}
68 ${LIBRARIES})
68 ${LIBRARIES})
69
69
70 # Link with Qt5 modules
70 # Link with Qt5 modules
71 qt5_use_modules(${EXECUTABLE_NAME} Core Widgets)
71 qt5_use_modules(${EXECUTABLE_NAME} Core Widgets)
72
72
73
73
74 # Add the files to the list of files to be analyzed
74 # Add the files to the list of files to be analyzed
75 LIST(APPEND CHECKSTYLE_INPUT_FILES ${APPLICATION_SOURCES})
75 LIST(APPEND CHECKSTYLE_INPUT_FILES ${APPLICATION_SOURCES})
76 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
76 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
77 # Vera++ exclusion files
77 # Vera++ exclusion files
78 #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/path/to/exclusionFiles.tcl)
78 LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt)
79 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
79 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
80
80
81 #
81 #
82 # Compile the tests
82 # Compile the tests
83 #
83 #
84 IF(BUILD_TESTS)
84 IF(BUILD_TESTS)
85 INCLUDE_DIRECTORIES(${SOURCES_DIR})
85 INCLUDE_DIRECTORIES(${SOURCES_DIR})
86 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
86 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
87 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
87 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
88 SET( TEST_LIBRARIES ${LIBRARIES})
88 SET( TEST_LIBRARIES ${LIBRARIES})
89
89
90 FOREACH( testFile ${TESTS_SOURCES} )
90 FOREACH( testFile ${TESTS_SOURCES} )
91 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
91 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
92 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
92 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
93
93
94 # Add to the list of sources files all the sources in the same
94 # Add to the list of sources files all the sources in the same
95 # directory that aren't another test
95 # directory that aren't another test
96 FILE (GLOB currentTestSources
96 FILE (GLOB currentTestSources
97 ${testDirectory}/*.c
97 ${testDirectory}/*.c
98 ${testDirectory}/*.cpp
98 ${testDirectory}/*.cpp
99 ${testDirectory}/*.h)
99 ${testDirectory}/*.h)
100 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
100 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
101 LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
101 LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
102
102
103 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
103 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
104 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
104 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
105 qt5_use_modules(${testName} Test)
105 qt5_use_modules(${testName} Test)
106
106
107 ADD_TEST( NAME ${testName} COMMAND ${testName} )
107 ADD_TEST( NAME ${testName} COMMAND ${testName} )
108
108
109 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName})
109 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName})
110 ENDFOREACH( testFile )
110 ENDFOREACH( testFile )
111
111
112 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
112 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
113 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
113 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
114 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
114 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
115 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
115 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
116 ENDIF(BUILD_TESTS)
116 ENDIF(BUILD_TESTS)
117
117
118 #
118 #
119 # Set the files that must be formatted by clang-format.
119 # Set the files that must be formatted by clang-format.
120 #
120 #
121 LIST (APPEND FORMATTING_INPUT_FILES ${APPLICATION_SOURCES})
121 LIST (APPEND FORMATTING_INPUT_FILES ${APPLICATION_SOURCES})
122 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
122 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
123
123
124 #
124 #
125 # Set the directories that doxygen must browse to generate the
125 # Set the directories that doxygen must browse to generate the
126 # documentation.
126 # documentation.
127 #
127 #
128 # Source directories:
128 # Source directories:
129 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
129 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
130 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
130 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
131 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
131 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
132 # Source directories to exclude from the documentation generation
132 # Source directories to exclude from the documentation generation
133 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
133 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
134 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
134 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
135
135
136 #
136 #
137 # Set the directories with the sources to analyze and propagate the
137 # Set the directories with the sources to analyze and propagate the
138 # modification to the parent scope
138 # modification to the parent scope
139 #
139 #
140 # Source directories to analyze:
140 # Source directories to analyze:
141 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
141 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
142 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
142 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
143 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
143 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
144 # Source directories to exclude from the analysis
144 # Source directories to exclude from the analysis
145 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
145 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
146 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
146 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
@@ -1,39 +1,38
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "mainwindow.h"
22 #include "mainwindow.h"
23 #include <QProcessEnvironment>
23 #include <QProcessEnvironment>
24 #include <QThread>
24 #include <QThread>
25 #include <SqpApplication.h>
25 #include <SqpApplication.h>
26 #include <qglobal.h>
26 #include <qglobal.h>
27
27
28 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
29 {
29 {
30 int ad;
30 SqpApplication a{argc, argv};
31 SqpApplication a(argc, argv);
32 SqpApplication::setOrganizationName("LPP");
31 SqpApplication::setOrganizationName("LPP");
33 SqpApplication::setOrganizationDomain("lpp.fr");
32 SqpApplication::setOrganizationDomain("lpp.fr");
34 SqpApplication::setApplicationName("SciQLop");
33 SqpApplication::setApplicationName("SciQLop");
35 MainWindow w;
34 MainWindow w;
36 w.show();
35 w.show();
37
36
38 return a.exec();
37 return a.exec();
39 }
38 }
@@ -1,128 +1,130
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}/vera-exclusions/exclusions.txt)
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 set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14)
87 set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON)
86 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
88 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
87 qt5_use_modules(${testName} Test)
89 qt5_use_modules(${testName} Test)
88
90
89 ADD_TEST( NAME ${testName} COMMAND ${testName} )
91 ADD_TEST( NAME ${testName} COMMAND ${testName} )
90
92
91 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
93 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
92 ENDFOREACH( testFile )
94 ENDFOREACH( testFile )
93
95
94 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
96 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
95 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
97 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
96 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
98 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
97 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
99 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
98 ENDIF(BUILD_TESTS)
100 ENDIF(BUILD_TESTS)
99
101
100 #
102 #
101 # Set the files that must be formatted by clang-format.
103 # Set the files that must be formatted by clang-format.
102 #
104 #
103 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
105 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
104 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
106 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
105
107
106 #
108 #
107 # Set the directories that doxygen must browse to generate the
109 # Set the directories that doxygen must browse to generate the
108 # documentation.
110 # documentation.
109 #
111 #
110 # Source directories:
112 # Source directories:
111 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
113 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
112 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
114 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
113 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
115 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
114 # Source directories to exclude from the documentation generation
116 # Source directories to exclude from the documentation generation
115 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
117 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
116 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
118 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
117
119
118 #
120 #
119 # Set the directories with the sources to analyze and propagate the
121 # Set the directories with the sources to analyze and propagate the
120 # modification to the parent scope
122 # modification to the parent scope
121 #
123 #
122 # Source directories to analyze:
124 # Source directories to analyze:
123 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
125 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
124 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
126 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
125 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
127 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
126 # Source directories to exclude from the analysis
128 # Source directories to exclude from the analysis
127 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
129 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
128 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
130 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
@@ -1,460 +1,462
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 #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
34 #define SPIMPL_NO_CPP11_NOEXCEPT
34 #define SPIMPL_NO_CPP11_NOEXCEPT
35 #define SPIMPL_NO_CPP11_CONSTEXPR
35 #define SPIMPL_NO_CPP11_CONSTEXPR
36 #define SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
36 #define SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
37 #endif
37 #endif
38
38
39 #if !defined SPIMPL_NO_CPP11_NOEXCEPT
39 #if !defined SPIMPL_NO_CPP11_NOEXCEPT
40 #define SPIMPL_NOEXCEPT noexcept
40 #define SPIMPL_NOEXCEPT noexcept
41 #else
41 #else
42 #define SPIMPL_NOEXCEPT
42 #define SPIMPL_NOEXCEPT
43 #endif
43 #endif
44
44
45 #if !defined SPIMPL_NO_CPP11_CONSTEXPR
45 #if !defined SPIMPL_NO_CPP11_CONSTEXPR
46 #define SPIMPL_CONSTEXPR constexpr
46 #define SPIMPL_CONSTEXPR constexpr
47 #else
47 #else
48 #define SPIMPL_CONSTEXPR
48 #define SPIMPL_CONSTEXPR
49 #endif
49 #endif
50
50
51 // 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
52 // std::auto_ptr
52 // std::auto_ptr
53 // TODO: auto detect std::auto_ptr support
53 // TODO: auto detect std::auto_ptr support
54
54
55
55
56 namespace spimpl {
56 namespace spimpl {
57 namespace details {
57 namespace details {
58 template <class T>
58 template <class T>
59 T *default_copy(T *src)
59 T *default_copy(T *src)
60 {
60 {
61 static_assert(sizeof(T) > 0, "default_copy cannot copy incomplete type");
61 static_assert(sizeof(T) > 0, "default_copy cannot copy incomplete type");
62 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");
63 return new T(*src);
63 return new T(*src);
64 }
64 }
65
65
66 template <class T>
66 template <class T>
67 void default_delete(T *p) SPIMPL_NOEXCEPT
67 void default_delete(T *p) SPIMPL_NOEXCEPT
68 {
68 {
69 static_assert(sizeof(T) > 0, "default_delete cannot delete incomplete type");
69 static_assert(sizeof(T) > 0, "default_delete cannot delete incomplete type");
70 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");
71 delete p;
71 delete p;
72 }
72 }
73
73
74 template <class T>
74 template <class T>
75 struct default_deleter {
75 struct default_deleter {
76 using type = void (*)(T *);
76 using type = void (*)(T *);
77 };
77 };
78
78
79 template <class T>
79 template <class T>
80 using default_deleter_t = typename default_deleter<T>::type;
80 using default_deleter_t = typename default_deleter<T>::type;
81
81
82 template <class T>
82 template <class T>
83 struct default_copier {
83 struct default_copier {
84 using type = T *(*)(T *);
84 using type = T *(*)(T *);
85 };
85 };
86
86
87 template <class T>
87 template <class T>
88 using default_copier_t = typename default_copier<T>::type;
88 using default_copier_t = typename default_copier<T>::type;
89
89
90 template <class T, class D, class C>
90 template <class T, class D, class C>
91 struct is_default_manageable
91 struct is_default_manageable
92 : public std::integral_constant<bool, std::is_same<D, default_deleter_t<T> >::value
92 : public std::integral_constant<bool,
93 && std::is_same<C, default_copier_t<T> >::value> {
93 std::is_same<D, default_deleter_t<T> >::value
94 && std::is_same<C, default_copier_t<T> >::value> {
94 };
95 };
95 }
96 }
96
97
97
98
98 template <class T, class Deleter = details::default_deleter_t<T>,
99 template <class T, class Deleter = details::default_deleter_t<T>,
99 class Copier = details::default_copier_t<T> >
100 class Copier = details::default_copier_t<T> >
100 class impl_ptr {
101 class impl_ptr {
101 private:
102 private:
102 static_assert(!std::is_array<T>::value,
103 static_assert(!std::is_array<T>::value,
103 "impl_ptr specialization for arrays is not implemented");
104 "impl_ptr specialization for arrays is not implemented");
104 struct dummy_t_ {
105 struct dummy_t_ {
105 int dummy__;
106 int dummy__;
106 };
107 };
107
108
108 public:
109 public:
109 using pointer = T *;
110 using pointer = T *;
110 using element_type = T;
111 using element_type = T;
111 using copier_type = typename std::decay<Copier>::type;
112 using copier_type = typename std::decay<Copier>::type;
112 using deleter_type = typename std::decay<Deleter>::type;
113 using deleter_type = typename std::decay<Deleter>::type;
113 using unique_ptr_type = std::unique_ptr<T, deleter_type>;
114 using unique_ptr_type = std::unique_ptr<T, deleter_type>;
114 using is_default_manageable = details::is_default_manageable<T, deleter_type, copier_type>;
115 using is_default_manageable = details::is_default_manageable<T, deleter_type, copier_type>;
115
116
116 SPIMPL_CONSTEXPR impl_ptr() SPIMPL_NOEXCEPT : ptr_(nullptr, deleter_type{}),
117 SPIMPL_CONSTEXPR impl_ptr() SPIMPL_NOEXCEPT : ptr_(nullptr, deleter_type{}),
117 copier_(copier_type{})
118 copier_(copier_type{})
118 {
119 {
119 }
120 }
120
121
121 SPIMPL_CONSTEXPR impl_ptr(std::nullptr_t) SPIMPL_NOEXCEPT : impl_ptr() {}
122 SPIMPL_CONSTEXPR impl_ptr(std::nullptr_t) SPIMPL_NOEXCEPT : impl_ptr() {}
122
123
123 template <class D, class C>
124 template <class D, class C>
124 impl_ptr(pointer p, D &&d, C &&c,
125 impl_ptr(pointer p, D &&d, C &&c,
125 typename std::enable_if<std::is_convertible<D, deleter_type>::value
126 typename std::enable_if<std::is_convertible<D, deleter_type>::value
126 && std::is_convertible<C, copier_type>::value,
127 && std::is_convertible<C, copier_type>::value,
127 dummy_t_>::type
128 dummy_t_>::type
128 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(p), std::forward<D>(d)),
129 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(p), std::forward<D>(d)),
129 copier_(std::forward<C>(c))
130 copier_(std::forward<C>(c))
130 {
131 {
131 }
132 }
132
133
133 template <class U>
134 template <class U>
134 impl_ptr(U *u, typename std::enable_if<std::is_convertible<U *, pointer>::value
135 impl_ptr(U *u,
135 && is_default_manageable::value,
136 typename std::enable_if<std::is_convertible<U *, pointer>::value
136 dummy_t_>::type
137 && is_default_manageable::value,
137 = dummy_t_()) SPIMPL_NOEXCEPT
138 dummy_t_>::type
139 = dummy_t_()) SPIMPL_NOEXCEPT
138 : impl_ptr(u, &details::default_delete<T>, &details::default_copy<T>)
140 : impl_ptr(u, &details::default_delete<T>, &details::default_copy<T>)
139 {
141 {
140 }
142 }
141
143
142 impl_ptr(const impl_ptr &r) : impl_ptr(r.clone()) {}
144 impl_ptr(const impl_ptr &r) : impl_ptr(r.clone()) {}
143
145
144 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
146 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
145 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
147 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
146 #else
148 #else
147 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT : ptr_(std::move(r.ptr_)), copier_(std::move(r.copier_))
149 impl_ptr(impl_ptr &&r) SPIMPL_NOEXCEPT : ptr_(std::move(r.ptr_)), copier_(std::move(r.copier_))
148 {
150 {
149 }
151 }
150 #endif
152 #endif
151
153
152 #ifdef SPIMPL_HAS_AUTO_PTR
154 #ifdef SPIMPL_HAS_AUTO_PTR
153 template <class U>
155 template <class U>
154 impl_ptr(std::auto_ptr<U> &&u, typename std::enable_if<std::is_convertible<U *, pointer>::value
156 impl_ptr(std::auto_ptr<U> &&u,
155 && is_default_manageable::value,
157 typename std::enable_if<std::is_convertible<U *, pointer>::value
156 dummy_t_>::type
158 && is_default_manageable::value,
157 = dummy_t_()) SPIMPL_NOEXCEPT
159 dummy_t_>::type
158 : ptr_(u.release(), &details::default_delete<T>),
160 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(u.release(), &details::default_delete<T>),
159 copier_(&details::default_copy<T>)
161 copier_(&details::default_copy<T>)
160 {
162 {
161 }
163 }
162 #endif
164 #endif
163
165
164 template <class U>
166 template <class U>
165 impl_ptr(std::unique_ptr<U> &&u,
167 impl_ptr(std::unique_ptr<U> &&u,
166 typename std::enable_if<std::is_convertible<U *, pointer>::value
168 typename std::enable_if<std::is_convertible<U *, pointer>::value
167 && is_default_manageable::value,
169 && is_default_manageable::value,
168 dummy_t_>::type
170 dummy_t_>::type
169 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(u.release(), &details::default_delete<T>),
171 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(u.release(), &details::default_delete<T>),
170 copier_(&details::default_copy<T>)
172 copier_(&details::default_copy<T>)
171 {
173 {
172 }
174 }
173
175
174 template <class U, class D, class C>
176 template <class U, class D, class C>
175 impl_ptr(std::unique_ptr<U, D> &&u, C &&c,
177 impl_ptr(std::unique_ptr<U, D> &&u, C &&c,
176 typename std::enable_if<std::is_convertible<U *, pointer>::value
178 typename std::enable_if<std::is_convertible<U *, pointer>::value
177 && std::is_convertible<D, deleter_type>::value
179 && std::is_convertible<D, deleter_type>::value
178 && std::is_convertible<C, copier_type>::value,
180 && std::is_convertible<C, copier_type>::value,
179 dummy_t_>::type
181 dummy_t_>::type
180 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u)),
182 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u)),
181 copier_(std::forward<C>(c))
183 copier_(std::forward<C>(c))
182 {
184 {
183 }
185 }
184
186
185 template <class U, class D, class C>
187 template <class U, class D, class C>
186 impl_ptr(impl_ptr<U, D, C> &&u,
188 impl_ptr(impl_ptr<U, D, C> &&u,
187 typename std::enable_if<std::is_convertible<U *, pointer>::value
189 typename std::enable_if<std::is_convertible<U *, pointer>::value
188 && std::is_convertible<D, deleter_type>::value
190 && std::is_convertible<D, deleter_type>::value
189 && std::is_convertible<C, copier_type>::value,
191 && std::is_convertible<C, copier_type>::value,
190 dummy_t_>::type
192 dummy_t_>::type
191 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u.ptr_)),
193 = dummy_t_()) SPIMPL_NOEXCEPT : ptr_(std::move(u.ptr_)),
192 copier_(std::move(u.copier_))
194 copier_(std::move(u.copier_))
193 {
195 {
194 }
196 }
195
197
196 impl_ptr &operator=(const impl_ptr &r)
198 impl_ptr &operator=(const impl_ptr &r)
197 {
199 {
198 if (this == &r)
200 if (this == &r)
199 return *this;
201 return *this;
200
202
201 return operator=(r.clone());
203 return operator=(r.clone());
202 }
204 }
203
205
204 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
206 #ifndef SPIMPL_NO_CPP11_DEFAULT_MOVE_SPEC_FUNC
205 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
207 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT = default;
206 #else
208 #else
207 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT
209 impl_ptr &operator=(impl_ptr &&r) SPIMPL_NOEXCEPT
208 {
210 {
209 ptr_ = std::move(r.ptr_);
211 ptr_ = std::move(r.ptr_);
210 copier_ = std::move(r.copier_);
212 copier_ = std::move(r.copier_);
211 return *this;
213 return *this;
212 }
214 }
213 #endif
215 #endif
214
216
215 template <class U, class D, class C>
217 template <class U, class D, class C>
216 typename std::enable_if<std::is_convertible<U *, pointer>::value
218 typename std::enable_if<std::is_convertible<U *, pointer>::value
217 && std::is_convertible<D, deleter_type>::value
219 && std::is_convertible<D, deleter_type>::value
218 && std::is_convertible<C, copier_type>::value,
220 && std::is_convertible<C, copier_type>::value,
219 impl_ptr &>::type
221 impl_ptr &>::type
220 operator=(impl_ptr<U, D, C> &&u) SPIMPL_NOEXCEPT
222 operator=(impl_ptr<U, D, C> &&u) SPIMPL_NOEXCEPT
221 {
223 {
222 ptr_ = std::move(u.ptr_);
224 ptr_ = std::move(u.ptr_);
223 copier_ = std::move(u.copier_);
225 copier_ = std::move(u.copier_);
224 return *this;
226 return *this;
225 }
227 }
226
228
227 template <class U, class D, class C>
229 template <class U, class D, class C>
228 typename std::enable_if<std::is_convertible<U *, pointer>::value
230 typename std::enable_if<std::is_convertible<U *, pointer>::value
229 && std::is_convertible<D, deleter_type>::value
231 && std::is_convertible<D, deleter_type>::value
230 && std::is_convertible<C, copier_type>::value,
232 && std::is_convertible<C, copier_type>::value,
231 impl_ptr &>::type
233 impl_ptr &>::type
232 operator=(const impl_ptr<U, D, C> &u)
234 operator=(const impl_ptr<U, D, C> &u)
233 {
235 {
234 return operator=(u.clone());
236 return operator=(u.clone());
235 }
237 }
236
238
237 //
239 //
238
240
239 #ifdef SPIMPL_HAS_AUTO_PTR
241 #ifdef SPIMPL_HAS_AUTO_PTR
240 template <class U>
242 template <class U>
241 typename std::enable_if<std::is_convertible<U *, pointer>::value
243 typename std::enable_if<std::is_convertible<U *, pointer>::value
242 && is_default_manageable::value,
244 && is_default_manageable::value,
243 impl_ptr &>::type
245 impl_ptr &>::type
244 operator=(std::auto_ptr<U> &&u) SPIMPL_NOEXCEPT
246 operator=(std::auto_ptr<U> &&u) SPIMPL_NOEXCEPT
245 {
247 {
246 return operator=(impl_ptr(std::move(u)));
248 return operator=(impl_ptr(std::move(u)));
247 }
249 }
248 #endif
250 #endif
249
251
250 template <class U>
252 template <class U>
251 typename std::enable_if<std::is_convertible<U *, pointer>::value
253 typename std::enable_if<std::is_convertible<U *, pointer>::value
252 && is_default_manageable::value,
254 && is_default_manageable::value,
253 impl_ptr &>::type
255 impl_ptr &>::type
254 operator=(std::unique_ptr<U> &&u) SPIMPL_NOEXCEPT
256 operator=(std::unique_ptr<U> &&u) SPIMPL_NOEXCEPT
255 {
257 {
256 return operator=(impl_ptr(std::move(u)));
258 return operator=(impl_ptr(std::move(u)));
257 }
259 }
258
260
259 impl_ptr clone() const
261 impl_ptr clone() const
260 {
262 {
261 return impl_ptr(ptr_ ? copier_(ptr_.get()) : nullptr, ptr_.get_deleter(), copier_);
263 return impl_ptr(ptr_ ? copier_(ptr_.get()) : nullptr, ptr_.get_deleter(), copier_);
262 }
264 }
263
265
264 typename std::remove_reference<T>::type &operator*() const { return *ptr_; }
266 typename std::remove_reference<T>::type &operator*() const { return *ptr_; }
265 pointer operator->() const SPIMPL_NOEXCEPT { return get(); }
267 pointer operator->() const SPIMPL_NOEXCEPT { return get(); }
266 pointer get() const SPIMPL_NOEXCEPT { return ptr_.get(); }
268 pointer get() const SPIMPL_NOEXCEPT { return ptr_.get(); }
267
269
268 void swap(impl_ptr &u) SPIMPL_NOEXCEPT
270 void swap(impl_ptr &u) SPIMPL_NOEXCEPT
269 {
271 {
270 using std::swap;
272 using std::swap;
271 ptr_.swap(u.ptr_);
273 ptr_.swap(u.ptr_);
272 swap(copier_, u.copier_);
274 swap(copier_, u.copier_);
273 }
275 }
274
276
275 pointer release() SPIMPL_NOEXCEPT { return ptr_.release(); }
277 pointer release() SPIMPL_NOEXCEPT { return ptr_.release(); }
276
278
277 unique_ptr_type release_unique() SPIMPL_NOEXCEPT { return std::move(ptr_); }
279 unique_ptr_type release_unique() SPIMPL_NOEXCEPT { return std::move(ptr_); }
278
280
279 explicit operator bool() const SPIMPL_NOEXCEPT { return static_cast<bool>(ptr_); }
281 explicit operator bool() const SPIMPL_NOEXCEPT { return static_cast<bool>(ptr_); }
280
282
281 typename std::remove_reference<deleter_type>::type &get_deleter() SPIMPL_NOEXCEPT
283 typename std::remove_reference<deleter_type>::type &get_deleter() SPIMPL_NOEXCEPT
282 {
284 {
283 return ptr_.get_deleter();
285 return ptr_.get_deleter();
284 }
286 }
285 const typename std::remove_reference<deleter_type>::type &get_deleter() const SPIMPL_NOEXCEPT
287 const typename std::remove_reference<deleter_type>::type &get_deleter() const SPIMPL_NOEXCEPT
286 {
288 {
287 return ptr_.get_deleter();
289 return ptr_.get_deleter();
288 }
290 }
289
291
290 typename std::remove_reference<copier_type>::type &get_copier() SPIMPL_NOEXCEPT
292 typename std::remove_reference<copier_type>::type &get_copier() SPIMPL_NOEXCEPT
291 {
293 {
292 return copier_;
294 return copier_;
293 }
295 }
294 const typename std::remove_reference<copier_type>::type &get_copier() const SPIMPL_NOEXCEPT
296 const typename std::remove_reference<copier_type>::type &get_copier() const SPIMPL_NOEXCEPT
295 {
297 {
296 return copier_;
298 return copier_;
297 }
299 }
298
300
299 private:
301 private:
300 unique_ptr_type ptr_;
302 unique_ptr_type ptr_;
301 copier_type copier_;
303 copier_type copier_;
302 };
304 };
303
305
304
306
305 template <class T, class D, class C>
307 template <class T, class D, class C>
306 inline void swap(impl_ptr<T, D, C> &l, impl_ptr<T, D, C> &r) SPIMPL_NOEXCEPT
308 inline void swap(impl_ptr<T, D, C> &l, impl_ptr<T, D, C> &r) SPIMPL_NOEXCEPT
307 {
309 {
308 l.swap(r);
310 l.swap(r);
309 }
311 }
310
312
311
313
312 template <class T1, class D1, class C1, class T2, class D2, class C2>
314 template <class T1, class D1, class C1, class T2, class D2, class C2>
313 inline bool operator==(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
315 inline bool operator==(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
314 {
316 {
315 return l.get() == r.get();
317 return l.get() == r.get();
316 }
318 }
317
319
318 template <class T1, class D1, class C1, class T2, class D2, class C2>
320 template <class T1, class D1, class C1, class T2, class D2, class C2>
319 inline bool operator!=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
321 inline bool operator!=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
320 {
322 {
321 return !(l == r);
323 return !(l == r);
322 }
324 }
323
325
324 template <class T1, class D1, class C1, class T2, class D2, class C2>
326 template <class T1, class D1, class C1, class T2, class D2, class C2>
325 inline bool operator<(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
327 inline bool operator<(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
326 {
328 {
327 using P1 = typename impl_ptr<T1, D1, C1>::pointer;
329 using P1 = typename impl_ptr<T1, D1, C1>::pointer;
328 using P2 = typename impl_ptr<T2, D2, C2>::pointer;
330 using P2 = typename impl_ptr<T2, D2, C2>::pointer;
329 using CT = typename std::common_type<P1, P2>::type;
331 using CT = typename std::common_type<P1, P2>::type;
330 return std::less<CT>()(l.get(), r.get());
332 return std::less<CT>()(l.get(), r.get());
331 }
333 }
332
334
333 template <class T1, class D1, class C1, class T2, class D2, class C2>
335 template <class T1, class D1, class C1, class T2, class D2, class C2>
334 inline bool operator>(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
336 inline bool operator>(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
335 {
337 {
336 return r < l;
338 return r < l;
337 }
339 }
338
340
339 template <class T1, class D1, class C1, class T2, class D2, class C2>
341 template <class T1, class D1, class C1, class T2, class D2, class C2>
340 inline bool operator<=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
342 inline bool operator<=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
341 {
343 {
342 return !(r < l);
344 return !(r < l);
343 }
345 }
344
346
345 template <class T1, class D1, class C1, class T2, class D2, class C2>
347 template <class T1, class D1, class C1, class T2, class D2, class C2>
346 inline bool operator>=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
348 inline bool operator>=(const impl_ptr<T1, D1, C1> &l, const impl_ptr<T2, D2, C2> &r)
347 {
349 {
348 return !(l < r);
350 return !(l < r);
349 }
351 }
350
352
351 template <class T, class D, class C>
353 template <class T, class D, class C>
352 inline bool operator==(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
354 inline bool operator==(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
353 {
355 {
354 return !p;
356 return !p;
355 }
357 }
356
358
357 template <class T, class D, class C>
359 template <class T, class D, class C>
358 inline bool operator==(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
360 inline bool operator==(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
359 {
361 {
360 return !p;
362 return !p;
361 }
363 }
362
364
363 template <class T, class D, class C>
365 template <class T, class D, class C>
364 inline bool operator!=(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
366 inline bool operator!=(const impl_ptr<T, D, C> &p, std::nullptr_t) SPIMPL_NOEXCEPT
365 {
367 {
366 return static_cast<bool>(p);
368 return static_cast<bool>(p);
367 }
369 }
368
370
369 template <class T, class D, class C>
371 template <class T, class D, class C>
370 inline bool operator!=(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
372 inline bool operator!=(std::nullptr_t, const impl_ptr<T, D, C> &p) SPIMPL_NOEXCEPT
371 {
373 {
372 return static_cast<bool>(p);
374 return static_cast<bool>(p);
373 }
375 }
374
376
375 template <class T, class D, class C>
377 template <class T, class D, class C>
376 inline bool operator<(const impl_ptr<T, D, C> &l, std::nullptr_t)
378 inline bool operator<(const impl_ptr<T, D, C> &l, std::nullptr_t)
377 {
379 {
378 using P = typename impl_ptr<T, D, C>::pointer;
380 using P = typename impl_ptr<T, D, C>::pointer;
379 return std::less<P>()(l.get(), nullptr);
381 return std::less<P>()(l.get(), nullptr);
380 }
382 }
381
383
382 template <class T, class D, class C>
384 template <class T, class D, class C>
383 inline bool operator<(std::nullptr_t, const impl_ptr<T, D, C> &p)
385 inline bool operator<(std::nullptr_t, const impl_ptr<T, D, C> &p)
384 {
386 {
385 using P = typename impl_ptr<T, D, C>::pointer;
387 using P = typename impl_ptr<T, D, C>::pointer;
386 return std::less<P>()(nullptr, p.get());
388 return std::less<P>()(nullptr, p.get());
387 }
389 }
388
390
389 template <class T, class D, class C>
391 template <class T, class D, class C>
390 inline bool operator>(const impl_ptr<T, D, C> &p, std::nullptr_t)
392 inline bool operator>(const impl_ptr<T, D, C> &p, std::nullptr_t)
391 {
393 {
392 return nullptr < p;
394 return nullptr < p;
393 }
395 }
394
396
395 template <class T, class D, class C>
397 template <class T, class D, class C>
396 inline bool operator>(std::nullptr_t, const impl_ptr<T, D, C> &p)
398 inline bool operator>(std::nullptr_t, const impl_ptr<T, D, C> &p)
397 {
399 {
398 return p < nullptr;
400 return p < nullptr;
399 }
401 }
400
402
401 template <class T, class D, class C>
403 template <class T, class D, class C>
402 inline bool operator<=(const impl_ptr<T, D, C> &p, std::nullptr_t)
404 inline bool operator<=(const impl_ptr<T, D, C> &p, std::nullptr_t)
403 {
405 {
404 return !(nullptr < p);
406 return !(nullptr < p);
405 }
407 }
406
408
407 template <class T, class D, class C>
409 template <class T, class D, class C>
408 inline bool operator<=(std::nullptr_t, const impl_ptr<T, D, C> &p)
410 inline bool operator<=(std::nullptr_t, const impl_ptr<T, D, C> &p)
409 {
411 {
410 return !(p < nullptr);
412 return !(p < nullptr);
411 }
413 }
412
414
413 template <class T, class D, class C>
415 template <class T, class D, class C>
414 inline bool operator>=(const impl_ptr<T, D, C> &p, std::nullptr_t)
416 inline bool operator>=(const impl_ptr<T, D, C> &p, std::nullptr_t)
415 {
417 {
416 return !(p < nullptr);
418 return !(p < nullptr);
417 }
419 }
418
420
419 template <class T, class D, class C>
421 template <class T, class D, class C>
420 inline bool operator>=(std::nullptr_t, const impl_ptr<T, D, C> &p)
422 inline bool operator>=(std::nullptr_t, const impl_ptr<T, D, C> &p)
421 {
423 {
422 return !(nullptr < p);
424 return !(nullptr < p);
423 }
425 }
424
426
425
427
426 template <class T, class... Args>
428 template <class T, class... Args>
427 inline impl_ptr<T> make_impl(Args &&... args)
429 inline impl_ptr<T> make_impl(Args &&... args)
428 {
430 {
429 return impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>,
431 return impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>,
430 &details::default_copy<T>);
432 &details::default_copy<T>);
431 }
433 }
432
434
433
435
434 // Helpers to manage unique impl, stored in std::unique_ptr
436 // Helpers to manage unique impl, stored in std::unique_ptr
435
437
436 template <class T, class Deleter = void (*)(T *)>
438 template <class T, class Deleter = void (*)(T *)>
437 using unique_impl_ptr = std::unique_ptr<T, Deleter>;
439 using unique_impl_ptr = std::unique_ptr<T, Deleter>;
438
440
439 template <class T, class... Args>
441 template <class T, class... Args>
440 inline unique_impl_ptr<T> make_unique_impl(Args &&... args)
442 inline unique_impl_ptr<T> make_unique_impl(Args &&... args)
441 {
443 {
442 static_assert(!std::is_array<T>::value, "unique_impl_ptr does not support arrays");
444 static_assert(!std::is_array<T>::value, "unique_impl_ptr does not support arrays");
443 return unique_impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>);
445 return unique_impl_ptr<T>(new T(std::forward<Args>(args)...), &details::default_delete<T>);
444 }
446 }
445 }
447 }
446
448
447 namespace std {
449 namespace std {
448 template <class T, class D, class C>
450 template <class T, class D, class C>
449 struct hash<spimpl::impl_ptr<T, D, C> > {
451 struct hash<spimpl::impl_ptr<T, D, C> > {
450 using argument_type = spimpl::impl_ptr<T, D, C>;
452 using argument_type = spimpl::impl_ptr<T, D, C>;
451 using result_type = size_t;
453 using result_type = size_t;
452
454
453 result_type operator()(const argument_type &p) const SPIMPL_NOEXCEPT
455 result_type operator()(const argument_type &p) const SPIMPL_NOEXCEPT
454 {
456 {
455 return hash<typename argument_type::pointer>()(p.get());
457 return hash<typename argument_type::pointer>()(p.get());
456 }
458 }
457 };
459 };
458 }
460 }
459
461
460 #endif // SPIMPL_H_
462 #endif // SPIMPL_H_
@@ -1,39 +1,61
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
3
3
4 #include "DataSourceController.h"
5
6 #include <QLoggingCategory>
4 #include <QLoggingCategory>
7 #include <QObject>
5 #include <QObject>
6 #include <QUuid>
8
7
9 #include <Common/spimpl.h>
8 #include <Common/spimpl.h>
10
9
11 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
12
11
12 class DataSourceItem;
13
13 /**
14 /**
14 * @brief The DataSourceController class aims to make the link between SciQlop
15 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
15 * and its plugins. This is the intermediate class that SciQlop have to use
16 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
16 * in the way to connect a data source. Please first use load method to intialize
17 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
17 * a plugin specified by its metadata name (JSON plugin source) then others specifics
18 * source) then others specifics method will be able to access it. You can load a data source driver
18 * method will ba able to access it.
19 * plugin then create a data source.
19 * You can load a data source driver plugin then create a data source.
20 */
20 */
21 class DataSourceController : public QObject {
21 class DataSourceController : public QObject {
22 Q_OBJECT
22 Q_OBJECT
23 public:
23 public:
24 explicit DataSourceController(QObject *parent = 0);
24 explicit DataSourceController(QObject *parent = 0);
25 virtual ~DataSourceController();
25 virtual ~DataSourceController();
26
26
27 /**
28 * Registers a data source. The method delivers a unique id that can be used afterwards to
29 * access to the data source properties (structure, connection parameters, data provider, etc.)
30 * @param dataSourceName the name of the data source
31 * @return the unique id with which the data source has been registered
32 */
33 QUuid registerDataSource(const QString &dataSourceName) noexcept;
34
35 /**
36 * Sets the structure of a data source. The controller takes ownership of the structure.
37 * @param dataSourceUid the unique id with which the data source has been registered into the
38 * controller. If it is invalid, the method has no effect.
39 * @param dataSourceItem the structure of the data source
40 * @sa registerDataSource()
41 */
42 void setDataSourceItem(const QUuid &dataSourceUid,
43 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
44
27 public slots:
45 public slots:
28 /// Manage init/end of the controller
46 /// Manage init/end of the controller
29 void initialize();
47 void initialize();
30 void finalize();
48 void finalize();
31
49
50 signals:
51 /// Signal emitted when a structure has been set for a data source
52 void dataSourceItemSet(const DataSourceItem &dataSourceItem);
53
32 private:
54 private:
33 void waitForFinish();
55 void waitForFinish();
34
56
35 class DataSourceControllerPrivate;
57 class DataSourceControllerPrivate;
36 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
58 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
37 };
59 };
38
60
39 #endif // SCIQLOP_DATASOURCECONTROLLER_H
61 #endif // SCIQLOP_DATASOURCECONTROLLER_H
@@ -1,48 +1,78
1 #include "DataSource/DataSourceController.h"
1 #include <DataSource/DataSourceController.h>
2 #include <DataSource/DataSourceItem.h>
2
3
3 #include <QMutex>
4 #include <QMutex>
4 #include <QThread>
5 #include <QThread>
5
6
6 #include <QDir>
7 #include <QDir>
7 #include <QStandardPaths>
8 #include <QStandardPaths>
8
9
9 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
10 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
10
11
11 class DataSourceController::DataSourceControllerPrivate {
12 class DataSourceController::DataSourceControllerPrivate {
12 public:
13 public:
13 DataSourceControllerPrivate() {}
14
15 QMutex m_WorkingMutex;
14 QMutex m_WorkingMutex;
15 /// Data sources registered
16 QHash<QUuid, QString> m_DataSources;
17 /// Data sources structures
18 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
16 };
19 };
17
20
18 DataSourceController::DataSourceController(QObject *parent)
21 DataSourceController::DataSourceController(QObject *parent)
19 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
22 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
20 {
23 {
21 qCDebug(LOG_DataSourceController()) << tr("Construction du DataSourceController")
24 qCDebug(LOG_DataSourceController())
22 << QThread::currentThread();
25 << tr("DataSourceController construction") << QThread::currentThread();
23 }
26 }
24
27
25 DataSourceController::~DataSourceController()
28 DataSourceController::~DataSourceController()
26 {
29 {
27 qCDebug(LOG_DataSourceController()) << tr("Desctruction du DataSourceController")
30 qCDebug(LOG_DataSourceController())
28 << QThread::currentThread();
31 << tr("DataSourceController destruction") << QThread::currentThread();
29 this->waitForFinish();
32 this->waitForFinish();
30 }
33 }
31
34
35 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
36 {
37 auto dataSourceUid = QUuid::createUuid();
38 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
39
40 return dataSourceUid;
41 }
42
43 void DataSourceController::setDataSourceItem(
44 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
45 {
46 if (impl->m_DataSources.contains(dataSourceUid)) {
47 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
48
49 // Retrieves the data source item to emit the signal with it
50 auto it = impl->m_DataSourceItems.find(dataSourceUid);
51 if (it != impl->m_DataSourceItems.end()) {
52 emit dataSourceItemSet(*it->second);
53 }
54 }
55 else {
56 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
57 "data source has been registered with the uid")
58 .arg(dataSourceUid.toString());
59 }
60 }
61
32 void DataSourceController::initialize()
62 void DataSourceController::initialize()
33 {
63 {
34 qCDebug(LOG_DataSourceController()) << tr("initialize du DataSourceController")
64 qCDebug(LOG_DataSourceController())
35 << QThread::currentThread();
65 << tr("DataSourceController init") << QThread::currentThread();
36 impl->m_WorkingMutex.lock();
66 impl->m_WorkingMutex.lock();
37 qCDebug(LOG_DataSourceController()) << tr("initialize du DataSourceController END");
67 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
38 }
68 }
39
69
40 void DataSourceController::finalize()
70 void DataSourceController::finalize()
41 {
71 {
42 impl->m_WorkingMutex.unlock();
72 impl->m_WorkingMutex.unlock();
43 }
73 }
44
74
45 void DataSourceController::waitForFinish()
75 void DataSourceController::waitForFinish()
46 {
76 {
47 QMutexLocker locker(&impl->m_WorkingMutex);
77 QMutexLocker locker{&impl->m_WorkingMutex};
48 }
78 }
@@ -1,4 +1,8
1 # On ignore toutes les règles vera++ pour le fichier spimpl
1 # On ignore toutes les règles vera++ pour le fichier spimpl
2
2
3 .*IPSIS_S04_METHOD.*found: Q_DECLARE_LOGGING_CATEGORY.*
3 .*IPSIS_S04_METHOD.*found: Q_DECLARE_LOGGING_CATEGORY.*
4 .*IPSIS_S04_VARIABLE.*found: impl.*
4 .*IPSIS_S04_VARIABLE.*found: impl.*
5
6 # Ignore false positive relative to 'noexcept' keyword
7 .*IPSIS_S04_VARIABLE.*found: noexcept
8 .*IPSIS_S06.*found: noexcept
@@ -1,158 +1,160
1
1
2 ## gui - CMakeLists.txt
2 ## gui - CMakeLists.txt
3 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
3 STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX)
4 SET(SQPGUI_LIBRARY_NAME "${LIBRARY_PREFFIX}_gui${DEBUG_SUFFIX}")
4 SET(SQPGUI_LIBRARY_NAME "${LIBRARY_PREFFIX}_gui${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 SET(UI_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/ui")
7 SET(UI_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/ui")
8 SET(RES_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/resources")
8 SET(RES_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/resources")
9
9
10 # Include gui directory
10 # Include gui directory
11 include_directories("${INCLUDES_DIR}")
11 include_directories("${INCLUDES_DIR}")
12 include_directories("${CMAKE_CURRENT_BINARY_DIR}")
12 include_directories("${CMAKE_CURRENT_BINARY_DIR}")
13
13
14 # Set a variable to display a warning in the version files.
14 # Set a variable to display a warning in the version files.
15 SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.")
15 SET(SCIQLOP_CMAKE_GENERATION_WARNING "DON'T CHANGE THIS FILE. AUTOGENERATED BY CMAKE.")
16
16
17 #
17 #
18 # Find Qt modules
18 # Find Qt modules
19 #
19 #
20 SCIQLOP_FIND_QT(Core Widgets)
20 SCIQLOP_FIND_QT(Core Widgets)
21
21
22 #
22 #
23 # Find dependent libraries
23 # Find dependent libraries
24 # ========================
24 # ========================
25 find_package(sciqlop-core)
25 find_package(sciqlop-core)
26
26
27 SET(LIBRARIES ${SCIQLOP-CORE_LIBRARIES})
27 SET(LIBRARIES ${SCIQLOP-CORE_LIBRARIES})
28
28
29 INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR})
29 INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR})
30
30
31 # Add sqpcore to the list of libraries to use
31 # Add sqpcore to the list of libraries to use
32 list(APPEND LIBRARIES ${SQPCORE_LIBRARY_NAME})
32 list(APPEND LIBRARIES ${SQPCORE_LIBRARY_NAME})
33
33
34 # Add dependent shared libraries
34 # Add dependent shared libraries
35 list(APPEND SHARED_LIBRARIES ${SQPCORE_SHARED_LIBRARIES})
35 list(APPEND SHARED_LIBRARIES ${SQPCORE_SHARED_LIBRARIES})
36
36
37
37
38 # Ui files
38 # Ui files
39 FILE (GLOB_RECURSE PROJECT_FORMS ${UI_FOLDER}/*.ui)
39 FILE (GLOB_RECURSE PROJECT_FORMS ${UI_FOLDER}/*.ui)
40
40
41 # Resources files
41 # Resources files
42 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RES_FOLDER}/*.qrc)
42 FILE (GLOB_RECURSE PROJECT_RESOURCES ${RES_FOLDER}/*.qrc)
43
43
44 #
44 #
45 # Compile the library library
45 # Compile the library library
46 #
46 #
47 FILE (GLOB_RECURSE MODULE_SOURCES
47 FILE (GLOB_RECURSE MODULE_SOURCES
48 ${INCLUDES_DIR}/*.h
48 ${INCLUDES_DIR}/*.h
49 ${SOURCES_DIR}/*.c
49 ${SOURCES_DIR}/*.c
50 ${SOURCES_DIR}/*.cpp
50 ${SOURCES_DIR}/*.cpp
51 ${SOURCES_DIR}/*.h
51 ${SOURCES_DIR}/*.h
52 ${PROJECT_FORMS})
52 ${PROJECT_FORMS})
53
53
54 QT5_ADD_RESOURCES(RCC_HDRS
54 QT5_ADD_RESOURCES(RCC_HDRS
55 ${PROJECT_RESOURCES}
55 ${PROJECT_RESOURCES}
56 )
56 )
57
57
58 QT5_WRAP_UI(UIS_HDRS
58 QT5_WRAP_UI(UIS_HDRS
59 ${PROJECT_FORMS}
59 ${PROJECT_FORMS}
60 )
60 )
61
61
62
62
63 ADD_LIBRARY(${SQPGUI_LIBRARY_NAME} ${MODULE_SOURCES} ${UIS_HDRS} ${RCC_HDRS})
63 ADD_LIBRARY(${SQPGUI_LIBRARY_NAME} ${MODULE_SOURCES} ${UIS_HDRS} ${RCC_HDRS})
64 set_property(TARGET ${SQPGUI_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
64 set_property(TARGET ${SQPGUI_LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
65 set_property(TARGET ${SQPGUI_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
65 set_property(TARGET ${SQPGUI_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
66
66
67 TARGET_LINK_LIBRARIES(${SQPGUI_LIBRARY_NAME} ${LIBRARIES})
67 TARGET_LINK_LIBRARIES(${SQPGUI_LIBRARY_NAME} ${LIBRARIES})
68 qt5_use_modules(${SQPGUI_LIBRARY_NAME} Core Widgets)
68 qt5_use_modules(${SQPGUI_LIBRARY_NAME} Core Widgets)
69
69
70 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
70 # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
71 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
71 # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order.
72 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
72 # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets
73 IF(BUILD_SHARED_LIBS)
73 IF(BUILD_SHARED_LIBS)
74 SET_TARGET_PROPERTIES(${SQPGUI_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
74 SET_TARGET_PROPERTIES(${SQPGUI_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT")
75 ELSE()
75 ELSE()
76 TARGET_COMPILE_DEFINITIONS(${SQPGUI_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
76 TARGET_COMPILE_DEFINITIONS(${SQPGUI_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES")
77 ENDIF()
77 ENDIF()
78
78
79 # Set the variable to parent scope so that the other projects can copy the
79 # Set the variable to parent scope so that the other projects can copy the
80 # dependent shared libraries
80 # dependent shared libraries
81 SCIQLOP_SET_TO_PARENT_SCOPE(SQPGUI_LIBRARY_NAME)
81 SCIQLOP_SET_TO_PARENT_SCOPE(SQPGUI_LIBRARY_NAME)
82
82
83 # Copy extern shared libraries to the lib folder
83 # Copy extern shared libraries to the lib folder
84 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPGUI_LIBRARY_NAME})
84 SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPGUI_LIBRARY_NAME})
85
85
86 # Add the files to the list of files to be analyzed
86 # Add the files to the list of files to be analyzed
87 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
87 LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES})
88 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
88 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES)
89 # Vera++ exclusion files
89 # Vera++ exclusion files
90 #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/path/to/exclusionFiles.tcl)
90 #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/path/to/exclusionFiles.tcl)
91 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
91 SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES)
92
92
93 #
93 #
94 # Compile the tests
94 # Compile the tests
95 #
95 #
96 IF(BUILD_TESTS)
96 IF(BUILD_TESTS)
97 INCLUDE_DIRECTORIES(${SOURCES_DIR})
97 INCLUDE_DIRECTORIES(${SOURCES_DIR})
98 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
98 FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp)
99 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
99 FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h)
100 SET( TEST_LIBRARIES ${SQPGUI_LIBRARY_NAME})
100 SET( TEST_LIBRARIES ${SQPGUI_LIBRARY_NAME})
101
101
102 FOREACH( testFile ${TESTS_SOURCES} )
102 FOREACH( testFile ${TESTS_SOURCES} )
103 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
103 GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY )
104 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
104 GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE )
105
105
106 # Add to the list of sources files all the sources in the same
106 # Add to the list of sources files all the sources in the same
107 # directory that aren't another test
107 # directory that aren't another test
108 FILE (GLOB currentTestSources
108 FILE (GLOB currentTestSources
109 ${testDirectory}/*.c
109 ${testDirectory}/*.c
110 ${testDirectory}/*.cpp
110 ${testDirectory}/*.cpp
111 ${testDirectory}/*.h)
111 ${testDirectory}/*.h)
112 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
112 LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES})
113 LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
113 # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS})
114
114
115 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
115 ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources})
116 set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14)
117 set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON)
116 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
118 TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} )
117 qt5_use_modules(${testName} Test)
119 qt5_use_modules(${testName} Test)
118
120
119 ADD_TEST( NAME ${testName} COMMAND ${testName} )
121 ADD_TEST( NAME ${testName} COMMAND ${testName} )
120
122
121 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
123 SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES})
122 ENDFOREACH( testFile )
124 ENDFOREACH( testFile )
123
125
124 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
126 LIST(APPEND testFilesToFormat ${TESTS_SOURCES})
125 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
127 LIST(APPEND testFilesToFormat ${TESTS_HEADERS})
126 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
128 LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat})
127 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
129 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
128 ENDIF(BUILD_TESTS)
130 ENDIF(BUILD_TESTS)
129
131
130 #
132 #
131 # Set the files that must be formatted by clang-format.
133 # Set the files that must be formatted by clang-format.
132 #
134 #
133 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
135 LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES})
134 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
136 SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES)
135
137
136 #
138 #
137 # Set the directories that doxygen must browse to generate the
139 # Set the directories that doxygen must browse to generate the
138 # documentation.
140 # documentation.
139 #
141 #
140 # Source directories:
142 # Source directories:
141 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
143 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs")
142 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
144 LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
143 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
145 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS)
144 # Source directories to exclude from the documentation generation
146 # Source directories to exclude from the documentation generation
145 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
147 #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*")
146 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
148 SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS)
147
149
148 #
150 #
149 # Set the directories with the sources to analyze and propagate the
151 # Set the directories with the sources to analyze and propagate the
150 # modification to the parent scope
152 # modification to the parent scope
151 #
153 #
152 # Source directories to analyze:
154 # Source directories to analyze:
153 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
155 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")
154 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
156 LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
155 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
157 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS)
156 # Source directories to exclude from the analysis
158 # Source directories to exclude from the analysis
157 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
159 #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir")
158 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
160 SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS)
@@ -1,34 +1,43
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 #if defined(sqpApp)
14 #undef sqpApp
15 #endif
16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
17
18 class DataSourceController;
19
13 /**
20 /**
14 * @brief The SqpApplication class aims to make the link between SciQlop
21 * @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
22 * and its plugins. This is the intermediate class that SciQlop has to use
16 * in the way to connect a data source. Please first use load method to intialize
23 * in the way to connect a data source. Please first use load method to initialize
17 * a plugin specified by its metadata name (JSON plugin source) then others specifics
24 * a plugin specified by its metadata name (JSON plugin source) then others specifics
18 * method will ba able to access it.
25 * method will be able to access it.
19 * You can load a data source driver plugin then create a data source.
26 * You can load a data source driver plugin then create a data source.
20 */
27 */
21
28
22 class SqpApplication : public QApplication {
29 class SqpApplication : public QApplication {
23 Q_OBJECT
30 Q_OBJECT
24 public:
31 public:
25 explicit SqpApplication(int &argc, char **argv);
32 explicit SqpApplication(int &argc, char **argv);
26 virtual ~SqpApplication();
33 virtual ~SqpApplication();
27 void initialize();
34 void initialize();
28
35
36 DataSourceController &dataSourceController() const noexcept;
37
29 private:
38 private:
30 class SqpApplicationPrivate;
39 class SqpApplicationPrivate;
31 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
40 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
32 };
41 };
33
42
34 #endif // SCIQLOP_SQPAPPLICATION_H
43 #endif // SCIQLOP_SQPAPPLICATION_H
@@ -1,45 +1,51
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() : m_DataSourceController{std::make_unique<DataSourceController>()}
11 {
12 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
13 }
14
11 virtual ~SqpApplicationPrivate()
15 virtual ~SqpApplicationPrivate()
12 {
16 {
13 qCInfo(LOG_SqpApplication()) << tr("Desctruction du SqpApplicationPrivate");
17 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
14 m_DataSourceControllerThread.quit();
18 m_DataSourceControllerThread.quit();
15 m_DataSourceControllerThread.wait();
19 m_DataSourceControllerThread.wait();
16 }
20 }
17
21
18 std::unique_ptr<DataSourceController> m_DataSourceController;
22 std::unique_ptr<DataSourceController> m_DataSourceController;
19 QThread m_DataSourceControllerThread;
23 QThread m_DataSourceControllerThread;
20 };
24 };
21
25
22
26
23 SqpApplication::SqpApplication(int &argc, char **argv)
27 SqpApplication::SqpApplication(int &argc, char **argv)
24 : QApplication(argc, argv), impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
28 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
25 {
29 {
26 qCInfo(LOG_SqpApplication()) << tr("Construction du SqpApplication");
30 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
27
28 impl->m_DataSourceController = std::make_unique<DataSourceController>();
29 impl->m_DataSourceController->moveToThread(&impl->m_DataSourceControllerThread);
30
31
31 connect(&impl->m_DataSourceControllerThread, &QThread::started,
32 connect(&impl->m_DataSourceControllerThread, &QThread::started,
32 impl->m_DataSourceController.get(), &DataSourceController::initialize);
33 impl->m_DataSourceController.get(), &DataSourceController::initialize);
33 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
34 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
34 impl->m_DataSourceController.get(), &DataSourceController::finalize);
35 impl->m_DataSourceController.get(), &DataSourceController::finalize);
35
36
36 impl->m_DataSourceControllerThread.start();
37 impl->m_DataSourceControllerThread.start();
37 }
38 }
38
39
39 SqpApplication::~SqpApplication()
40 SqpApplication::~SqpApplication()
40 {
41 {
41 }
42 }
42
43
43 void SqpApplication::initialize()
44 void SqpApplication::initialize()
44 {
45 {
45 }
46 }
47
48 DataSourceController &SqpApplication::dataSourceController() const noexcept
49 {
50 return *impl->m_DataSourceController;
51 }
General Comments 0
You need to be logged in to leave comments. Login now