##// END OF EJS Templates
Settings binding (4)...
Settings binding (4) Loads settings when opening the dialog, and save settings when closing it (if it's by the OK button)

File last commit:

r454:c975894e323f
r469:7a2eb58d2083
Show More
ArrayData.h
169 lines | 4.9 KiB | text/x-c | CLexer
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 #ifndef SCIQLOP_ARRAYDATA_H
#define SCIQLOP_ARRAYDATA_H
Add current progression for thread fix
r364 #include <QReadLocker>
#include <QReadWriteLock>
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 #include <QVector>
Alexandre Leroux
Makes a Data series be sorted (2)...
r450
#include <memory>
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 /**
* @brief The ArrayData class represents a dataset for a data series.
*
* A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
* template-parameter.
*
* @tparam Dim the dimension of the ArrayData (one or two)
* @sa IDataSeries
*/
template <int Dim>
class ArrayData {
public:
/**
* Ctor for a unidimensional ArrayData
* @param nbColumns the number of values the ArrayData will hold
*/
template <int D = Dim, typename = std::enable_if_t<D == 1> >
explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}}
{
Alexandre Leroux
Review fixes
r372 QWriteLocker locker{&m_Lock};
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 m_Data[0].resize(nbColumns);
}
Alexandre Leroux
Creates constructor for ScalarSeries that directly takes vectors...
r392 /**
* Ctor for a unidimensional ArrayData
* @param data the data the ArrayData will hold
*/
template <int D = Dim, typename = std::enable_if_t<D == 1> >
explicit ArrayData(QVector<double> data) : m_Data{1, QVector<double>{}}
{
QWriteLocker locker{&m_Lock};
m_Data[0] = std::move(data);
}
Alexandre Leroux
Review fixes
r372 /// Copy ctor
Add current progression for thread fix
r364 explicit ArrayData(const ArrayData &other)
{
Alexandre Leroux
Review fixes
r372 QReadLocker otherLocker{&other.m_Lock};
QWriteLocker locker{&m_Lock};
Add current progression for thread fix
r364 m_Data = other.m_Data;
}
Alexandre Leroux
Makes a Data series be sorted (2)...
r450 /**
* @return the data at a specified index
* @remarks index must be a valid position
* @remarks this method is only available for a unidimensional ArrayData
*/
template <int D = Dim, typename = std::enable_if_t<D == 1> >
double at(int index) const noexcept
{
QReadLocker locker{&m_Lock};
return m_Data[0].at(index);
}
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 /**
* Sets a data at a specified index. The index has to be valid to be effective
* @param index the index to which the data will be set
* @param data the data to set
* @remarks this method is only available for a unidimensional ArrayData
*/
template <int D = Dim, typename = std::enable_if_t<D == 1> >
void setData(int index, double data) noexcept
{
Alexandre Leroux
Review fixes
r372 QWriteLocker locker{&m_Lock};
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 if (index >= 0 && index < m_Data.at(0).size()) {
m_Data[0].replace(index, data);
}
}
/**
* @return the data as a vector
* @remarks this method is only available for a unidimensional ArrayData
*/
template <int D = Dim, typename = std::enable_if_t<D == 1> >
Add current progression for thread fix
r364 QVector<double> data() const noexcept
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 {
Alexandre Leroux
Review fixes
r372 QReadLocker locker{&m_Lock};
Update ArrayData to make it better
r294 return m_Data[0];
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 }
Add merge API and implement it for the DataSeries
r233 /**
Alexandre Leroux
Makes a Data series be sorted (1)
r449 * @return the data as a vector, as a const reference
Add merge API and implement it for the DataSeries
r233 * @remarks this method is only available for a unidimensional ArrayData
*/
template <int D = Dim, typename = std::enable_if_t<D == 1> >
Alexandre Leroux
Makes a Data series be sorted (1)
r449 const QVector<double> &cdata() const noexcept
Add merge API and implement it for the DataSeries
r233 {
Alexandre Leroux
Review fixes
r372 QReadLocker locker{&m_Lock};
Alexandre Leroux
Makes a Data series be sorted (1)
r449 return m_Data.at(0);
Add merge API and implement it for the DataSeries
r233 }
Alexandre Leroux
Handles merge of two data series
r451 /**
* Merges into the array data an other array data
* @param other the array data to merge with
* @param prepend if true, the other array data is inserted at the beginning, otherwise it is
* inserted at the end
* @remarks this method is only available for a unidimensional ArrayData
*/
Add merge API and implement it for the DataSeries
r233 template <int D = Dim, typename = std::enable_if_t<D == 1> >
Alexandre Leroux
Handles merge of two data series
r451 void add(const ArrayData<1> &other, bool prepend = false)
Add merge API and implement it for the DataSeries
r233 {
Alexandre Leroux
Review fixes
r372 QWriteLocker locker{&m_Lock};
Add merge API and implement it for the DataSeries
r233 if (!m_Data.empty()) {
Alexandre Leroux
Handles merge of two data series
r451 QReadLocker otherLocker{&other.m_Lock};
if (prepend) {
const auto &otherData = other.data();
const auto otherDataSize = otherData.size();
auto &data = m_Data[0];
data.insert(data.begin(), otherDataSize, 0.);
for (auto i = 0; i < otherDataSize; ++i) {
data.replace(i, otherData.at(i));
}
}
else {
m_Data[0] += other.data();
}
Add merge API and implement it for the DataSeries
r233 }
}
template <int D = Dim, typename = std::enable_if_t<D == 1> >
Add current progression for thread fix
r364 int size() const
Add merge API and implement it for the DataSeries
r233 {
Alexandre Leroux
Review fixes
r372 QReadLocker locker{&m_Lock};
Add merge API and implement it for the DataSeries
r233 return m_Data[0].size();
}
Alexandre Leroux
Makes a Data series be sorted (2)...
r450 template <int D = Dim, typename = std::enable_if_t<D == 1> >
std::shared_ptr<ArrayData<Dim> > sort(const std::vector<int> sortPermutation)
{
QReadLocker locker{&m_Lock};
const auto &data = m_Data.at(0);
// Inits result
auto sortedData = QVector<double>{};
sortedData.resize(data.size());
std::transform(sortPermutation.cbegin(), sortPermutation.cend(), sortedData.begin(),
[&data](int i) { return data[i]; });
return std::make_shared<ArrayData<Dim> >(std::move(sortedData));
}
Alexandre Leroux
Correction on ArrayData::clear() method
r454
template <int D = Dim, typename = std::enable_if_t<D == 1> >
Add current progression for thread fix
r364 void clear()
{
Alexandre Leroux
Review fixes
r372 QWriteLocker locker{&m_Lock};
Alexandre Leroux
Correction on ArrayData::clear() method
r454 m_Data[0].clear();
Add current progression for thread fix
r364 }
Add merge API and implement it for the DataSeries
r233
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 private:
QVector<QVector<double> > m_Data;
Add current progression for thread fix
r364 mutable QReadWriteLock m_Lock;
Alexandre Leroux
Creates ArrayData (struct that holds data as a vector of double)
r124 };
#endif // SCIQLOP_ARRAYDATA_H