@@ -0,0 +1,58 | |||||
|
1 | #ifndef SCIQLOP_OPTIONALAXIS_H | |||
|
2 | #define SCIQLOP_OPTIONALAXIS_H | |||
|
3 | ||||
|
4 | #include "CoreGlobal.h" | |||
|
5 | #include "Unit.h" | |||
|
6 | ||||
|
7 | #include <memory> | |||
|
8 | ||||
|
9 | template <int Dim> | |||
|
10 | class ArrayData; | |||
|
11 | ||||
|
12 | /** | |||
|
13 | * @brief The OptionalAxis class defines an optional data axis for a series of data. | |||
|
14 | * | |||
|
15 | * An optional data axis is an axis that can be defined or not for a data series. If defined, it | |||
|
16 | * contains a unit and data (1-dim ArrayData). It is then possible to access the data or the unit. | |||
|
17 | * In the case of an undefined axis, the axis has no data and no unit. The methods for accessing the | |||
|
18 | * data or the unit are always callable but will return undefined values. | |||
|
19 | * | |||
|
20 | * @sa DataSeries | |||
|
21 | * @sa ArrayData | |||
|
22 | */ | |||
|
23 | class SCIQLOP_CORE_EXPORT OptionalAxis { | |||
|
24 | public: | |||
|
25 | /// Ctor for an undefined axis | |||
|
26 | explicit OptionalAxis(); | |||
|
27 | /// Ctor for a defined axis | |||
|
28 | /// @param data the axis' data | |||
|
29 | /// @param unit the axis' unit | |||
|
30 | /// @throws std::invalid_argument if no data is associated to the axis | |||
|
31 | explicit OptionalAxis(std::shared_ptr<ArrayData<1> > data, Unit unit); | |||
|
32 | ||||
|
33 | /// Copy ctor | |||
|
34 | OptionalAxis(const OptionalAxis &other); | |||
|
35 | /// Assignment operator | |||
|
36 | OptionalAxis &operator=(OptionalAxis other); | |||
|
37 | ||||
|
38 | /// @return the flag that indicates if the axis is defined or not | |||
|
39 | bool isDefined() const; | |||
|
40 | ||||
|
41 | /// @return gets the data at the index passed in parameter, NaN if the index is outside the | |||
|
42 | /// bounds of the axis, or if the axis is undefined | |||
|
43 | double at(int index) const; | |||
|
44 | /// @return the number of data on the axis, 0 if the axis is not defined | |||
|
45 | int size() const; | |||
|
46 | /// @return the unit of the axis, an empty unit if the axis is not defined | |||
|
47 | Unit unit() const; | |||
|
48 | ||||
|
49 | bool operator==(const OptionalAxis &other); | |||
|
50 | bool operator!=(const OptionalAxis &other); | |||
|
51 | ||||
|
52 | private: | |||
|
53 | bool m_Defined; ///< Axis is defined or not | |||
|
54 | std::shared_ptr<ArrayData<1> > m_Data; ///< Axis' data | |||
|
55 | Unit m_Unit; ///< Axis' unit | |||
|
56 | }; | |||
|
57 | ||||
|
58 | #endif // SCIQLOP_OPTIONALAXIS_H |
@@ -0,0 +1,74 | |||||
|
1 | #include <Data/OptionalAxis.h> | |||
|
2 | ||||
|
3 | #include "Data/ArrayData.h" | |||
|
4 | ||||
|
5 | OptionalAxis::OptionalAxis() : m_Defined{false}, m_Data{nullptr}, m_Unit{} | |||
|
6 | { | |||
|
7 | } | |||
|
8 | ||||
|
9 | OptionalAxis::OptionalAxis(std::shared_ptr<ArrayData<1> > data, Unit unit) | |||
|
10 | : m_Defined{true}, m_Data{data}, m_Unit{std::move(unit)} | |||
|
11 | { | |||
|
12 | if (m_Data == nullptr) { | |||
|
13 | throw std::invalid_argument{"Data can't be null for a defined axis"}; | |||
|
14 | } | |||
|
15 | } | |||
|
16 | ||||
|
17 | OptionalAxis::OptionalAxis(const OptionalAxis &other) | |||
|
18 | : m_Defined{other.m_Defined}, | |||
|
19 | m_Data{other.m_Data ? std::make_shared<ArrayData<1> >(*other.m_Data) : nullptr}, | |||
|
20 | m_Unit{other.m_Unit} | |||
|
21 | { | |||
|
22 | } | |||
|
23 | ||||
|
24 | OptionalAxis &OptionalAxis::operator=(OptionalAxis other) | |||
|
25 | { | |||
|
26 | std::swap(m_Defined, other.m_Defined); | |||
|
27 | std::swap(m_Data, other.m_Data); | |||
|
28 | std::swap(m_Unit, other.m_Unit); | |||
|
29 | } | |||
|
30 | ||||
|
31 | bool OptionalAxis::isDefined() const | |||
|
32 | { | |||
|
33 | return m_Defined; | |||
|
34 | } | |||
|
35 | ||||
|
36 | double OptionalAxis::at(int index) const | |||
|
37 | { | |||
|
38 | if (m_Defined) { | |||
|
39 | return (index >= 0 && index < m_Data->size()) ? m_Data->at(index) | |||
|
40 | : std::numeric_limits<double>::quiet_NaN(); | |||
|
41 | } | |||
|
42 | else { | |||
|
43 | return std::numeric_limits<double>::quiet_NaN(); | |||
|
44 | } | |||
|
45 | } | |||
|
46 | ||||
|
47 | int OptionalAxis::size() const | |||
|
48 | { | |||
|
49 | return m_Defined ? m_Data->size() : 0; | |||
|
50 | } | |||
|
51 | ||||
|
52 | Unit OptionalAxis::unit() const | |||
|
53 | { | |||
|
54 | return m_Defined ? m_Unit : Unit{}; | |||
|
55 | } | |||
|
56 | ||||
|
57 | bool OptionalAxis::operator==(const OptionalAxis &other) | |||
|
58 | { | |||
|
59 | // Axis not defined | |||
|
60 | if (!m_Defined) { | |||
|
61 | return !other.m_Defined; | |||
|
62 | } | |||
|
63 | ||||
|
64 | // Axis defined | |||
|
65 | return m_Unit == other.m_Unit | |||
|
66 | && std::equal( | |||
|
67 | m_Data->cbegin(), m_Data->cend(), other.m_Data->cbegin(), other.m_Data->cend(), | |||
|
68 | [](const auto &it1, const auto &it2) { return it1.values() == it2.values(); }); | |||
|
69 | } | |||
|
70 | ||||
|
71 | bool OptionalAxis::operator!=(const OptionalAxis &other) | |||
|
72 | { | |||
|
73 | return !(*this == other); | |||
|
74 | } |
@@ -1,63 +1,64 | |||||
1 |
|
1 | |||
2 | core_moc_headers = [ |
|
2 | core_moc_headers = [ | |
3 | 'include/Data/IDataProvider.h', |
|
3 | 'include/Data/IDataProvider.h', | |
4 | 'include/DataSource/DataSourceController.h', |
|
4 | 'include/DataSource/DataSourceController.h', | |
5 | 'include/DataSource/DataSourceItemAction.h', |
|
5 | 'include/DataSource/DataSourceItemAction.h', | |
6 | 'include/Network/NetworkController.h', |
|
6 | 'include/Network/NetworkController.h', | |
7 | 'include/Time/TimeController.h', |
|
7 | 'include/Time/TimeController.h', | |
8 | 'include/Variable/Variable.h', |
|
8 | 'include/Variable/Variable.h', | |
9 | 'include/Variable/VariableCacheController.h', |
|
9 | 'include/Variable/VariableCacheController.h', | |
10 | 'include/Variable/VariableController.h', |
|
10 | 'include/Variable/VariableController.h', | |
11 | 'include/Variable/VariableAcquisitionWorker.h', |
|
11 | 'include/Variable/VariableAcquisitionWorker.h', | |
12 | 'include/Variable/VariableCacheStrategy.h', |
|
12 | 'include/Variable/VariableCacheStrategy.h', | |
13 | 'include/Variable/VariableSynchronizationGroup.h', |
|
13 | 'include/Variable/VariableSynchronizationGroup.h', | |
14 | 'include/Variable/VariableModel.h', |
|
14 | 'include/Variable/VariableModel.h', | |
15 | 'include/Visualization/VisualizationController.h' |
|
15 | 'include/Visualization/VisualizationController.h' | |
16 | ] |
|
16 | ] | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | core_moc_files = qt5.preprocess(moc_headers : core_moc_headers) |
|
19 | core_moc_files = qt5.preprocess(moc_headers : core_moc_headers) | |
20 |
|
20 | |||
21 | core_sources = [ |
|
21 | core_sources = [ | |
22 | 'src/Common/DateUtils.cpp', |
|
22 | 'src/Common/DateUtils.cpp', | |
23 | 'src/Common/StringUtils.cpp', |
|
23 | 'src/Common/StringUtils.cpp', | |
24 | 'src/Common/MimeTypesDef.cpp', |
|
24 | 'src/Common/MimeTypesDef.cpp', | |
25 | 'src/Data/ScalarSeries.cpp', |
|
25 | 'src/Data/ScalarSeries.cpp', | |
26 | 'src/Data/DataSeriesIterator.cpp', |
|
26 | 'src/Data/DataSeriesIterator.cpp', | |
27 | 'src/Data/ArrayDataIterator.cpp', |
|
27 | 'src/Data/ArrayDataIterator.cpp', | |
28 | 'src/Data/VectorSeries.cpp', |
|
28 | 'src/Data/VectorSeries.cpp', | |
|
29 | 'src/Data/OptionalAxis.cpp', | |||
29 | 'src/DataSource/DataSourceController.cpp', |
|
30 | 'src/DataSource/DataSourceController.cpp', | |
30 | 'src/DataSource/DataSourceItem.cpp', |
|
31 | 'src/DataSource/DataSourceItem.cpp', | |
31 | 'src/DataSource/DataSourceItemAction.cpp', |
|
32 | 'src/DataSource/DataSourceItemAction.cpp', | |
32 | 'src/Network/NetworkController.cpp', |
|
33 | 'src/Network/NetworkController.cpp', | |
33 | 'src/Plugin/PluginManager.cpp', |
|
34 | 'src/Plugin/PluginManager.cpp', | |
34 | 'src/Settings/SqpSettingsDefs.cpp', |
|
35 | 'src/Settings/SqpSettingsDefs.cpp', | |
35 | 'src/Time/TimeController.cpp', |
|
36 | 'src/Time/TimeController.cpp', | |
36 | 'src/Variable/Variable.cpp', |
|
37 | 'src/Variable/Variable.cpp', | |
37 | 'src/Variable/VariableCacheController.cpp', |
|
38 | 'src/Variable/VariableCacheController.cpp', | |
38 | 'src/Variable/VariableController.cpp', |
|
39 | 'src/Variable/VariableController.cpp', | |
39 | 'src/Variable/VariableAcquisitionWorker.cpp', |
|
40 | 'src/Variable/VariableAcquisitionWorker.cpp', | |
40 | 'src/Variable/VariableSynchronizationGroup.cpp', |
|
41 | 'src/Variable/VariableSynchronizationGroup.cpp', | |
41 | 'src/Variable/VariableModel.cpp', |
|
42 | 'src/Variable/VariableModel.cpp', | |
42 | 'src/Visualization/VisualizationController.cpp' |
|
43 | 'src/Visualization/VisualizationController.cpp' | |
43 | ] |
|
44 | ] | |
44 |
|
45 | |||
45 | core_inc = include_directories(['include', '../plugin/include']) |
|
46 | core_inc = include_directories(['include', '../plugin/include']) | |
46 |
|
47 | |||
47 | sciqlop_core_lib = library('sciqlopcore', |
|
48 | sciqlop_core_lib = library('sciqlopcore', | |
48 | core_sources, |
|
49 | core_sources, | |
49 | core_moc_files, |
|
50 | core_moc_files, | |
50 | cpp_args : '-DCORE_LIB', |
|
51 | cpp_args : '-DCORE_LIB', | |
51 | include_directories : core_inc, |
|
52 | include_directories : core_inc, | |
52 | dependencies : [qt5core, qt5network], |
|
53 | dependencies : [qt5core, qt5network], | |
53 | install : true |
|
54 | install : true | |
54 | ) |
|
55 | ) | |
55 |
|
56 | |||
56 |
|
57 | |||
57 | sciqlop_core = declare_dependency(link_with : sciqlop_core_lib, |
|
58 | sciqlop_core = declare_dependency(link_with : sciqlop_core_lib, | |
58 | include_directories : core_inc, |
|
59 | include_directories : core_inc, | |
59 | dependencies : [qt5core, qt5network]) |
|
60 | dependencies : [qt5core, qt5network]) | |
60 |
|
61 | |||
61 |
|
62 | |||
62 | subdir('tests') |
|
63 | subdir('tests') | |
63 |
|
64 |
General Comments 0
You need to be logged in to leave comments.
Login now