Collage
0.6.1
|
00001 00002 /* Copyright (c) 2011, Cedric Stalder <cedric.stalder@gmail.com> 00003 * 2012, Stefan.Eilemann@epfl.ch 00004 * 00005 * This library is free software; you can redistribute it and/or modify it under 00006 * the terms of the GNU Lesser General Public License version 2.1 as published 00007 * by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this library; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00017 */ 00018 00019 #ifndef CO_EXCEPTION_H 00020 #define CO_EXCEPTION_H 00021 #include <sstream> 00022 00023 namespace co 00024 { 00025 class Exception; 00026 std::ostream& operator << ( std::ostream& os, const Exception& e ); 00027 00029 class Exception : public std::exception 00030 { 00031 public: 00032 enum Type 00033 { 00034 TIMEOUT_WRITE, 00035 TIMEOUT_READ, 00036 TIMEOUT_BARRIER, 00037 TIMEOUT_COMMANDQUEUE, 00038 CUSTOM = 20 // leave some room 00039 }; 00040 00042 Exception( const uint32_t type ) : _type( type ) {} 00043 00045 virtual ~Exception() throw() {} 00046 00048 virtual uint32_t getType() const { return _type; } 00049 00050 virtual const char* what() const throw() 00051 { 00052 std::stringstream os; 00053 os << *this; 00054 return os.str().c_str(); 00055 } 00056 00057 private: 00059 const uint32_t _type; 00060 }; 00061 00062 inline std::ostream& operator << ( std::ostream& os, const Exception& e ) 00063 { 00064 switch( e.getType() ) 00065 { 00066 case Exception::TIMEOUT_WRITE: 00067 return os << " Timeout on write operation"; 00068 case Exception::TIMEOUT_READ: 00069 return os << " Timeout on read operation"; 00070 case Exception::TIMEOUT_BARRIER: 00071 return os << " Timeout on barrier"; 00072 case Exception::TIMEOUT_COMMANDQUEUE: 00073 return os << " Timeout on command queue"; 00074 default: 00075 return os << " Unknown Exception"; 00076 } 00077 } 00078 } 00079 00080 #endif // CO_EXCEPTION_H