Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
exception.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_EXCEPTION_H_
21 #define OMNI_EXCEPTION_H_
22 
23 #include <QException>
24 #include <QString>
25 #include <omni/Id.h>
26 
27 namespace omni {
28  /// Base class for all exception. Throws a message with QString type
29  class Exception : public QException {
30  public:
31  enum Type {
35  };
36 
37  /// This is the method which throw the message string
38  virtual QString message() const throw() = 0;
39 
40  /// Return type of exception
41  virtual Type type() const = 0;
42 
43  inline virtual QString typeAsString() const {
44  switch (type()) {
45  case WARNING: return "WARNING";
46 
47  case ERROR: return "ERROR";
48 
49  case FATAL: return "FATAL";
50  }
51  return "INVALID";
52  }
53  };
54 
55 #define OMNI_EXCEPTION(EXCEPTION) \
56  inline virtual void raise() const { \
57  throw *this; \
58  } \
59  inline QException *clone() const { \
60  return new EXCEPTION(*this); \
61  }
62 
63  namespace exception {
64  class Warning : public Exception {
65  public:
66  inline Type type() const {
67  return WARNING;
68  }
69  };
70 
71  class Error : public Exception {
72  public:
73  inline Type type() const {
74  return ERROR;
75  }
76  };
77 
78  class Fatal : public Exception {
79  public:
80  inline Type type() const {
81  return FATAL;
82  }
83  };
84 
85  /// An exception that occurs during Serialization
86  class Serialization : public Error {
87  public:
89 
90  Serialization(omni::Id _id) :
91  id_(_id)
92  {}
93 
94  QString message() const throw()
95  {
96  return QString("Serialization Exception. Invalid Id: ") + id_.str();
97  }
98 
99  private:
101  };
102  }
103 
104  using exception::Error;
105  using exception::Warning;
106  using exception::Fatal;
107 }
108 
109 #endif /* OMNI_EXCEPTION_H_ */
Definition: exception.h:78
Id type for classes An Id must only contain alpha numerical characters and must begin with a letter...
Definition: Id.h:34
Definition: exception.h:71
Type type() const
Return type of exception.
Definition: exception.h:80
virtual QString typeAsString() const
Definition: exception.h:43
QString const & str() const
Returns string representation (const)
Definition: Id.cpp:42
QString message() const
This is the method which throw the message string.
Definition: exception.h:94
virtual Type type() const =0
Return type of exception.
#define OMNI_EXCEPTION(EXCEPTION)
Definition: exception.h:55
omni::Id id_
Definition: exception.h:100
Definition: exception.h:64
virtual QString message() const =0
This is the method which throw the message string.
Type
Definition: exception.h:31
Definition: exception.h:34
Base class for all exception. Throws a message with QString type.
Definition: exception.h:29
Type type() const
Return type of exception.
Definition: exception.h:73
Type type() const
Return type of exception.
Definition: exception.h:66
Definition: exception.h:33
Definition: exception.h:32
An exception that occurs during Serialization.
Definition: exception.h:86