LCOV - code coverage report
Current view: top level - co - exception.h (source / functions) Hit Total Coverage
Test: Collage Lines: 0 8 0.0 %
Date: 2016-12-14 01:26:48 Functions: 0 5 0.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2011-2015, Cedric Stalder <cedric.stalder@gmail.com>
       3             :  *                          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             :             CUSTOM      = 20 //!< Application-specific exceptions
      41             :         };
      42             : 
      43             :         /** Construct a new Exception. @version 1.0 */
      44           0 :         explicit Exception( const uint32_t type ) : _type( type ) {}
      45             : 
      46             :         /** Destruct this exception. @version 1.0 */
      47           0 :         virtual ~Exception() throw() {}
      48             : 
      49             :         /** @return the type of this exception @version 1.0 */
      50           0 :         virtual uint32_t getType() const { return _type; }
      51             : 
      52             :         /** Output the exception in human-readable form. @version 1.0 */
      53           0 :         const char* what() const throw() override
      54             :         {
      55           0 :             switch( _type )
      56             :             {
      57             :               case Exception::TIMEOUT_WRITE:
      58           0 :                   return " Timeout on write operation";
      59             :               case Exception::TIMEOUT_READ:
      60           0 :                   return " Timeout on read operation";
      61             :               default:
      62           0 :                   return  " Unknown Exception";
      63             :             }
      64             :         }
      65             : 
      66             :     private:
      67             :         /** The type of this eception instance **/
      68             :         const uint32_t _type;
      69             :     };
      70             : 
      71             :     /** Output the exception in human-readable form. @version 1.0 */
      72             :     inline std::ostream& operator << ( std::ostream& os, const Exception& e )
      73             :         { return os << e.what(); }
      74             : }
      75             : 
      76             : #endif // CO_EXCEPTION_H

Generated by: LCOV version 1.11