/*************************************************************************** * Copyright (C) 2005 by Nicolas PASCAL * * pascal@icare-pc15 * * * * 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 HDF_EXCEPTIONS_H #define HDF_EXCEPTIONS_H #include #include #include #include "Hdf_common.hpp" #include "mfhdf.h" using namespace std; /** * @class hdfcpp_exception Hdf_exceptions.hpp * @brief Generic HDFCPP library exception class */ class hdfcpp_exception : public exception { /** file where the exception has been raised */ string file; /** line where the exception has been raised */ long line; /** exception message */ string msg; public: /** * @brief constructor * @param file file of the exception * @param line line of the exception * @param msg message of the exception */ hdfcpp_exception( const char* file, long line, string msg = "" ) : file(file) , line(line) , msg(msg) { }; /** * @brief destructor */ virtual ~hdfcpp_exception() throw() { }; /** * @brief print the message of the exception * @return the description of the exception */ virtual const char * what() const throw() { ostringstream oss; oss << file << "[" << line << "] : " << msg; return oss.str().c_str(); } }; /** bad_hdf_file exception : the specified file couldn't be opened : it doesn't exist, or isn't an HDF one */ class bad_hdf_file : public exception { public: bad_hdf_file(const string & _s) { s = _s; }; ~bad_hdf_file() throw() {} ; virtual const char* what(void) const throw() { string m; if (&s != NULL) m="bad_hdf_file : The file "+s+" can't be found or invalid HDF file"; else m="Empty file name"; return m.c_str(); }; private: string s; }; /** bad_hdf_file_opening_mode : the specified file couldn't be opened in the given mode. */ class bad_hdf_file_opening_mode : public exception { public: bad_hdf_file_opening_mode(const string & _file, const string & _mode= string("r")) { file = _file; mode = _mode; }; ~bad_hdf_file_opening_mode() throw() {} ; virtual const char* what(void) 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; }; class bad_close_file : public exception { public: bad_close_file(const string & file):file(file) {}; ~bad_close_file() throw() {} ; virtual const char* what(void) const throw() { string m="bad_close_file : can't properly close the file "+file; return m.c_str(); }; private: string file; }; class bad_hdf_compression : public exception { public: bad_hdf_compression(const char *_file, const char *_sds, const int32 _code) { file = _file; sds = _sds; code = _code; } ~bad_hdf_compression() throw() {} virtual const char* what(void) const throw() { string m = "bad_hdf_compression : failed to compress dataset "+sds+" using the compression code "; if (code==COMP_CODE_NONE) m+=string("COMP_CODE_NONE"); else if (code==COMP_CODE_DEFLATE) m+=string("COMP_CODE_DEFLATE (gzip)"); else if (code==COMP_CODE_SKPHUFF) m+=string("COMP_CODE_SKPHUFF (huffman)"); else m+=string("UNKNOWN"); return m.c_str(); } private: string file; string sds; int32 code; }; class bad_chunk_creation : public exception { public: bad_chunk_creation(const char *_file, const char *_sds) :file(_file),sds(_sds){} ~bad_chunk_creation() throw() {} virtual const char* what(void) const throw() { string m="bad_chunk_creation : failed to create chunk for sds "+sds+" in file "+file; return m.c_str(); } private: string file; string sds; }; class bad_sd_file_info : public exception { public: bad_sd_file_info(const char* _filename) { filename=_filename; }; ~bad_sd_file_info() throw() {} ; virtual const char* what(void) const throw() { string m="bad_sd_file_info : Can't read the sd file info for "+filename; return m.c_str(); }; private: string filename; }; class bad_sd_attr_info : public exception { public: bad_sd_attr_info(const char* _attr_name) { attr_name=_attr_name; }; ~bad_sd_attr_info() throw() {} ; virtual const char* what(void) const throw() { string m="bad_sd_attr_info : Can't read the sd attribute "+attr_name; return m.c_str(); }; private: string attr_name; }; class bad_sd_get_info : public exception { public: bad_sd_get_info(const char* _sds_name) { sds_name=_sds_name; }; ~bad_sd_get_info() throw() {} ; virtual const char* what(void) const throw() { string m="bad_sd_get_info : can't get the info from the sds "+sds_name; return m.c_str(); }; private: string sds_name; }; class bad_sd_create : public exception { public: bad_sd_create(const char* _filename) { filename=_filename; }; ~bad_sd_create() throw() {} ; virtual const char* what(void) const throw() { string m="bad_sd_create : can't create the sd for the file "+filename; return m.c_str(); }; private: string filename; }; class bad_hdf_typecode : public exception { public: bad_hdf_typecode(const int32& typecode) : typecode(typecode){}; ~bad_hdf_typecode() throw() {}; virtual const char* what(void) const throw() { string m="bad_hdf_typecode : unknown hdf type code "+Hdf_common::to_string(typecode); return m.c_str(); }; private: int32 typecode; }; class bad_sd_set_fill_mode : public exception { public: bad_sd_set_fill_mode(const char* _filename, const int32 _fill_mode) { filename=_filename; fill_mode=_fill_mode; }; ~bad_sd_set_fill_mode() throw() {} ; virtual const char* what(void) const throw() { string m="Can't set the sd fill mode for the file "+filename+" to "; switch (fill_mode) { case SD_FILL: m+="SD_FILL";break; case SD_NOFILL: m+="SD_NOFILL";break; default: m+="the unknown mode : "+Hdf_common::to_string(fill_mode)+". Must be SD_FILL or SD_NOFILL";break; } return m.c_str(); }; private: string filename; int32 fill_mode; }; class bad_sds_name : public exception { public: bad_sds_name(const char* _filename, const char* _sds_name) { filename=_filename; sds_name=_sds_name; }; ~bad_sds_name() throw() {} ; virtual const char* what(void) const throw() { string m="bad_sds_name : can't find the sds "+sds_name+" in file "+filename; return m.c_str(); }; private: string filename; string sds_name; }; class bad_set_file_attribute : public exception { public: bad_set_file_attribute(const char* _filename, const char* _attr_name) { filename=_filename; attr_name=_attr_name; }; ~bad_set_file_attribute() throw() {} ; virtual const char* what(void) const throw() { string m="bad_set_file_attribute : can't set the attribute "+attr_name+" in file "+filename; return m.c_str(); }; private: string filename; string attr_name; }; class bad_set_sds_attribute : public exception { public: bad_set_sds_attribute(const char* _filename, const char* _sds_name, const char* _attr_name) { filename=_filename; sds_name=_sds_name; attr_name=_attr_name; }; ~bad_set_sds_attribute() throw() {} ; virtual const char* what(void) const throw() { string m="bad_set_sds_attribute : in file "+filename+" : can't set the attribute "+attr_name+" for the sds "+sds_name; return m.c_str(); }; private: string filename; string sds_name; string attr_name; }; class bad_get_sds_attribute : public exception { public: bad_get_sds_attribute(const char* _filename, const char* _sds_name, const char* _attr_name) { filename=_filename; sds_name=_sds_name; attr_name=_attr_name; }; ~bad_get_sds_attribute() throw() {} ; virtual const char* what(void) const throw() { string m="bad_get_sds_attribute : in file "+filename+" : can't read the attribute "+attr_name+" for the sds "+sds_name; return m.c_str(); }; private: string filename; string sds_name; string attr_name; }; class bad_sds_attribute : public exception { // thrown inside Hdf_sds, per opposition to bad_get_sds_attribute that is thrown by Hdf_file (higher level) public: bad_sds_attribute(const char* _sds_name, const char* _attr_name) { sds_name=_sds_name; attr_name=_attr_name; }; ~bad_sds_attribute() throw() {}; virtual const char* what(void) const throw() { string m="bad_sds_attribute : the sds "+sds_name+" doesn't have an attribute named "+attr_name; return m.c_str(); }; private: string sds_name; string attr_name; }; class bad_sd_select : public exception { public: bad_sd_select(const int32 _sds_index) { sds_index=_sds_index; }; ~bad_sd_select() throw() {} ; virtual const char* what(void) const throw() { string m="bad_sd_select : can't select the sds "+sds_index; return m.c_str(); }; private: int32 sds_index; }; class bad_sd_end_access : public exception { public: bad_sd_end_access(void) { }; ~bad_sd_end_access() throw() {} ; virtual const char* what(void) const throw() { string m="bad_sd_end_access : can't end correctly the accessed sd"; return m.c_str(); }; }; class bad_sd_end : public exception { public: bad_sd_end(void) { }; ~bad_sd_end() throw() {} ; virtual const char* what(void) const throw() { string m="bad_sd_end : Can't close properly the opened sd"; return m.c_str(); }; }; class sd_create_error : public exception { string filename; string sds_name; string error; public: sd_create_error(const string & _filename, const string &_sds_name, const string & _error){ filename=_filename; sds_name=_sds_name; error=_error; }; ~sd_create_error() throw() {} ; virtual const char* what(void) const throw() { string m="sd_create_error : while creating the sds "+sds_name+" in the file "+filename+" : "+error; return m.c_str(); }; }; class sd_write_data_error : public exception { string filename; string sds_name; string error; public: sd_write_data_error(const string & _filename, const string &_sds_name, const string & _error){ filename=_filename; sds_name=_sds_name; error=_error; }; ~sd_write_data_error() throw() {} ; virtual const char* what(void) const throw() { string m="sd_write_data_error : while writing the sds "+sds_name+" in the file "+filename+" : "+error; return m.c_str(); }; }; class sd_get_fill_value_error : public exception { string sds_name; public: sd_get_fill_value_error(const string &_sds_name){ sds_name=_sds_name; }; ~sd_get_fill_value_error() throw() {} ; virtual const char* what(void) const throw() { string m="sd_get_fill_value_error while reading the sds "+sds_name+". Perhaps : \n- the fill value hasn't been set for this sds\n- has a bad type\n- the fill_value output parametre is NULL"; return m.c_str(); }; }; class sd_set_fill_value_error : public exception { string sds_name; public: sd_set_fill_value_error(const string &_sds_name){ sds_name=_sds_name; }; ~sd_set_fill_value_error() throw() {} ; virtual const char* what(void) const throw() { string m="sd_set_fill_value_error in the sds "+sds_name+". Perhaps : \n- the fill value has a bad type\n- the fill_value parametre is NULL"; return m.c_str(); }; }; class sd_get_calibration_error : public exception { string sds_name; public: sd_get_calibration_error(const string &_sds_name){ sds_name=_sds_name; }; ~sd_get_calibration_error() throw() {} ; virtual const char* what(void) const throw() { string m="sd_get_calibration_error while reading the sds "+sds_name; return m.c_str();; }; }; class read_sds_error : public exception { string filename; int32 sds_index; string error_code; public: read_sds_error(const string &filename,const int32 &sds_index,const string &error_code) : filename(filename),sds_index(sds_index),error_code(error_code){}; ~read_sds_error() throw() {}; virtual const char* what(void) const throw() { string m="read_sds_error : in "+filename +" at sds index "+ Hdf_common::to_string(sds_index) +" : error "+error_code ; return m.c_str(); }; }; // class bad_attribute_name : public exception { // public: // bad_attribute_name(const string &filename, const string &attribute_name) : filename(filename),attribute_name(attribute_name){}; // ~bad_attribute_name() throw() {}; // virtual const char* what(void) const throw() { // string m="bad_attribute_name : can't find the attribute "+attribute_name+" in file "+filename; // return m.c_str(); // }; // private: // string filename; // string attribute_name; // }; class bad_vs_initialisation : public exception { public: bad_vs_initialisation(const string &filename) : filename(filename){}; ~bad_vs_initialisation() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_initialisation : can't initialize the VS interface for file "+filename; return m.c_str(); }; private: string filename; }; class bad_v_end : public exception { public: bad_v_end(const string &filename) : filename(filename){}; ~bad_v_end() throw() {}; virtual const char* what(void) const throw() { string m="bad_v_end : can't properly terminate the VS interface access the file "+filename; return m.c_str(); }; private: string filename; }; class bad_v_start : public exception { public: bad_v_start(const string &filename) : filename(filename){}; ~bad_v_start() throw() {}; virtual const char* what(void) const throw() { string m="bad_v_start : can't initialize the VS interface for the file "+filename; return m.c_str(); }; private: string filename; }; class bad_vs_lone : public exception { public: bad_vs_lone(const string &filename) : filename(filename){}; ~bad_vs_lone() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_lone : can't retrieve the lone VD references for file "+filename; return m.c_str(); }; private: string filename; }; class bad_vs_attach : public exception { public: bad_vs_attach(const string &filename, const int32& vs_idx, const string& mode) : filename(filename),vs_idx(vs_idx),mode(mode){}; ~bad_vs_attach() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_attach : can't attach the vdata of index "+Hdf_common::to_string(vs_idx)+" in mode "+mode+" for file "+filename; return m.c_str(); }; private: string filename; int32 vs_idx; string mode; }; class bad_vs_detach : public exception { public: bad_vs_detach(const string &filename, const int32& vd_id) : filename(filename),vd_id(vd_id){}; ~bad_vs_detach() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_detach : can't detach the vdata with id "+Hdf_common::to_string(vd_id)+" for file "+filename; return m.c_str(); }; private: string filename; int32 vd_id; }; class bad_vs_inquire : public exception { public: bad_vs_inquire(const string &filename, const int32& vs_idx) : filename(filename),vs_id(vs_id){}; ~bad_vs_inquire() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_inquire : can't inquire the infos of the VData of id "+Hdf_common::to_string(vs_id)+" in file "+filename; return m.c_str(); }; private: string filename; int32 vs_id; }; class bad_vs_getclass : public exception { public: bad_vs_getclass(const string &filename, const int32& vs_id) : filename(filename),vs_id(vs_id){}; ~bad_vs_getclass() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_getclass : can't access the class info in the VData of id "+Hdf_common::to_string(vs_id)+" in file "+filename; return m.c_str(); }; private: string filename; int32 vs_id; }; class bad_field_type : public exception { public: bad_field_type(const string &vd_name,const string &fieldname) : fieldname(fieldname),vd_name(vd_name){}; ~bad_field_type() throw() {}; virtual const char* what(void) const throw() { string m="bad_field_type : can't read the type of the field named "+fieldname+" in VData "+vd_name; return m.c_str(); }; private: string fieldname; string vd_name; }; class bad_field_order : public exception { public: bad_field_order(const string &vd_name,const string &fieldname) : fieldname(fieldname),vd_name(vd_name){}; ~bad_field_order() throw() {}; virtual const char* what(void) const throw() { string m="bad_field_order : can't read the order of the field named "+fieldname+" in VData "+vd_name; return m.c_str(); }; private: string fieldname; string vd_name; }; class bad_field_size : public exception { public: bad_field_size(const string &vd_name,const string &fieldname) : fieldname(fieldname),vd_name(vd_name){}; ~bad_field_size() throw() {}; virtual const char* what(void) const throw() { string m="bad_field_size : can't read the size of the field named "+fieldname+" in VData "+vd_name; return m.c_str(); }; private: string fieldname; string vd_name; }; class bad_vs_attr_info : public exception { public: bad_vs_attr_info(const string &vd_name,const int32 &field_index,const int32 &attr_index) : vd_name(vd_name),field_index(field_index),attr_index(attr_index){}; ~bad_vs_attr_info() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_attr_info : can't read the attribute informations in the VData named "+vd_name; if (field_index!=-1) // infos specific to a given field m+=" of the field of index "+Hdf_common::to_string(field_index); if (field_index!=-1) // infos specific to a given attribute m+=" for the attribute of index "+Hdf_common::to_string(attr_index); return m.c_str(); }; private: string vd_name; int32 field_index; intn attr_index; }; class bad_vs_fnattrs : public exception { public: bad_vs_fnattrs(const string &vd_name,const int32 &field_index) : vd_name(vd_name),field_index(field_index){}; ~bad_vs_fnattrs() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_fnattrs : can't find the number of attributes "+vd_name; if (field_index!=-1) // infos specific to a given field m+=" of the field of index "+Hdf_common::to_string(field_index); return m.c_str(); }; private: string vd_name; int32 field_index; }; class bad_vf_nfields : public exception { public: bad_vf_nfields(const string &filename,const string &vd_name) : filename(filename),vd_name(vd_name){}; ~bad_vf_nfields() throw() {}; virtual const char* what(void) const throw() { string m="bad_vf_nfields : can't find the number of fields for vdata "+vd_name+" in "+filename; return m.c_str(); }; private: string filename; string vd_name; }; class bad_attribute_index : public exception { public: bad_attribute_index(const string &parent_name,const int32 &attr_idx,const attribute_parent& parent) : parent_name(parent_name),attr_idx(attr_idx),parent(parent){}; ~bad_attribute_index() throw() {}; virtual const char* what(void) const throw() { string m="bad_attribute_index : can't find the attribute of index "+Hdf_common::to_string(attr_idx)+" in "; if (parent==HDF_FILE) m+=" the file "+parent_name; else if (parent==SDS) m+=" the sds "+parent_name; else if (parent==VDATA) m+=" the VData "+parent_name; else if (parent==VDATA_FIELD) m+=" the VData Field "+parent_name; else m+=" an UNKNOWN parent"; return m.c_str(); }; private: string parent_name; int32 attr_idx; attribute_parent parent; }; class bad_attribute_name : public exception { public: bad_attribute_name(const string &parent_name,const char* &attr_name,const attribute_parent& parent) : parent_name(parent_name),attr_name(attr_name),parent(parent){}; ~bad_attribute_name() throw() {}; virtual const char* what(void) const throw() { string m="bad_attribute_name : can't find the attribute of name "+attr_name+" in "; if (parent==HDF_FILE) m+=" the file "+parent_name; else if (parent==SDS) m+=" the sds "+parent_name; else if (parent==VDATA) m+=" the VData "+parent_name; else if (parent==VDATA_FIELD) m+=" the VData Field "+parent_name; else m+=" an UNKNOWN parent"; return m.c_str(); }; private: string parent_name; string attr_name; attribute_parent parent; }; class bad_vd_index : public exception { public: bad_vd_index(const string &filename,const int32 &vd_idx) : filename(filename),vd_idx(vd_idx){}; ~bad_vd_index() throw() {}; virtual const char* what(void) const throw() { string m="bad_vd_index : can't find the vd of index "+Hdf_common::to_string(vd_idx)+" in "+filename; return m.c_str(); }; private: string filename; int32 vd_idx; }; class bad_vd_name : public exception { public: bad_vd_name(const string &filename,const char* &vd_name) : filename(filename),vd_name(vd_name){}; ~bad_vd_name() throw() {}; virtual const char* what(void) const throw() { string m="bad_vd_name : can't find the vd of name "+vd_name+" in "+filename; return m.c_str(); }; private: string filename; string vd_name; }; class bad_field_index : public exception { public: bad_field_index(const string &vd_name,const int32 &field_idx) : vd_name(vd_name),field_idx(field_idx){}; ~bad_field_index() throw() {}; virtual const char* what(void) const throw() { string m="bad_field_index : can't find the field of index "+Hdf_common::to_string(field_idx)+" in VData "+vd_name; return m.c_str(); }; private: string vd_name; int32 field_idx; }; class bad_field_name : public exception { public: bad_field_name(const string &vd_name,const string &field_name) : vd_name(vd_name),field_name(field_name){}; ~bad_field_name() throw() {}; virtual const char* what(void) const throw() { string m="bad_field_name : can't find the field named "+field_name+" in VData "+vd_name; return m.c_str(); }; private: string vd_name; string field_name; }; class bad_vs_setfields : public exception { public: bad_vs_setfields(const string &filename,const string &vd_name,const string &field_name) : filename(filename),vd_name(vd_name),field_name(field_name){}; ~bad_vs_setfields() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_setfields : can't find the field "+field_name+" in VData "+vd_name+" in "+filename; return m.c_str(); }; private: string filename; string vd_name; string field_name; }; class bad_vs_seek : public exception { public: bad_vs_seek(const string &filename,const string &vd_name,const int32& position) : filename(filename),vd_name(vd_name),position(position){}; ~bad_vs_seek() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_seek : can't seek the position "+Hdf_common::to_string(position)+" in VData "+vd_name+" in "+filename; return m.c_str(); }; private: string filename; string vd_name; int32 position; }; class bad_vs_read : public exception { public: bad_vs_read(const string &filename,const string &vd_name,const int32& nb_values) : filename(filename),vd_name(vd_name),nb_values(nb_values){}; ~bad_vs_read() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_read : can't read "+Hdf_common::to_string(nb_values)+" values in VData "+vd_name+" in "+filename; return m.c_str(); }; private: string filename; string vd_name; int32 nb_values; }; class bad_vs_fpack : public exception { public: bad_vs_fpack(const string &filename,const string &vd_name,const string &field_name) : filename(filename),vd_name(vd_name),field_name(field_name){}; ~bad_vs_fpack() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_fpack : can't pack/unpack the datas of the field "+field_name+" in VData "+vd_name+" in "+filename; return m.c_str(); }; private: string filename; string vd_name; string field_name; }; class bad_sd_read_attr : public exception { public: bad_sd_read_attr(const string &attrname) : attrname(attrname){}; ~bad_sd_read_attr() throw() {}; virtual const char* what(void) const throw() { string m="bad_sd_read_attr : can't read the SD attribute "+attrname; return m.c_str(); }; private: string attrname; }; class bad_vs_get_attr : public exception { public: bad_vs_get_attr(const string &attrname) : attrname(attrname){}; ~bad_vs_get_attr() throw() {}; virtual const char* what(void) const throw() { string m="bad_vs_get_attr : can't read the VData attribute "+attrname; return m.c_str(); }; private: string attrname; }; #endif