6 * $Date: 2012-07-07 00:03:48 +0200 (Sa, 07. Jul 2012) $
7 ***************************************************************/
10 * \brief Definition of exception classes
12 * \author Carsten Gutwenger, Markus Chimani
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
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
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.
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 ***************************************************************/
48 #include <ogdf/basic/basic.h>
51 #ifndef OGDF_EXCEPTIONS_H
52 #define OGDF_EXCEPTIONS_H
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
70 #ifndef OGDF_THROW_WITH_INFO
71 #define OGDF_THROW_PARAM(CLASS, PARAM) throw CLASS ( PARAM )
72 #define OGDF_THROW(CLASS) throw CLASS ( )
74 //! Replacement for \c throw.
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.
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__ )
93 //! Error code for a violated precondition.
95 * \see PreconditionViolatedException
97 enum PreconditionViolatedCode
{
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
{
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
{
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
{
155 const char *m_file
; //!< Source file where exception occurred.
156 int m_line
; //!< Line number where exception occurred.
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) :
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
{
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
{
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
{
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
220 //! Constructs a precondition violated exception.
221 PreconditionViolatedException(PreconditionViolatedCode code
,
222 const char *file
= NULL
,
224 Exception(file
, line
),
225 m_exceptionCode(code
)
228 //! Constructs a precondition violated exception.
229 PreconditionViolatedException(
230 const char *file
= NULL
,
232 Exception(file
, line
),
233 m_exceptionCode(pvcUnknown
)
236 //! Returns the error code of the exception.
237 PreconditionViolatedCode
exceptionCode() const { return m_exceptionCode
; }
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
250 //! Constructs an algorithm failure exception.
251 AlgorithmFailureException(AlgorithmFailureCode code
,
252 const char *file
= NULL
,
254 Exception(file
, line
),
255 m_exceptionCode(code
)
258 //! Constructs an algorithm failure exception.
259 AlgorithmFailureException(
260 const char *file
= NULL
,
262 Exception(file
, line
),
263 m_exceptionCode(afcUnknown
)
266 //! Returns the error code of the exception.
267 AlgorithmFailureCode
exceptionCode() const { return m_exceptionCode
; }
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
{
278 //! Constructs a library not supported exception.
279 LibraryNotSupportedException(LibraryNotSupportedCode code
,
280 const char *file
= NULL
,
282 Exception(file
, line
),
283 m_exceptionCode(code
)
286 //! Constructs a library not supported exception.
287 LibraryNotSupportedException(
288 const char *file
= NULL
,
290 Exception(file
, line
),
291 m_exceptionCode(lnscUnknown
)
294 //! Returns the error code of the exception.
295 LibraryNotSupportedCode
exceptionCode() const { return m_exceptionCode
; }
298 LibraryNotSupportedCode m_exceptionCode
; //!< The error code specifying the exception.
299 }; // class LibraryNotSupportedException
301 } // end namespace ogdf