| 1 | #ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED |
| 2 | #define BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED |
| 3 | |
| 4 | // http://www.boost.org/libs/assert |
| 5 | // |
| 6 | // Copyright 2019 Peter Dimov |
| 7 | // Distributed under the Boost Software License, Version 1.0. |
| 8 | // http://www.boost.org/LICENSE_1_0.txt |
| 9 | |
| 10 | #include <boost/current_function.hpp> |
| 11 | #include <boost/config.hpp> |
| 12 | #include <boost/cstdint.hpp> |
| 13 | #include <iosfwd> |
| 14 | |
| 15 | namespace boost |
| 16 | { |
| 17 | |
| 18 | struct source_location |
| 19 | { |
| 20 | private: |
| 21 | |
| 22 | char const * file_; |
| 23 | char const * function_; |
| 24 | boost::uint_least32_t line_; |
| 25 | boost::uint_least32_t column_; |
| 26 | |
| 27 | public: |
| 28 | |
| 29 | BOOST_CONSTEXPR source_location() BOOST_NOEXCEPT: file_( "(unknown)" ), function_( "(unknown)" ), line_( 0 ), column_( 0 ) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | BOOST_CONSTEXPR source_location( char const * file, boost::uint_least32_t ln, char const * function, boost::uint_least32_t col = 0 ) BOOST_NOEXCEPT: file_( file ), function_( function ), line_( ln ), column_( col ) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | BOOST_CONSTEXPR char const * file_name() const BOOST_NOEXCEPT |
| 38 | { |
| 39 | return file_; |
| 40 | } |
| 41 | |
| 42 | BOOST_CONSTEXPR char const * function_name() const BOOST_NOEXCEPT |
| 43 | { |
| 44 | return function_; |
| 45 | } |
| 46 | |
| 47 | BOOST_CONSTEXPR boost::uint_least32_t line() const BOOST_NOEXCEPT |
| 48 | { |
| 49 | return line_; |
| 50 | } |
| 51 | |
| 52 | BOOST_CONSTEXPR boost::uint_least32_t column() const BOOST_NOEXCEPT |
| 53 | { |
| 54 | return column_; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | template<class E, class T> std::basic_ostream<E, T> & operator<<( std::basic_ostream<E, T> & os, source_location const & loc ) |
| 59 | { |
| 60 | os.width( 0 ); |
| 61 | |
| 62 | if( loc.line() == 0 ) |
| 63 | { |
| 64 | os << "(unknown source location)" ; |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | os << loc.file_name() << ':' << loc.line(); |
| 69 | |
| 70 | if( loc.column() ) |
| 71 | { |
| 72 | os << ':' << loc.column(); |
| 73 | } |
| 74 | |
| 75 | os << ": in function '" << loc.function_name() << '\''; |
| 76 | } |
| 77 | |
| 78 | return os; |
| 79 | } |
| 80 | |
| 81 | } // namespace boost |
| 82 | |
| 83 | #if defined( BOOST_DISABLE_CURRENT_LOCATION ) |
| 84 | |
| 85 | # define BOOST_CURRENT_LOCATION ::boost::source_location() |
| 86 | |
| 87 | #else |
| 88 | |
| 89 | # define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION) |
| 90 | |
| 91 | #endif |
| 92 | |
| 93 | #endif // #ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED |
| 94 | |