Tomographer  v1.0a
Tomographer C++ Framework Documentation
eigen_assert_exception.h
Go to the documentation of this file.
1 /* This file is part of the Tomographer project, which is distributed under the
2  * terms of the MIT license.
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2015 ETH Zurich, Institute for Theoretical Physics, Philippe Faist
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
27 #ifndef TOMOGRAPHER_TOOLS_EIGEN_ASSERT_EXCEPTION_H
28 #define TOMOGRAPHER_TOOLS_EIGEN_ASSERT_EXCEPTION_H
29 
44 #include <string>
45 #include <stdexcept>
46 
47 namespace Tomographer {
48 namespace Tools {
49 
55 {
56  std::string _msg;
57 public:
58  eigen_assert_exception(const std::string& msg, const std::string& file, const std::size_t line)
59  : _msg("eigen_assert() failed: `" + msg + "' at " + file + ", line " + std::to_string(line))
60  {
61  }
62  virtual ~eigen_assert_exception() noexcept {}
63 
64  virtual const char * what() const noexcept { return _msg.c_str(); }
65 };
66 
67 } // namespace Tools
68 } // namespace Tomographer
69 
70 
71 
78 #define eigen_assert_throw_exception(x) \
79  if (!(x)) { throw (::Tomographer::Tools::eigen_assert_exception(#x, __FILE__, __LINE__)); }
80 
81 
82 #ifdef TOMOGRAPHER_EIGEN_ASSERT_EXCEPTION
83 // override Eigen's eigen_assert() macro
84 #undef eigen_assert
85 #define eigen_assert(x) eigen_assert_throw_exception(x)
86 #endif
87 
88 
89 #endif
Base namespace for the Tomographer project.
Definition: dmmhrw.h:51
T to_string(T...args)
Exception that is thrown upon failed eigen_assert.
STL class.
STL class.
T c_str(T...args)