forked from boostorg/assert
Add boost::source_location
This commit is contained in:
69
include/boost/assert/source_location.hpp
Normal file
69
include/boost/assert/source_location.hpp
Normal file
@ -0,0 +1,69 @@
|
||||
#ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED
|
||||
#define BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED
|
||||
|
||||
// http://www.boost.org/libs/assert
|
||||
//
|
||||
// Copyright 2019 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/current_function.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
struct source_location
|
||||
{
|
||||
private:
|
||||
|
||||
char const * file_;
|
||||
char const * function_;
|
||||
boost::uint_least32_t line_;
|
||||
boost::uint_least32_t column_;
|
||||
|
||||
public:
|
||||
|
||||
BOOST_CONSTEXPR source_location() BOOST_NOEXCEPT: file_( "(unknown)" ), function_( file_ ), line_( 0 ), column_( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR source_location( char const * file, boost::uint_least32_t line, char const * function, boost::uint_least32_t column = 0 ) BOOST_NOEXCEPT: file_( file ), function_( function ), line_( line ), column_( column )
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR char const * file_name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return file_;
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR char const * function_name() const BOOST_NOEXCEPT
|
||||
{
|
||||
return function_;
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR boost::uint_least32_t line() const BOOST_NOEXCEPT
|
||||
{
|
||||
return line_;
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR boost::uint_least32_t column() const BOOST_NOEXCEPT
|
||||
{
|
||||
return column_;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#if defined( BOOST_DISABLE_CURRENT_LOCATION )
|
||||
|
||||
# define BOOST_CURRENT_LOCATION ::boost::source_location()
|
||||
|
||||
#else
|
||||
|
||||
# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED
|
@ -27,3 +27,6 @@ run assert_msg_test2.cpp ;
|
||||
run quick.cpp ;
|
||||
|
||||
run current_function_test2.cpp ;
|
||||
|
||||
run source_location_test.cpp ;
|
||||
run source_location_test2.cpp ;
|
||||
|
30
test/source_location_test.cpp
Normal file
30
test/source_location_test.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright 2019 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/assert/source_location.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::source_location loc;
|
||||
|
||||
BOOST_TEST_CSTR_EQ( loc.file_name(), "(unknown)" );
|
||||
BOOST_TEST_CSTR_EQ( loc.function_name(), "(unknown)" );
|
||||
BOOST_TEST_EQ( loc.line(), 0 );
|
||||
BOOST_TEST_EQ( loc.column(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
|
||||
BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ );
|
||||
BOOST_TEST_CSTR_EQ( loc.function_name(), BOOST_CURRENT_FUNCTION );
|
||||
BOOST_TEST_EQ( loc.line(), 20 );
|
||||
BOOST_TEST_EQ( loc.column(), 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
32
test/source_location_test2.cpp
Normal file
32
test/source_location_test2.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright 2019 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#define BOOST_DISABLE_CURRENT_LOCATION
|
||||
|
||||
#include <boost/assert/source_location.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::source_location loc;
|
||||
|
||||
BOOST_TEST_CSTR_EQ( loc.file_name(), "(unknown)" );
|
||||
BOOST_TEST_CSTR_EQ( loc.function_name(), "(unknown)" );
|
||||
BOOST_TEST_EQ( loc.line(), 0 );
|
||||
BOOST_TEST_EQ( loc.column(), 0 );
|
||||
}
|
||||
|
||||
{
|
||||
boost::source_location loc = BOOST_CURRENT_LOCATION;
|
||||
|
||||
|
||||
BOOST_TEST_CSTR_EQ( loc.file_name(), "(unknown)" );
|
||||
BOOST_TEST_CSTR_EQ( loc.function_name(), "(unknown)" );
|
||||
BOOST_TEST_EQ( loc.line(), 0 );
|
||||
BOOST_TEST_EQ( loc.column(), 0 );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user