Skip to content

Commit

Permalink
Data store interface: got rid of all our assertions.
Browse files Browse the repository at this point in the history
Indeed, although those methods are not officially part of our Python wrappers, they could still be called from Python. So, we need to ensure that they don't cause problems (if the original assertion was to be false), which is what we are already doing for methods that are officially part of our Python wrappers.
  • Loading branch information
agarny committed Dec 11, 2019
1 parent 7fc8976 commit c56a8cb
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions src/plugins/datastoreinterface.cpp
Expand Up @@ -84,9 +84,11 @@ double DataStoreArray::data(quint64 pPosition) const
{
// Return the data value at the given position

Q_ASSERT((pPosition < mSize) && (mData != nullptr));
if ((pPosition < mSize) && (mData != nullptr)) {
return mData[pPosition];
}

return mData[pPosition];
return qQNaN();
}

//==============================================================================
Expand Down Expand Up @@ -152,9 +154,11 @@ double DataStoreValue::value() const
{
// Return our value

Q_ASSERT(mValue != nullptr);
if (mValue != nullptr) {
return *mValue;
}

return *mValue;
return qQNaN();
}

//==============================================================================
Expand All @@ -163,9 +167,9 @@ void DataStoreValue::setValue(double pValue)
{
// Set our value

Q_ASSERT(mValue != nullptr);

*mValue = pValue;
if (mValue != nullptr) {
*mValue = pValue;
}
}

//==============================================================================
Expand Down Expand Up @@ -231,11 +235,11 @@ void DataStoreVariableRun::addValue()
{
// Set the value of the variable at the given position

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

mArray->data()[mSize] = *mValue;
if ((mSize < mCapacity) && (mValue != nullptr)) {
mArray->data()[mSize] = *mValue;

++mSize;
++mSize;
}
}

//==============================================================================
Expand All @@ -244,11 +248,11 @@ void DataStoreVariableRun::addValue(double pValue)
{
// Set the value of the variable at the given position using the given value

Q_ASSERT(mSize < mCapacity);

mArray->data()[mSize] = pValue;
if (mSize < mCapacity) {
mArray->data()[mSize] = pValue;

++mSize;
++mSize;
}
}

//==============================================================================
Expand Down Expand Up @@ -477,9 +481,9 @@ void DataStoreVariable::addValue()
{
// Add a value to our current (i.e. last) run

Q_ASSERT(!mRuns.isEmpty());

mRuns.last()->addValue();
if (!mRuns.isEmpty()) {
mRuns.last()->addValue();
}
}

//==============================================================================
Expand All @@ -488,14 +492,12 @@ void DataStoreVariable::addValue(double pValue, int pRun)
{
// Add the given value to our current (i.e. last) run

Q_ASSERT(!mRuns.isEmpty());

if (pRun == -1) {
mRuns.last()->addValue(pValue);
} else {
Q_ASSERT((pRun >= 0) && (pRun < mRuns.count()));

mRuns[pRun]->addValue(pValue);
if (!mRuns.isEmpty()) {
if (pRun == -1) {
mRuns.last()->addValue(pValue);
} else if ((pRun >= 0) && (pRun < mRuns.count())) {
mRuns[pRun]->addValue(pValue);
}
}
}

Expand Down Expand Up @@ -543,9 +545,11 @@ double DataStoreVariable::value() const
{
// Return the value to be added next

Q_ASSERT(mValue != nullptr);
if (mValue != nullptr) {
return *mValue;
}

return *mValue;
return qQNaN();
}

//==============================================================================
Expand All @@ -554,9 +558,9 @@ void DataStoreVariable::setValue(double pValue)
{
// Set the value to be added next

Q_ASSERT(mValue != nullptr);

*mValue = pValue;
if (mValue != nullptr) {
*mValue = pValue;
}
}

//==============================================================================
Expand Down

0 comments on commit c56a8cb

Please sign in to comment.