File indexing completed on 2025-01-30 09:44:52
0001 #ifndef BOOST_LEAF_COMMON_HPP_INCLUDED
0002 #define BOOST_LEAF_COMMON_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009 #include <boost/leaf/config.hpp>
0010 #include <boost/leaf/detail/demangle.hpp>
0011
0012 #include <iosfwd>
0013 #include <cerrno>
0014
0015 #if BOOST_LEAF_CFG_STD_STRING
0016 # include <string>
0017 #endif
0018
0019 #if BOOST_LEAF_CFG_WIN32
0020 # include <windows.h>
0021 # include <cstring>
0022 # ifdef min
0023 # undef min
0024 # endif
0025 # ifdef max
0026 # undef max
0027 # endif
0028 #endif
0029
0030 namespace boost { namespace leaf {
0031
0032 struct BOOST_LEAF_SYMBOL_VISIBLE e_api_function { char const * value; };
0033
0034 #if BOOST_LEAF_CFG_STD_STRING
0035
0036 struct BOOST_LEAF_SYMBOL_VISIBLE e_file_name
0037 {
0038 std::string value;
0039 };
0040
0041 #else
0042
0043 struct BOOST_LEAF_SYMBOL_VISIBLE e_file_name
0044 {
0045 constexpr static char const * const value = "<unavailable>";
0046 BOOST_LEAF_CONSTEXPR explicit e_file_name( char const * ) { }
0047 };
0048
0049 #endif
0050
0051 struct BOOST_LEAF_SYMBOL_VISIBLE e_errno
0052 {
0053 int value;
0054
0055 explicit e_errno(int val=errno): value(val) { }
0056
0057 template <class CharT, class Traits>
0058 friend std::ostream & operator<<(std::basic_ostream<CharT, Traits> & os, e_errno const & err)
0059 {
0060 return os << type<e_errno>() << ": " << err.value << ", \"" << std::strerror(err.value) << '"';
0061 }
0062 };
0063
0064 struct BOOST_LEAF_SYMBOL_VISIBLE e_type_info_name { char const * value; };
0065
0066 struct BOOST_LEAF_SYMBOL_VISIBLE e_at_line { int value; };
0067
0068 namespace windows
0069 {
0070 struct e_LastError
0071 {
0072 unsigned value;
0073
0074 explicit e_LastError(unsigned val): value(val) { }
0075
0076 #if BOOST_LEAF_CFG_WIN32
0077 e_LastError(): value(GetLastError()) { }
0078
0079 template <class CharT, class Traits>
0080 friend std::ostream & operator<<(std::basic_ostream<CharT, Traits> & os, e_LastError const & err)
0081 {
0082 struct msg_buf
0083 {
0084 LPVOID * p;
0085 msg_buf(): p(nullptr) { }
0086 ~msg_buf() noexcept { if(p) LocalFree(p); }
0087 };
0088 msg_buf mb;
0089 if( FormatMessageA(
0090 FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
0091 nullptr,
0092 err.value,
0093 MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
0094 (LPSTR)&mb.p,
0095 0,
0096 nullptr) )
0097 {
0098 BOOST_LEAF_ASSERT(mb.p != nullptr);
0099 char * z = std::strchr((LPSTR)mb.p,0);
0100 if( z[-1] == '\n' )
0101 *--z = 0;
0102 if( z[-1] == '\r' )
0103 *--z = 0;
0104 return os << type<e_LastError>() << ": " << err.value << ", \"" << (LPCSTR)mb.p << '"';
0105 }
0106 return os;
0107 }
0108 #endif
0109 };
0110 }
0111
0112 } }
0113
0114 #endif