Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / ogdf / basic / exceptions.h
blob32f36a9515e288d44f47d6ed6ca2cd94a827e1cb
1 /*
2 * $Revision: 2564 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-07 00:03:48 +0200 (Sa, 07. Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Definition of exception classes
12 * \author Carsten Gutwenger, Markus Chimani
14 * \par License:
15 * This file is part of the Open Graph Drawing Framework (OGDF).
17 * \par
18 * Copyright (C)<br>
19 * See README.txt in the root directory of the OGDF installation for details.
21 * \par
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
26 * for details.
28 * \par
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * \par
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
43 #ifdef _MSC_VER
44 #pragma once
45 #endif
47 #include <stdio.h>
48 #include <ogdf/basic/basic.h>
51 #ifndef OGDF_EXCEPTIONS_H
52 #define OGDF_EXCEPTIONS_H
55 namespace ogdf {
57 #ifdef OGDF_DEBUG
58 /**
59 * If this flag is set the #OGDF_THROW macros pass the location where the
60 * exception is thrown (file name and line number) to the exception
61 * constructor, otherwise not.
63 #define OGDF_THROW_WITH_INFO
64 #endif
66 #ifdef OGDF_THROW
67 #undef OGDF_THROW
68 #endif
70 #ifndef OGDF_THROW_WITH_INFO
71 #define OGDF_THROW_PARAM(CLASS, PARAM) throw CLASS ( PARAM )
72 #define OGDF_THROW(CLASS) throw CLASS ( )
73 #else
74 //! Replacement for \c throw.
75 /**
76 * This macro is used to throw an exception and pass the file name
77 * and line number of the location in the source file.
78 * @param CLASS is the name of the exception class.
79 * @param PARAM is an additional parameter (like the error code) required
80 * by the exception calls.
82 #define OGDF_THROW_PARAM(CLASS, PARAM) throw CLASS ( PARAM , __FILE__ , __LINE__ )
83 //! Replacement for \c throw.
84 /**
85 * This macro is used to throw an exception and pass the file name
86 * and line number of the location in the source file.
87 * @param CLASS is the name of the exception class.
89 #define OGDF_THROW(CLASS) throw CLASS ( __FILE__ , __LINE__ )
90 #endif
93 //! Error code for a violated precondition.
94 /**
95 * \see PreconditionViolatedException
97 enum PreconditionViolatedCode {
98 pvcUnknown,
99 pvcSelfLoop, //!< graph contains a self-loop
100 pvcTreeHierarchies, //!< hierarchies are not only trees
101 pvcAcyclicHierarchies,//!< hierarchies are not acyclic
102 pvcSingleSource, //!< graph has not a single source
103 pvcUpwardPlanar, //!< graph is not upward planar
104 pvcTree, //!< graph is not a rooted tree
105 pvcForest, //!< graph is not a rooted forest
106 pvcOrthogonal, //!< layout is not orthogonal
107 pvcPlanar, //!< graph is not planar
108 pvcClusterPlanar, //!< graph is not c-planar
109 pvcNoCopy, //!< graph is not a copy of the corresponding graph
110 pvcConnected, //!< graph is not connected
111 pvcBiconnected, //!< graph is not twoconnected
112 pvcSTOP // INSERT NEW CODES BEFORE pvcSTOP!
113 }; // enum PreconditionViolatedCode
116 //! Code for an internal failure condition
118 * \see AlgorithmFailureException
120 enum AlgorithmFailureCode {
121 afcUnknown,
122 afcIllegalParameter, //!< function parameter is illegal
123 afcNoFlow, //!< min-cost flow could not find a legal flow
124 afcSort, //!< sequence not sorted
125 afcLabel, //!< labelling failed
126 afcExternalFace, //!< external face not correct
127 afcForbiddenCrossing,//!< crossing forbidden but necessary
128 afcTimelimitExceeded,//!< it took too long
129 afcNoSolutionFound, //!< couldn't solve the problem
130 afcSTOP // INSERT NEW CODES BEFORE afcSTOP!
131 }; // enum AlgorithmFailureCode
135 //! Code for the library which was intended to get used, but its use is not supported.
137 * \see LibraryNotSupportedException
139 enum LibraryNotSupportedCode {
140 lnscUnknown,
141 lnscCoin, //!< COIN not supported
142 lnscAbacus, //!< ABACUS not supported
143 lnscFunctionNotImplemented, //!< the used library doesn't support that function
144 lnscMissingCallbackImplementation, //
145 lnscSTOP // INSERT NEW CODES BEFORE nscSTOP!
146 }; // enum AlgorithmFailureCode
150 //! Base class of all ogdf exceptions.
151 class OGDF_EXPORT Exception {
153 private:
155 const char *m_file; //!< Source file where exception occurred.
156 int m_line; //!< Line number where exception occurred.
158 public:
159 //! Constructs an exception.
161 * @param file is the name of the source file where exception was thrown.
162 * @param line is the line number in the source file where the exception was thrown.
164 Exception(const char *file = NULL, int line = -1) :
165 m_file(file),
166 m_line(line)
169 //! Returns the name of the source file where exception was thrown.
171 * Returns a null pointer if the name of the source file is unknown.
173 const char *file() { return m_file; }
175 //! Returns the line number where the exception was thrown.
177 * Returns -1 if the line number is unknown.
179 int line() { return m_line; }
183 //! %Exception thrown when result of cast is 0.
184 class OGDF_EXPORT DynamicCastFailedException : public Exception {
186 public:
187 //! Constructs a dynamic cast failed exception.
188 DynamicCastFailedException(const char *file = NULL, int line = -1) : Exception(file, line) {}
192 //! %Exception thrown when not enough memory is available to execute an algorithm.
193 class OGDF_EXPORT InsufficientMemoryException : public Exception {
195 public:
196 //! Constructs an insufficient memory exception.
197 InsufficientMemoryException(const char *file = NULL, int line = -1) : Exception(file, line) {}
201 //! %Exception thrown when a required standard comparer has not been specialized.
203 * The default implementation of StdComparer<E> throws this exception, since it
204 * provides no meaningful implementation of comparer methods. You need to specialize
205 * this class for the types you want to use with sorting and searching methods (like
206 * quicksort and binary search).
208 class OGDF_EXPORT NoStdComparerException : public Exception {
210 public:
211 //! Constructs a no standard comparer available exception.
212 NoStdComparerException(const char *file = NULL, int line = -1) : Exception(file, line) {}
216 //! %Exception thrown when preconditions are violated.
217 class OGDF_EXPORT PreconditionViolatedException : public Exception
219 public:
220 //! Constructs a precondition violated exception.
221 PreconditionViolatedException(PreconditionViolatedCode code,
222 const char *file = NULL,
223 int line = -1) :
224 Exception(file, line),
225 m_exceptionCode(code)
228 //! Constructs a precondition violated exception.
229 PreconditionViolatedException(
230 const char *file = NULL,
231 int line = -1) :
232 Exception(file, line),
233 m_exceptionCode(pvcUnknown)
236 //! Returns the error code of the exception.
237 PreconditionViolatedCode exceptionCode() const { return m_exceptionCode; }
239 private:
240 PreconditionViolatedCode m_exceptionCode; //!< The error code specifying the exception.
241 }; // class PreconditionViolatedException
245 //! %Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
246 class OGDF_EXPORT AlgorithmFailureException : public Exception
248 public:
250 //! Constructs an algorithm failure exception.
251 AlgorithmFailureException(AlgorithmFailureCode code,
252 const char *file = NULL,
253 int line = -1) :
254 Exception(file, line),
255 m_exceptionCode(code)
258 //! Constructs an algorithm failure exception.
259 AlgorithmFailureException(
260 const char *file = NULL,
261 int line = -1) :
262 Exception(file, line),
263 m_exceptionCode(afcUnknown)
266 //! Returns the error code of the exception.
267 AlgorithmFailureCode exceptionCode() const { return m_exceptionCode; }
269 private:
270 AlgorithmFailureCode m_exceptionCode; //!< The error code specifying the exception.
271 }; // class AlgorithmFailureException
275 //! %Exception thrown when an external library shall be used which is not supported.
276 class OGDF_EXPORT LibraryNotSupportedException : public Exception {
277 public:
278 //! Constructs a library not supported exception.
279 LibraryNotSupportedException(LibraryNotSupportedCode code,
280 const char *file = NULL,
281 int line = -1) :
282 Exception(file, line),
283 m_exceptionCode(code)
286 //! Constructs a library not supported exception.
287 LibraryNotSupportedException(
288 const char *file = NULL,
289 int line = -1) :
290 Exception(file, line),
291 m_exceptionCode(lnscUnknown)
294 //! Returns the error code of the exception.
295 LibraryNotSupportedCode exceptionCode() const { return m_exceptionCode; }
297 private:
298 LibraryNotSupportedCode m_exceptionCode; //!< The error code specifying the exception.
299 }; // class LibraryNotSupportedException
301 } // end namespace ogdf
304 #endif