Used a more uniform of logging and added a commandline parser.
[UnsignedByte.git] / src / Resource / Assert.h
blobc7629f24023c1fea989d30affc3bf6df7c8484e9
1 /***************************************************************************
2 * Copyright (C) 2008 by Vegard Nossum *
3 * vegard.nossum@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #pragma once
23 /**
24 * @file Assert.h
25 * This file contains the Assertion exception and macro.
27 * @see Assertion
28 * @see Assert
29 */
31 #include <exception>
32 #include <string>
34 /**
35 * This exception is thrown when an assertion fails.
36 */
37 class Assertion : public std::exception
39 public:
40 /**
41 * Constructs an assertion with the specified attributes.
43 * @param expr The expression of the assertion that failed.
44 * @param file The file in which the assertion failed.
45 * @param line The line in which the assertion failed.
46 * @param func The function in which the assertion failed.
47 * @param pretty_func A 'pretty' name of the function in which the assertion failed.
48 */
49 Assertion(const char* expr,
50 const char* file, unsigned int line,
51 const char* func, const char* pretty_func);
53 /** Destructor, a noop. */
54 ~Assertion() throw();
56 public:
57 /** Override the msg of this exception to describe the assertion failure.*/
58 const char *what() const throw();
60 private:
61 std::string m_msg; /**< The msg that describes the failed assertion. */
64 /** Assert that x is true, if it is not an Assertion exception is thrown. */
65 #define Assert(x) \
66 if(!(x)) { \
67 throw Assertion("" # x, \
68 __FILE__, __LINE__, \
69 __FUNCTION__, __PRETTY_FUNCTION__); \