Skip to content

Commit

Permalink
Some minor cleaning up.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Oct 21, 2019
1 parent 09fc0d6 commit a84a9aa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 66 deletions.
105 changes: 45 additions & 60 deletions src/plugins/datastoreinterface.cpp
Expand Up @@ -82,7 +82,7 @@ double DataStoreArray::data(quint64 pPosition) const
{
// Return the value at the given position

Q_ASSERT((pPosition < mSize) && mData);
Q_ASSERT((pPosition < mSize) && (mData != nullptr));

return mData[pPosition];
}
Expand Down Expand Up @@ -122,15 +122,17 @@ void DataStoreArray::decRef()
//==============================================================================

DataStoreValue::DataStoreValue(double *pValue) :
mUri(QString()),
mValue(pValue)
{
}

//==============================================================================

DataStoreValue::~DataStoreValue()
QString DataStoreValue::uri() const
{
// Return our URI

return mUri;
}

//==============================================================================
Expand All @@ -144,20 +146,11 @@ void DataStoreValue::setUri(const QString &pUri)

//==============================================================================

QString DataStoreValue::uri() const
{
// Return our URI

return mUri;
}

//==============================================================================

double DataStoreValue::value() const
{
// Return our value

Q_ASSERT(mValue);
Q_ASSERT(mValue != nullptr);

return *mValue;
}
Expand All @@ -168,44 +161,37 @@ void DataStoreValue::setValue(double pValue)
{
// Set our value

Q_ASSERT(mValue);
Q_ASSERT(mValue != nullptr);

*mValue = pValue;
}

//==============================================================================

DataStoreValues::DataStoreValues()
{
}

//==============================================================================

DataStoreValues::DataStoreValues(DataStoreArray *pDataStoreArray)
{
// Create a list of DataStoreValues
// Create a list of DataStoreValue objects

double *data = pDataStoreArray->data();

double *d = pDataStoreArray->data();
quint64 i = pDataStoreArray->size();
for (quint64 i = 0, iMax = pDataStoreArray->size(); i < iMax; ++i) {
*this << new DataStoreValue(data);

while (i-- > 0) {
auto v = new DataStoreValue(d);
*this << v;
++d;
++data;
}
}

//==============================================================================

DataStoreValues::~DataStoreValues()
{
// Delete our DataStoreValues
// Delete our DataStoreValue objects

while (count() > 0) {
delete last();

removeLast();
for (DataStoreValue *dataStoreValue : *this) {
delete dataStoreValue;
}

clear();
}

//==============================================================================
Expand All @@ -217,7 +203,6 @@ DataStoreVariableRun::DataStoreVariableRun(quint64 pCapacity, double *pValue) :
// Create our array of values

mArray = new DataStoreArray(mCapacity);
mValues = mArray->data();
}

//==============================================================================
Expand All @@ -244,9 +229,9 @@ void DataStoreVariableRun::addValue()
{
// Set the value of the variable at the given position

Q_ASSERT((mSize < mCapacity) && mValue);
Q_ASSERT((mSize < mCapacity) && (mValue != nullptr));

mValues[mSize] = *mValue;
mArray->data()[mSize] = *mValue;

++mSize;
}
Expand All @@ -259,7 +244,7 @@ void DataStoreVariableRun::addValue(double pValue)

Q_ASSERT(mSize < mCapacity);

mValues[mSize] = pValue;
mArray->data()[mSize] = pValue;

++mSize;
}
Expand All @@ -281,7 +266,7 @@ double DataStoreVariableRun::value(quint64 pPosition) const

Q_ASSERT(pPosition < mSize);

return mValues[pPosition];
return mArray->data()[pPosition];
}

//==============================================================================
Expand All @@ -290,7 +275,7 @@ double * DataStoreVariableRun::values() const
{
// Return our values

return mValues;
return mArray->data();
}

//==============================================================================
Expand Down Expand Up @@ -465,6 +450,25 @@ quint64 DataStoreVariable::size(int pRun) const

//==============================================================================

DataStoreArray * DataStoreVariable::array(int pRun) const
{
// Return the data array for the given run, if any

if (mRuns.isEmpty()) {
return nullptr;
}

if (pRun == -1) {
return mRuns.last()->array();
}

return ((pRun >= 0) && (pRun < mRuns.count()))?
mRuns[pRun]->array():
nullptr;
}

//==============================================================================

void DataStoreVariable::addValue()
{
// Add a value to our current (i.e. last) run
Expand Down Expand Up @@ -529,11 +533,11 @@ double * DataStoreVariable::values(int pRun) const

//==============================================================================

double DataStoreVariable::getValue() const
double DataStoreVariable::value() const
{
// Return the value to be added next

Q_ASSERT(mValue);
Q_ASSERT(mValue != nullptr);

return *mValue;
}
Expand All @@ -544,32 +548,13 @@ void DataStoreVariable::setValue(double pValue)
{
// Set the value to be added next

Q_ASSERT(mValue);
Q_ASSERT(mValue != nullptr);

*mValue = pValue;
}

//==============================================================================

DataStoreArray * DataStoreVariable::array(int pRun) const
{
// Return the data array for the given run, if any

if (mRuns.isEmpty()) {
return nullptr;
} else {
if (pRun == -1) {
return mRuns.last()->array();
} else {
return ((pRun >= 0) && (pRun < mRuns.count()))?
mRuns[pRun]->array():
nullptr;
}
}
}

//==============================================================================

DataStoreData::DataStoreData(const QString &pFileName) :
mFileName(pFileName)
{
Expand Down
9 changes: 3 additions & 6 deletions src/plugins/datastoreinterface.h
Expand Up @@ -63,7 +63,6 @@ class DataStoreValue : public QObject

public:
explicit DataStoreValue(double *pValue = nullptr);
~DataStoreValue();

void setUri(const QString &pUri);

Expand All @@ -84,7 +83,6 @@ public slots:
class DataStoreValues : public QList<DataStoreValue *>
{
public:
explicit DataStoreValues();
explicit DataStoreValues(DataStoreArray *pDataStoreArray);
~DataStoreValues();
};
Expand Down Expand Up @@ -115,7 +113,6 @@ class DataStoreVariableRun : public QObject

DataStoreArray *mArray;
double *mValue;
double *mValues;
};

//==============================================================================
Expand Down Expand Up @@ -167,11 +164,11 @@ public slots:

quint64 size(int pRun = -1) const;

double getValue() const;
void setValue(double pValue);

double value(quint64 pPosition, int pRun = -1) const;

double value() const;
void setValue(double pValue);

private:
int mType = -1;
QString mUri;
Expand Down

0 comments on commit a84a9aa

Please sign in to comment.