Skip to content

Commit

Permalink
remove asserts from most headers (MultiDimArray and CompactLookup don…
Browse files Browse the repository at this point in the history
…'t get called into from headers, so they should be okay)
  • Loading branch information
coalsont committed Jul 28, 2016
1 parent 875fe56 commit 900ac9a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/Cifti/VolumeSpace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "VolumeSpace.h"

#include "Common/CiftiAssert.h"
#include "Common/CiftiException.h"
#include "Common/FloatMatrix.h"

Expand Down
2 changes: 0 additions & 2 deletions src/Cifti/VolumeSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "Common/CiftiAssert.h"
#include "Common/Vector3D.h"

#include "Common/XmlAdapter.h"
Expand Down Expand Up @@ -129,7 +128,6 @@ namespace cifti

inline int64_t getIndex(const int64_t& indexIn1, const int64_t& indexIn2, const int64_t& indexIn3) const
{
CiftiAssert(indexValid(indexIn1, indexIn2, indexIn3));
return indexIn1 + m_dims[0] * (indexIn2 + m_dims[1] * indexIn3);
}

Expand Down
5 changes: 2 additions & 3 deletions src/Common/XmlAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace cifti

#ifdef CIFTILIB_USE_XMLPP
#define __XML_ADAPTER_H_HAVE_IMPL__
#include "CiftiAssert.h"
#include "libxml++/libxml++.h"
#include "libxml++/parsers/textreader.h"
#include "libxml/xmlwriter.h"
Expand Down Expand Up @@ -101,7 +100,7 @@ namespace cifti
}
void writeEndElement()
{
CiftiAssert(m_elementStack.size() > 0);
if (m_elementStack.empty()) throw CiftiException("internal error: attempted writing end element outside root element");
if (xmlTextWriterEndElement(m_xmlPtr) == -1) throw CiftiException("error writing end element for " + m_elementStack.back());
m_elementStack.pop_back();
}
Expand All @@ -118,7 +117,7 @@ namespace cifti
}
void writeAttribute(const AString& name, const AString& text)
{
CiftiAssert(m_elementStack.size() > 0);
if (m_elementStack.empty()) throw CiftiException("internal error: attempted writing attribute outside root element");
if (xmlTextWriterWriteAttribute(m_xmlPtr, BAD_CAST ASTRING_UTF8_RAW(name), BAD_CAST ASTRING_UTF8_RAW(text)) == -1)
{
throw CiftiException("error writing " + name + " attribute of " + m_elementStack.back() + " element");
Expand Down
25 changes: 16 additions & 9 deletions src/NiftiIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "Common/AString.h"

#include "Common/ByteSwapping.h"
#include "Common/CiftiAssert.h"
#include "Common/BinaryFile.h"
#include "Common/CiftiException.h"
#include "Nifti/NiftiHeader.h"
Expand Down Expand Up @@ -74,8 +73,12 @@ namespace cifti
template<typename T>
void NiftiIO::readData(T* dataOut, const int& fullDims, const std::vector<int64_t>& indexSelect, const bool& tolerateShortRead)
{
CiftiAssert(fullDims >= 0 && fullDims <= (int)m_dims.size());
CiftiAssert((size_t)fullDims + indexSelect.size() == m_dims.size());//could be >=, but should catch more stupid mistakes as ==
if (fullDims < 0) throw CiftiException("NiftiIO: fulldims must not be negative");
if (fullDims > (int)m_dims.size()) throw CiftiException("NiftiIO: fulldims must not be greater than number of dimensions");
if ((size_t)fullDims + indexSelect.size() != m_dims.size())
{//could be >=, but should catch more stupid mistakes as ==
throw CiftiException("NiftiIO: fulldims plus length of indexSelect must equal number of dimensions");
}
int64_t numElems = getNumComponents();//for now, calculate read size on the fly, as the read call will be the slowest part
int curDim;
for (curDim = 0; curDim < fullDims; ++curDim)
Expand All @@ -85,7 +88,8 @@ namespace cifti
int64_t numDimSkip = numElems, numSkip = 0;
for (; curDim < (int)m_dims.size(); ++curDim)
{
CiftiAssert(indexSelect[curDim - fullDims] >= 0 && indexSelect[curDim - fullDims] < m_dims[curDim]);
if (indexSelect[curDim - fullDims] < 0) throw CiftiException("NiftiIO: indices must not be negative");
if (indexSelect[curDim - fullDims] >= m_dims[curDim]) throw CiftiException("NiftiIO: index exceeds nifti dimension length");
numSkip += indexSelect[curDim - fullDims] * numDimSkip;
numDimSkip *= m_dims[curDim];
}
Expand Down Expand Up @@ -137,16 +141,19 @@ namespace cifti
convertRead(dataOut, (long double*)m_scratch.data(), numElems);
break;
default:
CiftiAssert(0);
throw CiftiException("internal error, tell the developers what you just tried to do");
}
}

template<typename T>
void NiftiIO::writeData(const T* dataIn, const int& fullDims, const std::vector<int64_t>& indexSelect)
{
CiftiAssert(fullDims >= 0 && fullDims <= (int)m_dims.size());
CiftiAssert((size_t)fullDims + indexSelect.size() == m_dims.size());//could be >=, but should catch more stupid mistakes as ==
if (fullDims < 0) throw CiftiException("NiftiIO: fulldims must not be negative");
if (fullDims > (int)m_dims.size()) throw CiftiException("NiftiIO: fulldims must not be greater than number of dimensions");
if ((size_t)fullDims + indexSelect.size() != m_dims.size())
{//could be >=, but should catch more stupid mistakes as ==
throw CiftiException("NiftiIO: fulldims plus length of indexSelect must equal number of dimensions");
}
int64_t numElems = getNumComponents();//for now, calculate read size on the fly, as the read call will be the slowest part
int curDim;
for (curDim = 0; curDim < fullDims; ++curDim)
Expand All @@ -156,7 +163,8 @@ namespace cifti
int64_t numDimSkip = numElems, numSkip = 0;
for (; curDim < (int)m_dims.size(); ++curDim)
{
CiftiAssert(indexSelect[curDim - fullDims] >= 0 && indexSelect[curDim - fullDims] < m_dims[curDim]);
if (indexSelect[curDim - fullDims] < 0) throw CiftiException("NiftiIO: indices must not be negative");
if (indexSelect[curDim - fullDims] >= m_dims[curDim]) throw CiftiException("NiftiIO: index exceeds nifti dimension length");
numSkip += indexSelect[curDim - fullDims] * numDimSkip;
numDimSkip *= m_dims[curDim];
}
Expand Down Expand Up @@ -202,7 +210,6 @@ namespace cifti
convertWrite((long double*)m_scratch.data(), dataIn, numElems);
break;
default:
CiftiAssert(0);
throw CiftiException("internal error, tell the developers what you just tried to do");
}
m_file.write(m_scratch.data(), m_scratch.size());
Expand Down

0 comments on commit 900ac9a

Please sign in to comment.