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