File indexing completed on 2025-01-18 09:11:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <exception>
0012 #include <iostream>
0013 #include <sstream>
0014 #include <string>
0015
0016 namespace Acts {
0017
0018
0019 class AssertionFailureException : public std::exception {
0020 public:
0021
0022 class StreamFormatter {
0023 private:
0024 std::ostringstream stream;
0025
0026 public:
0027
0028 operator std::string() const { return stream.str(); }
0029
0030
0031
0032
0033
0034 template <typename T>
0035 StreamFormatter& operator<<(const T& value) {
0036 stream << value;
0037 return *this;
0038 }
0039 };
0040
0041
0042
0043
0044
0045
0046 AssertionFailureException(const std::string& expression,
0047 const std::string& file, int line,
0048 const std::string& msg) {
0049 std::ostringstream os;
0050
0051 if (!msg.empty()) {
0052 os << msg << ": ";
0053 }
0054
0055 os << "Assertion '" << expression << "'";
0056
0057 os << " failed in file '" << file << "' line " << line;
0058 report = os.str();
0059 }
0060
0061
0062 const char* what() const throw() override { return report.c_str(); }
0063
0064 private:
0065 std::string report;
0066 };
0067
0068 }
0069
0070 #define throw_assert(EXPRESSION, MESSAGE) \
0071 do { \
0072 if (!(EXPRESSION)) { \
0073 throw Acts::AssertionFailureException( \
0074 #EXPRESSION, __FILE__, __LINE__, \
0075 (Acts::AssertionFailureException::StreamFormatter() << MESSAGE)); \
0076 } \
0077 } while (0)