GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Exception.hpp
Go to the documentation of this file.
1 /* ************************************************************************************************************* */
2 /* */
3 /* GLIP-LIB */
4 /* OpenGL Image Processing LIBrary */
5 /* */
6 /* Author : R. Kerviche */
7 /* LICENSE : MIT License */
8 /* Website : glip-lib.net */
9 /* */
10 /* File : Exception.hpp */
11 /* Original Date : August 15th 2011 */
12 /* */
13 /* Description : Exception class */
14 /* */
15 /* ************************************************************************************************************* */
16 
24 #ifndef __GLIP_EXCEPTION__
25 #define __GLIP_EXCEPTION__
26 
27  // Includes
28  #include <iostream>
29  #include <sstream>
30  #include <vector>
31  #include "Core/LibTools.hpp"
32 
33  namespace Glip
34  {
35  // Object
40  class GLIP_API Exception : public std::exception
41  {
42  public :
44  enum Type
45  {
59  ClientException
60  };
61 
62  private :
63  // Data :
64  Type type;
65  std::string message,
66  filename;
67  int line;
68  std::string completeMessage;
69  bool subordinateException,
70  showHeader;
71  std::vector<Exception> subExceptions;
72 
73  // Tools :
74  void cleanSubException(void);
75  std::string header(bool showHeaderControl=true) const;
76  void updateCompleteMessage(void);
77 
78  public :
79  // Tools :
80  Exception(const std::string& m, std::string f="", int l=-1, const Type& t=UnspecifiedException);
81  Exception(const Exception& e);
82  virtual ~Exception(void) throw();
83 
84  Type getType(void) const;
85  const char* what(void) const throw();
86  const std::string& getMessage(void) const throw();
87  const std::string& getFilename(void) const throw();
88  std::string getShortFilename(void) const;
89  int getLineNumber(void) const throw();
90 
91  Exception& operator=(const std::exception& e);
92  Exception& operator=(const Exception& e);
93  Exception& operator<<(const std::exception& e);
94  Exception& operator<<(const Exception& e);
95 
96  void append(const Exception& e);
97  void prepend(const Exception& e);
98  int getNumSubExceptions(void) const throw();
99  const Exception& getSubException(int i);
100  bool isSubException(void) const;
101  void hideHeader(bool enabled=true);
102  bool isHeaderHidden(void) const;
103  };
104 
105  // Tools
113  template<typename TYPE>
114  bool fromString(const std::string & Str, TYPE& Dest)
115  {
116  std::istringstream iss( Str );
117  return static_cast<bool>(iss >> Dest);
118  }
119 
126  template<typename TYPE>
127  std::string toString(const TYPE& Value )
128  {
129  std::ostringstream oss;
130  oss << Value;
131  return oss.str();
132  }
133  }
134 
135 #endif
Specific defines for the API structure.
From a glCall, or similar.
Definition: Exception.hpp:53
From a failed shader compilation, with code provided by the client.
Definition: Exception.hpp:55
From a Module.
Definition: Exception.hpp:51
From a failed script evaluaton, with code provided by the client.
Definition: Exception.hpp:57
Definition: Component.hpp:32
Exception class, derived from std::exception.
Definition: Exception.hpp:40
From a core library component.
Definition: Exception.hpp:49
Unspecified exception (default if not specified).
Definition: Exception.hpp:47
Type
Exception type.
Definition: Exception.hpp:44