libGDF
Exceptions.h
00001 //
00002 // This file is part of libGDF.
00003 //
00004 // libGDF is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation, either version 3 of
00007 // the License, or (at your option) any later version.
00008 //
00009 // libGDF is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with libGDF.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // Copyright 2010 Martin Billinger
00018 
00019 #ifndef __EXCEPTIONS_H_INCLUDED__
00020 #define __EXCEPTIONS_H_INCLUDED__
00021 
00022 #include <exception>
00023 #include <stdexcept>
00024 #include <list>
00025 #include <string>
00026 #include <sstream>
00027 
00028 namespace gdf {
00029     namespace exception
00030     {
00031 
00033         class general : public std::exception
00034         {
00035         public:
00036             general( const std::string str ) { msg = str; }
00037             virtual ~general( ) throw() { }
00038             const char *what( ) const throw() { return msg.c_str(); }
00039         private:
00040             std::string msg;
00041         };
00042 
00044         class index_out_of_range : public std::range_error
00045         {
00046         public:
00047             index_out_of_range( std::string str ) : range_error("Index out of range: "+str) { }
00048         };
00049 
00051         class invalid_operation : public std::runtime_error
00052         {
00053         public:
00054             invalid_operation( std::string str ) : runtime_error("Invalid operation: "+str) { }
00055         };
00056 
00058         class empty_container : public std::runtime_error
00059         {
00060         public:
00061             empty_container( std::string str ) : runtime_error("Empty container: "+str) { }
00062         };
00063 
00065         class bad_type_assigned_to_channel : public std::domain_error
00066         {
00067         public:
00068             bad_type_assigned_to_channel( std::string str = "" ) : domain_error("Bad datatype access to channel: "+str) { }
00069         };
00070 
00072         class invalid_type_id : public std::domain_error
00073         {
00074         public:
00075             invalid_type_id( std::string str ) : domain_error("Invalid type ID: "+str) { }
00076         };
00077 
00079         class mixed_types_not_allowed : public std::domain_error
00080         {
00081         public:
00082             mixed_types_not_allowed( std::string str ) : domain_error("Invalid type mix: "+str) { }
00083         };
00084 
00086         class signal_exists_not : public std::domain_error
00087         {
00088         public:
00089             signal_exists_not( std::string str ) : domain_error("Signal does not exist: "+str) { }
00090         };
00091 
00093         class signal_exists : public std::domain_error
00094         {
00095         public:
00096             signal_exists( std::string str ) : domain_error("Signal does exist: "+str) { }
00097         };
00098 
00100         class nonexistent_channel_access : public std::out_of_range
00101         {
00102         public:
00103             nonexistent_channel_access( std::string str ) : out_of_range("Channel does not exist: "+str) { }
00104         };
00105 
00107         class mismatch_channel_number : public std::domain_error
00108         {
00109         public:
00110             mismatch_channel_number( std::string str ) : domain_error("Number of channels mismatch: "+str) { }
00111         };
00112 
00114         class corrupt_recordbuffer : public std::runtime_error
00115         {
00116         public:
00117             corrupt_recordbuffer( std::string str ) : runtime_error("Record buffer corrupted: "+str) { }
00118         };
00119 
00121         class feature_not_implemented : public std::logic_error
00122         {
00123         public:
00124             feature_not_implemented( std::string str ) : logic_error("Feature not implemented: "+str) { }
00125         };
00126 
00128         class file_not_open : public std::invalid_argument
00129         {
00130         public:
00131             file_not_open( std::string str ) : invalid_argument("File is not open: "+str) { }
00132         };
00133 
00135         class file_open : public std::invalid_argument
00136         {
00137         public:
00138             file_open( std::string str ) : invalid_argument("File is open: "+str) { }
00139         };
00140 
00142         class file_exists : public std::invalid_argument
00143         {
00144         public:
00145             file_exists( std::string str ) : invalid_argument("File exists: "+str) { }
00146         };
00147 
00149         class file_exists_not : public std::invalid_argument
00150         {
00151         public:
00152             file_exists_not( std::string str ) : invalid_argument("File does not exists: "+str) { }
00153         };
00154 
00156         class serialization_error : public std::logic_error
00157         {
00158         public:
00159             serialization_error( std::string str ) : logic_error("Serialization error: "+str) { }
00160         };
00161 
00163         class illegal_eventmode_change : public std::domain_error
00164         {
00165         public:
00166             illegal_eventmode_change( std::string str ) : domain_error("Illegal attempt to change event mode: "+str) { }
00167         };
00168 
00170         class invalid_eventmode : public std::domain_error
00171         {
00172         public:
00173             invalid_eventmode( std::string str ) : domain_error("Invalid event mode: "+str) { }
00174         };
00175 
00177         class wrong_eventmode : public std::domain_error
00178         {
00179         public:
00180             wrong_eventmode( std::string str ) : domain_error("Wrong event mode: "+str) { }
00181         };
00182 
00184         class incompatible_gdf_version : public general
00185         {
00186         public:
00187             incompatible_gdf_version (std::string version_of_file) :
00188                     general ("Version \""+version_of_file+"\" not supported!"),
00189                     version_of_file_ (version_of_file) {}
00190 
00191             virtual ~incompatible_gdf_version () throw () {}
00192 
00193             std::string getVersionOfFile () {return version_of_file_;}
00194         private:
00195             std::string version_of_file_;
00196         };
00197 
00199         class header_issues : public std::exception
00200         {
00201         public:
00202             header_issues( std::list< std::string > w, std::list< std::string > e )
00203                 : warnings(w), errors(e)
00204             { }
00205 
00206             header_issues( std::list< std::string > w )
00207                 : warnings(w), errors()
00208             { }
00209 
00210             std::list< std::string > warnings, errors;
00211 
00212             virtual ~header_issues( ) throw() { }
00213 
00214             void generate_message( )
00215             {
00216                 std::stringstream ss;
00217                 std::list< std::string >::const_iterator it;
00218                 if( warnings.size( ) > 0 )
00219                     ss << std::string("Warnings: ") << std::endl;
00220                 for( it=warnings.begin(); it!=warnings.end(); it++ )
00221                     ss << " -> " << *it << std::endl;
00222 
00223                 if( errors.size( ) > 0 )
00224                 {
00225                     ss << "Errors: " << std::endl;
00226                 for( it=errors.begin(); it!=errors.end(); it++ )
00227                     ss << " -> " << *it << std::endl;
00228                 }
00229 
00230                 std::string str = ss.str( );
00231             }
00232 
00233             const char *what( ) const throw()
00234             {
00235                 return str.c_str( );
00236             }
00237 
00238             size_t num_warnings( ) { return warnings.size(); }
00239             size_t num_errors( ) { return errors.size(); }
00240 
00241         private:
00242             std::string str;
00243         };
00244     }
00245 }
00246 
00247 #endif
 All Data Structures Functions Variables Friends