Line data Source code
1 :
2 : /* Copyright (c) 2011, Cedric Stalder <cedric.stalder@gmail.com>
3 : * 2012-2013, Stefan.Eilemann@epfl.ch
4 : *
5 : * This file is part of Collage <https://github.com/Eyescale/Collage>
6 : *
7 : * This library is free software; you can redistribute it and/or modify it under
8 : * the terms of the GNU Lesser General Public License version 2.1 as published
9 : * by the Free Software Foundation.
10 : *
11 : * This library is distributed in the hope that it will be useful, but WITHOUT
12 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 : * details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public License
17 : * along with this library; if not, write to the Free Software Foundation, Inc.,
18 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : */
20 :
21 : #ifndef CO_EXCEPTION_H
22 : #define CO_EXCEPTION_H
23 :
24 : #include <exception> // base class
25 : #include <iostream>
26 : #include <lunchbox/compiler.h>
27 : #include <lunchbox/types.h>
28 :
29 : namespace co
30 : {
31 : /** A base Exception class for Collage operations. */
32 : class Exception : public std::exception
33 : {
34 : public:
35 : /** The exception type. @version 1.0 */
36 : enum Type
37 : {
38 : TIMEOUT_WRITE, //!< A write timeout operation
39 : TIMEOUT_READ, //!< A read timeout operation
40 : TIMEOUT_BARRIER, //!< A barrier timeout operation
41 : TIMEOUT_COMMANDQUEUE, //!< A timeout on a cmd queue operation
42 : CUSTOM = 20 //!< Application-specific exceptions
43 : };
44 :
45 : /** Construct a new Exception. @version 1.0 */
46 23 : explicit Exception( const uint32_t type ) : _type( type ) {}
47 :
48 : /** Destruct this exception. @version 1.0 */
49 23 : virtual ~Exception() throw() {}
50 :
51 : /** @return the type of this exception @version 1.0 */
52 23 : virtual uint32_t getType() const { return _type; }
53 :
54 : /** Output the exception in human-readable form. @version 1.0 */
55 0 : const char* what() const throw() override
56 : {
57 0 : switch( _type )
58 : {
59 : case Exception::TIMEOUT_WRITE:
60 0 : return " Timeout on write operation";
61 : case Exception::TIMEOUT_READ:
62 0 : return " Timeout on read operation";
63 : case Exception::TIMEOUT_BARRIER:
64 0 : return " Timeout on barrier";
65 : case Exception::TIMEOUT_COMMANDQUEUE:
66 0 : return " Timeout on command queue";
67 : default:
68 0 : return " Unknown Exception";
69 : }
70 : }
71 :
72 : private:
73 : /** The type of this eception instance **/
74 : const uint32_t _type;
75 : };
76 :
77 : /** Output the exception in human-readable form. @version 1.0 */
78 : inline std::ostream& operator << ( std::ostream& os, const Exception& e )
79 : { return os << e.what(); }
80 : }
81 :
82 : #endif // CO_EXCEPTION_H
|