Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
glfException.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef __glfException_hh__
26 #define __glfException_hh__
27 
28 #include "glfCommon.hh"
29 #include <string>
30 #include <sstream>
31 
32 namespace BIAS {
33 
34  /**
35  * Utility macro for throwing a glfException.
36  * Use like BIASERR:
37  * <code>GLF_THROW_EXCEPTION("xyz" << i << "123");</code>
38  */
39  #define GLF_THROW_EXCEPTION(MESSAGE) \
40  { \
41  std::stringstream msg; \
42  msg << MESSAGE; \
43  throw glfException(__FILE__, __LINE__, msg.str()); \
44  }
45 
46  /**
47  * Throws a glfException if an OpenGL error occured.
48  */
49  #define GLF_THROW_ON_OPENGL_ERROR \
50  { \
51  GLenum err = glGetError(); \
52  if (err != GL_NO_ERROR) { \
53  GLF_THROW_EXCEPTION("OpenGL Error: " << gluErrorString(err)); \
54  } \
55  }
56 
57 #ifdef BIAS_DEBUG
58 #define GLF_THROW_ON_OPENGL_ERROR_DEBUG GLF_THROW_ON_OPENGL_ERROR
59 #else
60 #define GLF_THROW_ON_OPENGL_ERROR_DEBUG
61 #endif
62 
63  /**
64  * Throws an glfException if an OpenGL error occured.
65  */
66  #define GLF_THROW_ON_OPENGL_ERROR_INFO(MESSAGE) \
67  { \
68  GLenum err = glGetError(); \
69  if (err != GL_NO_ERROR) { \
70  GLF_THROW_EXCEPTION("["<<MESSAGE<<"] OpenGL Error: " << gluErrorString(err)); \
71  } \
72  }
73 
74  /**
75  * \brief Exception class used for run-time errors in the OpenGLFramework.
76  * \ingroup g_openglframework
77  * \author jkollmann
78  */
79  class BIASOpenGLFramework_EXPORT glfException
80  {
81  public:
82 
83  /**
84  * Exception constructor.
85  * \param fileName File name of source code file where the error occured.
86  * \param lineNumber Line number in source code file where the error occured.
87  * \param message Description of the error.
88  */
89  glfException(const std::string& fileName,
90  int lineNumber,
91  const std::string& message);
92 
93  /**
94  * Returns the source code file name where the error occured.
95  */
96  const std::string& GetFileName() const;
97 
98  /**
99  * Returns the line number in the source code file where the error occured.
100  */
101  int GetLineNumber() const;
102 
103  /**
104  * Returns the description of the error including the file name and line number
105  * where the error occured.
106  */
107  const std::string& GetMessageString() const;
108 
109  private:
110  std::string fileName_;
111  int lineNumber_;
112  std::string message_;
113  };
114 
115 } // namespace BIAS
116 
117 #endif // __glfException_hh__
Exception class used for run-time errors in the OpenGLFramework.
Definition: glfException.hh:79