/*************************************************************************** * Copyright (C) 2005 by Nicolas PASCAL * * nicolas.pascal@icare.univ-lille1.fr * * * * 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. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef FILE_EXCEPTIONS_H #define FILE_EXCEPTIONS_H #include #include #include #include "tools.h" using namespace std; /** * @class bad_hdf_type thrown when an invalid hdf type is used */ class open_file_error : public exception { public: /** * @brief constructor * @param src_file name of the source code file where the error occurs (ie __FILE__) * @param src_line number of the line of the source code file where the error occurs (ie __LINE__) * @param file name of the file that has been triied to open */ open_file_error(const string &src_file, const int src_line, const string &file): src_file(src_file),src_line(src_line),file(file){}; ~open_file_error() throw() {} ; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m=src_file+"("+MyTools::to_string(src_line)+") : can not open the file "+file; return m.c_str(); }; private: string src_file; int src_line; string file; }; /** * @class bad_temp_file thrown when a temporary file can't be created using the stdlib's mkstemp function */ class bad_temp_file : public exception { public: /** * @brief constructor * @param src_file name of the source code file where the error occurs (ie __FILE__) * @param src_line number of the line of the source code file where the error occurs (ie __LINE__) * @param pattern temp file pattern used (see mkstemp manual for details) */ bad_temp_file(const string &src_file, const int src_line, const string &filename_pattern): src_file(src_file),src_line(src_line),filename_pattern(filename_pattern){}; ~bad_temp_file() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m=src_file+"("+MyTools::to_string(src_line)+") : Temporary File Creation Error with mkstemp using the pattern "+filename_pattern; return m.c_str(); }; private: string src_file; int src_line; string filename_pattern; }; /** * @class file_not_opened thrown when an error occurs when trying to write to an file */ class file_not_opened : public exception { public: file_not_opened(const string &filename):filename(filename) {}; ~file_not_opened() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string msg="file_not_opened : the file "+filename+" is not opened. Can't write to it"; return msg.c_str(); }; private: string filename; }; /** *@class bad_file exception : the specified file couldn't be opened : it doesn't exist, or isn't an HDF one */ class bad_file : public exception { public: bad_file(const string & _s) { s = _s; }; ~bad_file() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m; if (&s != NULL) m="The file "+s+" doesn't exist"; else m="Empty file name"; return m.c_str(); }; private: string s; string mode; }; /** bad_file bad_file_opening_mode : the specified file couldn't be opened. */ class bad_file_opening_mode : public exception { public: bad_file_opening_mode(const string & _file, const string & _mode= string("r")) { file = _file; mode = _mode; }; ~bad_file_opening_mode() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="The file "+file+" can't be opened in mode "+mode+". Check the file's access rights"; return m.c_str(); }; private: string file; string mode; }; /** file_creation_error : the specified file couldn't be created : already exists exist, or bad acces rights */ class file_creation_error : public exception { public: file_creation_error(const std::string & _filename) { filename = _filename; }; ~file_creation_error() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="file_creation_error : the file "+filename+" can't be created"; return m.c_str(); }; private: std::string filename; }; /** Exception thrown when an error occurs during a file opening */ class bad_open_file : public exception { public: bad_open_file(const string filename, string mode) : filename(filename),mode(mode) {}; ~bad_open_file() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="bad_open_file : can't open the file "+filename+" using the mode "+mode; return m.c_str(); }; private: string filename; string mode; }; class empty_parasol_file : public exception { public: empty_parasol_file(const string filename) : filename(filename) {}; ~empty_parasol_file() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw(){ string m="The file :"+filename+" has no valid pixels."; return m.c_str(); }; private: string filename; }; #endif