File indexing completed on 2025-11-08 09:18:26
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 explicit operator std::string() const { return stream.str(); }
0029
0030
0031
0032
0033
0034
0035 template <typename T>
0036 StreamFormatter& operator<<(const T& value) {
0037 stream << value;
0038 return *this;
0039 }
0040 };
0041
0042
0043
0044
0045
0046
0047 AssertionFailureException(const std::string& expression,
0048 const std::string& file, int line,
0049 const std::string& msg) {
0050 std::ostringstream os;
0051
0052 if (!msg.empty()) {
0053 os << msg << ": ";
0054 }
0055
0056 os << "Assertion '" << expression << "'";
0057
0058 os << " failed in file '" << file << "' line " << line;
0059 report = os.str();
0060 }
0061
0062
0063
0064 const char* what() const throw() override { return report.c_str(); }
0065
0066 private:
0067 std::string report;
0068 };
0069
0070 }
0071
0072 #define throw_assert(EXPRESSION, MESSAGE) \
0073 do { \
0074 if (!(EXPRESSION)) { \
0075 throw Acts::AssertionFailureException( \
0076 #EXPRESSION, __FILE__, __LINE__, \
0077 static_cast<std::string>( \
0078 Acts::AssertionFailureException::StreamFormatter() << MESSAGE)); \
0079 } \
0080 } while (0)