/*************************************************************************** * 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 FILEDATAEXCEPTION_H #define FILEDATAEXCEPTION_H #include "date.h" #include "file_tools.h" #include "tools.h" #include "file_exceptions.h" #include "g_exception.h" /** * @class UnimplementedProduct thrown when an invalid hdf type is used */ class UnimplementedProduct : 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 src_method the name of the method that raised the exception */ UnimplementedProduct(const string &src_file, const int src_line, const string & src_method): src_file(src_file),src_line(src_line),src_method(src_method){}; /** * @brief destructor */ ~UnimplementedProduct() 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)+") : Unimplemented Product in "+src_method; return m.c_str(); }; private: /** source file where the error occured */ string src_file; /** line number where the error occured */ int src_line; /** method where the error occured */ string src_method; }; /** * @class UnimplementedMethod thrown when an invalid hdf type is used */ class UnimplementedMethod : 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 src_method the name of the method that raised the exception */ UnimplementedMethod(const string &src_file, const int src_line, const string & src_method): src_file(src_file),src_line(src_line),src_method(src_method){}; /** * @brief destructor */ ~UnimplementedMethod() 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)+") : Unimplemented method "+src_method; return m.c_str(); }; private: /** source file where the error occured */ string src_file; /** line number where the error occured */ int src_line; /** method where the error occured */ string src_method; }; /** * @class bad_hdf_type thrown when an invalid hdf type is used */ class bad_hdf_type : 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 type the type code used */ bad_hdf_type(const string &src_file, const int src_line, const string & type): src_file(src_file),src_line(src_line),type(type){}; ~bad_hdf_type() 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)+") : Bad HDF type used : "+type; return m.c_str(); }; private: string src_file; int src_line; string type; }; /** * @class invalid_filename thrown when a satellite file doesn't have a name matching the nomenclatura */ class invalid_filename : 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 filename name of the file that not matches the nomenclatura * @param sensor name of the sensor the file is issued of */ invalid_filename(const string &src_file, const int src_line, const string & filename,const string & sensor):src_file(src_file),src_line(src_line),filename(filename),sensor(sensor){}; /** * @brief destructor */ ~invalid_filename() 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)+") : Invalid Filename : the file "+filename+" doesn't match a valid "+sensor+" product naming convention"; return m.c_str(); }; private: string src_file; int src_line; string filename; string sensor; }; /** * @class bad_record_index exception thrown when an invalid record index is specified in a PARASOL file */ class bad_record_index : public exception { public: bad_record_index(const string &filename, const int record_idx, const int nb_record_max, const string &source_file, const int source_line) : filename(filename),record_idx(record_idx),nb_record_max(nb_record_max),source_file(source_file),source_line(source_line){}; ~bad_record_index() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { // using namespace MyTools; // for to_string string m=source_file+"("+MyTools::to_string(source_line)+") bad_record_index : the record index "+MyTools::to_string(record_idx)+" can't be accessed in the file "+filename+". It must be in the range [0,"+MyTools::to_string(nb_record_max)+"]"; return m.c_str(); }; private: string filename; int record_idx; int nb_record_max; string source_file; int source_line; }; /** * @class bad_level exception thrown when trying to access a product using a bad level number */ class bad_level : public exception { public: bad_level(const int &level) : level(level){}; ~bad_level() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="bad_level : can't find the level "+level; return m.c_str(); }; private: int level; }; /** * @class bad_level exception thrown when trying to access a product using a bad product id */ class bad_product_id : public exception { public: bad_product_id(const int &product_id) : product_id(product_id){}; ~bad_product_id() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="bad_product_id : unknown product_id "+product_id; return m.c_str(); }; private: int product_id; }; /** * @class bad_parametre exception thrown when a parametre can't be retieved in a file */ class bad_parametre : public exception { public: bad_parametre(const string ¶metre) : parametre(parametre){}; ~bad_parametre() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="bad_parametre : can't find the parametre "+parametre; return m.c_str(); }; private: string parametre; }; /** * @class bad_parametre_idx exception thrown when a parametre can't be retieved in a file */ class bad_parametre_idx : public exception { public: bad_parametre_idx(const int ¶metre_index) : parametre_index(parametre_index){}; ~bad_parametre_idx() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="bad_parametre_idx : can't find a parametre at index "+parametre_index; return m.c_str(); }; private: int parametre_index; }; /** * @class bad_rank Exception bad given rank when reading the data of a file */ class bad_rank : public exception { public: /** * @brief constructor * @param given_rank rank given * @param authorized_rank real rank * @return */ bad_rank(const int & given_rank, const int & authorized_rank) : given_rank(given_rank), authorized_rank(authorized_rank){}; ~bad_rank() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="Bad Rank : "+MyTools::to_string(given_rank)+" : must be "+MyTools::to_string(authorized_rank)+"]"; return m.c_str(); }; private: int given_rank; int authorized_rank; }; /** * @class bad_index Exception Index overflow when accessing to a sds data */ class bad_index : public exception { public: /** * @brief constructor * @param _index index to acces * @param _index_max max allowed index */ bad_index(const long long & _index, const long long & _index_max) { index = _index; index_max = _index_max; }; ~bad_index() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="Bad index : "+MyTools::to_string(index)+". It must be in the range [0,"+MyTools::to_string(index_max)+"]"; return m.c_str(); }; private: long long index; long long index_max; }; /** * @class bad_type Type incompatibility when accessing to a sds data. * For example, calling the template method getValue\ on an sds that contains \ values will throw this exception */ class bad_type : public exception { public: bad_type(const string & t1, const string & t2, const string & _sds) { invocatedType = t1; realType = t2; sds = _sds; }; ~bad_type() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="bad_type : The data' type in the sds "+sds+" is "+realType+" and you are using "+invocatedType; return m.c_str(); }; private: string invocatedType; string realType; string sds; }; /** * @class longitude_out_of_file Thrown when a longitude can't be found in a file's data */ class longitude_out_of_file : public exception { public: longitude_out_of_file(const string & _filename, const double &_lon):filename(filename),lon(lon) {}; ~longitude_out_of_file() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="longitude_out_of_file : the longitude "+MyTools::to_string(lon)+" can't be found in the file "+filename; return m.c_str(); }; private: string filename; double lon; }; /** * @class latitude_out_of_file Thrown when a latitude can't be found in a file's data */ class latitude_out_of_file : public exception { public: latitude_out_of_file(const string & filename, const double &lat):filename(filename),lat(lat) {}; ~latitude_out_of_file() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="latitude_out_of_file : the latitude "+MyTools::to_string(lat)+" can't be found in the file "+filename; return m.c_str(); }; private: string filename; double lat; }; /** * @class bad_read_file Exception thrown when an error occurs while reading a file */ class bad_read_file : public exception { public: bad_read_file(const string &filename) : filename(filename){}; ~bad_read_file() throw() {}; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="bad_read_file : can't read the data of the file "+filename; return m.c_str(); }; private: string filename; }; /** * @class bad_netcdf_file Thrown when a netcdf filename doesn't seem to be valid and can't be opened */ class bad_netcdf_file : public exception { public: bad_netcdf_file(const string & filename):filename(filename){}; ~bad_netcdf_file() throw() {} ; /** * @brief accessor to the error message * @return the error message */ virtual const char* what() const throw() { string m="bad_netcdf_file : can't open "+filename+" as a netcdf one"; return m.c_str(); }; private: string filename; }; #endif