Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

matfile/matfile_concepts/src/exceptions.hh
Go to the documentation of this file.
00001 /*
00002     This file is part of matfile.
00003 
00004     Copyright (C) 2010-2011 Andrea Arteaga <arteagaa@student.ethz.ch>
00005 
00006     matfile is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Lesser General Public License as published
00008     by the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     matfile is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public License
00017     along with matfile.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #ifndef EXCEPTIONS_HPP_
00021 #define EXCEPTIONS_HPP_
00022 
00023 
00024 class bad_MAT_code : public std::exception
00025 {
00026   std::string what_;
00027 public:
00028   bad_MAT_code() {
00029     what_ = "The code is not valid. The file could be corrupted.";
00030   }
00031 
00032   virtual ~bad_MAT_code() throw() { }
00033 
00034   virtual const char* what() throw() {
00035     return what_.c_str();
00036   }
00037 };
00038 
00039 
00040 class bad_cast : public std::exception
00041 {
00042   const int type1_, type2_;
00043   std::string what_;
00044 
00045 public:
00046   bad_cast(const int& type1, const int& type2)
00047   : type1_(type1), type2_(type2)
00048   {
00049     std::ostringstream descr;
00050     descr << "Given miMATRIX of class: " << class_to_string(type1) << ", which is not compatile with class: " << class_to_string(type2) << ".";
00051     what_ = descr.str();
00052   }
00053 
00054   virtual ~bad_cast() throw() { }
00055 
00056   virtual const char* what() const throw() {
00057     return what_.c_str();
00058   }
00059 
00060 };
00061 
00062 
00063 class bad_mxNUMARRAY_cast : public std::exception
00064 {
00065   const int type_;
00066   std::string what_;
00067 
00068 public:
00069   bad_mxNUMARRAY_cast(const int& type)
00070   : type_(type)
00071   {
00072     std::ostringstream descr;
00073     descr << "Given miMATRIX of class: " << class_to_string(type) << ", which is not compatile with any numeric class.";
00074     what_ = descr.str();
00075   }
00076 
00077   virtual ~bad_mxNUMARRAY_cast() throw() { }
00078 
00079   virtual const char* what() const throw() {
00080     return what_.c_str();
00081   }
00082 };
00083 
00084 
00085 class bad_mxSTRUCT_cast : public std::exception
00086 {
00087   const int type_;
00088   std::string what_;
00089 
00090 public:
00091   bad_mxSTRUCT_cast(const int& type)
00092   : type_(type)
00093   {
00094     std::ostringstream descr;
00095     descr << "Given miMATRIX of class: " << class_to_string(type) << ", which is not compatible with mxSTRUCT.";
00096     what_ = descr.str();
00097   }
00098 
00099   virtual ~bad_mxSTRUCT_cast() throw() { }
00100 
00101   virtual const char* what() const throw() {
00102     return what_.c_str();
00103   }
00104 };
00105 
00106 class bad_initializator : public std::exception
00107 {
00108   std::string what_;
00109 
00110 public:
00111   bad_initializator() {
00112     what_ = "The used initializator is not valid for this use.";
00113   }
00114 
00115   virtual ~bad_initializator() throw() { }
00116 
00117   virtual const char* what() const throw() {
00118     return what_.c_str();
00119   }
00120 };
00121 
00122 
00123 class class_not_supported : public std::exception
00124 {
00125 public:
00126   class_not_supported(const int& type)
00127   {
00128     std::ostringstream descr;
00129     if (type >= 1 && type <= 13) {
00130       descr << "The class ";
00131       switch(type) {
00132       case 1:
00133         descr << "mxCELL_CLASS";
00134         break;
00135       case 3:
00136         descr << "mxOBJECT_CLASS";
00137         break;
00138       case 4:
00139         descr << "mxCHAR_CLASS";
00140         break;
00141       case 5:
00142         descr << "mxSPARSE_CLASS";
00143         break;
00144       case 8:
00145         descr << "mxINT8_CLASS";
00146         break;
00147       case 9:
00148         descr << "mxUINT8_CLASS";
00149         break;
00150       default:
00151         descr << "(unrecognized class " << type << ")";
00152         break;
00153       }
00154       descr << " is not (yet) supported.";
00155     } else {
00156       descr << "The class you selected is not recognized.";
00157     }
00158     what_ = descr.str();
00159   }
00160 
00161   virtual ~class_not_supported() throw() { }
00162 
00163   virtual const char* what() const throw() {
00164     return what_.c_str();
00165   }
00166 
00167 private:
00168   std::string what_;
00169 };
00170 
00171 
00172 class matrix_type_not_supported : public std::exception
00173 {
00174 private:
00175   std::string what_;
00176 
00177 public:
00178   matrix_type_not_supported(const MATtype& type)
00179   {
00180     std::ostringstream descr;
00181     switch(type) {
00182     case miINT8:
00183       descr << "miINT8";
00184       break;
00185     case miUINT8:
00186       descr << "miUINT8";
00187       break;
00188     case miINT64:
00189       descr << "miINT64";
00190       break;
00191     case miUINT64:
00192       descr << "miUINT64";
00193       break;
00194     case miMATRIX:
00195       descr << "miMATRIX";
00196       break;
00197     case miCOMPRESSED:
00198       descr << "miCOMPRESSED";
00199       break;
00200     case miUTF8:
00201       descr << "miUTF8";
00202       break;
00203     case miUTF16:
00204       descr << "miUTF16";
00205       break;
00206     case miUTF32:
00207       descr << "miUTF32";
00208       break;
00209     default:
00210       descr << "(unrecognized type" << type << ")";
00211     }
00212     descr << " cannot be the type of a matrix";
00213 
00214     what_ = descr.str();
00215   }
00216 
00217   virtual ~matrix_type_not_supported() throw() { }
00218 
00219   virtual const char *what() const throw() {
00220     return what_.c_str();
00221   }
00222 };
00223 
00224 #endif /* EXCEPTIONS_HPP_ */

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)