Added ability to opt-out of file reader/writer errors

This commit is contained in:
Jack Andersen
2015-11-22 17:08:48 -10:00
parent b0d56910ce
commit 0a4e8c360e
6 changed files with 62 additions and 39 deletions

View File

@@ -13,8 +13,8 @@ namespace io
class FileReader : public IStreamReader
{
public:
FileReader(const std::string& filename, atInt32 cacheSize = (32 * 1024));
FileReader(const std::wstring& filename, atInt32 cacheSize = (32 * 1024));
FileReader(const std::string& filename, atInt32 cacheSize = (32 * 1024), bool globalErr=true);
FileReader(const std::wstring& filename, atInt32 cacheSize = (32 * 1024), bool globalErr=true);
virtual ~FileReader();
inline std::string filename() const
@@ -58,6 +58,7 @@ protected:
atInt32 m_blockSize;
atInt32 m_curBlock;
atUint64 m_offset;
bool m_globalErr;
};
} // io
} // Athena

View File

@@ -11,8 +11,8 @@ namespace io
class FileWriter : public IStreamWriter
{
public:
FileWriter(const std::string& filename, bool overwrite = true);
FileWriter(const std::wstring& filename, bool overwrite = true);
FileWriter(const std::string& filename, bool overwrite = true, bool globalErr=true);
FileWriter(const std::wstring& filename, bool overwrite = true, bool globalErr=true);
virtual ~FileWriter();
inline std::string filename() const
@@ -51,6 +51,7 @@ private:
FILE* m_fileHandle;
atUint8 m_currentByte;
atUint64 m_bytePosition;
bool m_globalErr;
};
}
} // Athena

View File

@@ -104,12 +104,12 @@ namespace Athena
{
namespace error
{
enum Level
enum class Level
{
LevelMessage,
LevelWarning,
LevelError,
LevelFatal
Message,
Warning,
Error,
Fatal
};
}
enum SeekOrigin
@@ -126,7 +126,7 @@ enum Endian
};
} // Athena
typedef void (*atEXCEPTION_HANDLER)(const Athena::error::Level& level, const char* file, const char* function, int line, const char* fmt, ...);
typedef void (*atEXCEPTION_HANDLER)(Athena::error::Level level, const char* file, const char* function, int line, const char* fmt, ...);
atEXCEPTION_HANDLER atGetExceptionHandler();
void atSetExceptionHandler(atEXCEPTION_HANDLER func);
@@ -183,19 +183,19 @@ std::ostream& operator<<(std::ostream& os, const Athena::Endian& endian);
#define atMessage(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(Athena::error::LevelMessage, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
__handler(Athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while(0)
#define atWarning(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(Athena::error::LevelWarning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
__handler(Athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while(0)
#define atError(fmt...) \
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
if (__handler) \
__handler(Athena::error::LevelError, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
__handler(Athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
} while(0)
#define atFatal(fmt...) \