# HG changeset patch # User Chris Cannam # Date 1151509324 0 # Node ID b290c43f01ec16a88f0bc03b5390b70d2623e55c # Parent 4e38a29c13fc39c4856ea18c0d5e43005f785292 * Exceptions for file read etc diff -r 4e38a29c13fc -r b290c43f01ec base/Exceptions.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/Exceptions.cpp Wed Jun 28 15:42:04 2006 +0000 @@ -0,0 +1,109 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2006 Chris Cannam. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "Exceptions.h" + +#include + +FileNotFound::FileNotFound(QString file) throw() : + m_file(file) +{ + std::cerr << "ERROR: File not found: " + << file.toStdString() << std::endl; +} + +const char * +FileNotFound::what() const throw() +{ + return QString("File \"%1\" not found") + .arg(m_file).toLocal8Bit().data(); +} + +FailedToOpenFile::FailedToOpenFile(QString file) throw() : + m_file(file) +{ + std::cerr << "ERROR: Failed to open file: " + << file.toStdString() << std::endl; +} + +const char * +FailedToOpenFile::what() const throw() +{ + return QString("Failed to open file \"%1\"") + .arg(m_file).toLocal8Bit().data(); +} + +DirectoryCreationFailed::DirectoryCreationFailed(QString directory) throw() : + m_directory(directory) +{ + std::cerr << "ERROR: Directory creation failed for directory: " + << directory.toStdString() << std::endl; +} + +const char * +DirectoryCreationFailed::what() const throw() +{ + return QString("Directory creation failed for \"%1\"") + .arg(m_directory).toLocal8Bit().data(); +} + +FileReadFailed::FileReadFailed(QString file) throw() : + m_file(file) +{ + std::cerr << "ERROR: File read failed for file: " + << file.toStdString() << std::endl; +} + +const char * +FileReadFailed::what() const throw() +{ + return QString("File read failed for \"%1\"") + .arg(m_file).toLocal8Bit().data(); +} + +FileOperationFailed::FileOperationFailed(QString file, QString op) throw() : + m_file(file), + m_operation(op) +{ + std::cerr << "ERROR: File " << op.toStdString() << " failed for file: " + << file.toStdString() << std::endl; +} + +const char * +FileOperationFailed::what() const throw() +{ + return QString("File %1 failed for \"%2\"") + .arg(m_operation).arg(m_file).toLocal8Bit().data(); +} + +InsufficientDiscSpace::InsufficientDiscSpace(QString directory, + size_t required, + size_t available) throw() : + m_directory(directory), + m_required(required), + m_available(available) +{ + std::cerr << "ERROR: Not enough disc space available in " + << directory.toStdString() << ": need " << required + << ", only have " << available << std::endl; +} + +const char * +InsufficientDiscSpace::what() const throw() +{ + return QString("Not enough space available in \"%1\": need %2, have %3") + .arg(m_directory).arg(m_required).arg(m_available).toLocal8Bit().data(); +} + diff -r 4e38a29c13fc -r b290c43f01ec base/Exceptions.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/Exceptions.h Wed Jun 28 15:42:04 2006 +0000 @@ -0,0 +1,96 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2006 Chris Cannam. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _EXCEPTIONS_H_ +#define _EXCEPTIONS_H_ + +#include + +#include + +class FileNotFound : virtual public std::exception +{ +public: + FileNotFound(QString file) throw(); + virtual ~FileNotFound() throw() { } + virtual const char *what() const throw(); + +protected: + QString m_file; +}; + +class FailedToOpenFile : virtual public std::exception +{ +public: + FailedToOpenFile(QString file) throw(); + virtual ~FailedToOpenFile() throw() { } + virtual const char *what() const throw(); + +protected: + QString m_file; +}; + +class DirectoryCreationFailed : virtual public std::exception +{ +public: + DirectoryCreationFailed(QString directory) throw(); + virtual ~DirectoryCreationFailed() throw() { } + virtual const char *what() const throw(); + +protected: + QString m_directory; +}; + +class FileReadFailed : virtual public std::exception +{ +public: + FileReadFailed(QString file) throw(); + virtual ~FileReadFailed() throw() { } + virtual const char *what() const throw(); + +protected: + QString m_file; +}; + +class FileOperationFailed : virtual public std::exception +{ +public: + FileOperationFailed(QString file, QString operation) throw(); + virtual ~FileOperationFailed() throw() { } + virtual const char *what() const throw(); + +protected: + QString m_file; + QString m_operation; +}; + +class InsufficientDiscSpace : virtual public std::exception +{ +public: + InsufficientDiscSpace(QString directory, + size_t required, size_t available) throw(); + virtual ~InsufficientDiscSpace() throw() { } + virtual const char *what() const throw(); + + size_t getRequired() const { return m_required; } + size_t getAvailable() const { return m_available; } + +protected: + QString m_directory; + size_t m_required; + size_t m_available; +}; + +#endif diff -r 4e38a29c13fc -r b290c43f01ec base/TempDirectory.cpp --- a/base/TempDirectory.cpp Wed Jun 28 13:41:12 2006 +0000 +++ b/base/TempDirectory.cpp Wed Jun 28 15:42:04 2006 +0000 @@ -15,6 +15,7 @@ #include "TempDirectory.h" #include "System.h" +#include "Exceptions.h" #include #include @@ -32,20 +33,6 @@ return m_instance; } -TempDirectory::DirectoryCreationFailed::DirectoryCreationFailed(QString directory) throw() : - m_directory(directory) -{ - std::cerr << "ERROR: Directory creation failed for directory: " - << directory.toLocal8Bit().data() << std::endl; -} - -const char * -TempDirectory::DirectoryCreationFailed::what() const throw() -{ - return QString("Directory creation failed for \"%1\"") - .arg(m_directory).toLocal8Bit().data(); -} - TempDirectory::TempDirectory() : m_tmpdir("") { diff -r 4e38a29c13fc -r b290c43f01ec base/TempDirectory.h --- a/base/TempDirectory.h Wed Jun 28 13:41:12 2006 +0000 +++ b/base/TempDirectory.h Wed Jun 28 15:42:04 2006 +0000 @@ -37,17 +37,6 @@ virtual ~TempDirectory(); - class DirectoryCreationFailed : virtual public std::exception - { - public: - DirectoryCreationFailed(QString directory) throw(); - virtual DirectoryCreationFailed::~DirectoryCreationFailed() throw() { } - virtual const char *what() const throw(); - - protected: - QString m_directory; - }; - /** * Create the root temporary directory if necessary, and return * its path. Throw DirectoryCreationFailed if the directory