From b43c4af3a777d6baf43a6108764648e52f3b7ea6 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 8 Aug 2016 08:22:03 -1000 Subject: [PATCH] Global error option flag for MemoryReader --- include/athena/MemoryReader.hpp | 3 ++- src/athena/MemoryReader.cpp | 35 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/athena/MemoryReader.hpp b/include/athena/MemoryReader.hpp index d676f05..e09c266 100644 --- a/include/athena/MemoryReader.hpp +++ b/include/athena/MemoryReader.hpp @@ -31,7 +31,7 @@ public: * \param length The length of the existing buffer * \param takeOwnership Memory will be freed with the reader if set */ - MemoryReader(const void* data, atUint64 length, bool takeOwnership=false); + MemoryReader(const void* data, atUint64 length, bool takeOwnership=false, bool globalErr=true); /*! \brief Sets the buffers position relative to the specified position.
* It seeks relative to the current position by default. @@ -89,6 +89,7 @@ protected: atUint64 m_length = 0; atUint64 m_position = 0; bool m_owns = false; + bool m_globalErr = true; }; class MemoryCopyReader : public MemoryReader diff --git a/src/athena/MemoryReader.cpp b/src/athena/MemoryReader.cpp index b8c34dd..211f569 100644 --- a/src/athena/MemoryReader.cpp +++ b/src/athena/MemoryReader.cpp @@ -14,22 +14,25 @@ namespace athena { namespace io { -MemoryReader::MemoryReader(const void* data, atUint64 length, bool takeOwnership) +MemoryReader::MemoryReader(const void* data, atUint64 length, bool takeOwnership, bool globalErr) : m_data(data), m_length(length), m_position(0), - m_owns(takeOwnership) + m_owns(takeOwnership), + m_globalErr(globalErr) { if (!data) { - atError("data cannot be NULL"); + if (m_globalErr) + atError("data cannot be NULL"); setError(); return; } if (length == 0) { - atError("length cannot be 0"); + if (m_globalErr) + atError("length cannot be 0"); setError(); return; } @@ -46,14 +49,16 @@ MemoryCopyReader::MemoryCopyReader(const void* data, atUint64 length) { if (!data) { - atError("data cannot be NULL"); + if (m_globalErr) + atError("data cannot be NULL"); setError(); return; } if (length == 0) { - atError("length cannot be 0"); + if (m_globalErr) + atError("length cannot be 0"); setError(); return; } @@ -70,7 +75,8 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin) case SeekOrigin::Begin: if ((position < 0 || (atInt64)position > (atInt64)m_length)) { - atError("Position %0.8X outside stream bounds ", position); + if (m_globalErr) + atError("Position %0.8X outside stream bounds ", position); setError(); return; } @@ -81,7 +87,8 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin) case SeekOrigin::Current: if ((((atInt64)m_position + position) < 0 || (m_position + position) > m_length)) { - atError("Position %0.8X outside stream bounds ", position); + if (m_globalErr) + atError("Position %0.8X outside stream bounds ", position); setError(); return; } @@ -92,7 +99,8 @@ void MemoryReader::seek(atInt64 position, SeekOrigin origin) case SeekOrigin::End: if ((((atInt64)m_length - position < 0) || (m_length - position) > m_length)) { - atError("Position %0.8X outside stream bounds ", position); + if (m_globalErr) + atError("Position %0.8X outside stream bounds ", position); setError(); return; } @@ -133,7 +141,8 @@ atUint64 MemoryReader::readUBytesToBuf(void* buf, atUint64 length) { if (m_position + length > m_length) { - atError("Position %0.8X outside stream bounds ", m_position); + if (m_globalErr) + atError("Position %0.8X outside stream bounds ", m_position); setError(); return 0; } @@ -151,7 +160,8 @@ void MemoryCopyReader::loadData() if (!in) { - atError("Unable to open file '%s'", m_filepath.c_str()); + if (m_globalErr) + atError("Unable to open file '%s'", m_filepath.c_str()); setError(); return; } @@ -174,7 +184,8 @@ void MemoryCopyReader::loadData() if (ret < 0) { - atError("Error reading data from disk"); + if (m_globalErr) + atError("Error reading data from disk"); setError(); return; }