File indexing completed on 2025-09-15 08:39:07
0001 #ifndef BOOST_LEAF_DETAIL_CAPTURE_LIST_HPP_INCLUDED
0002 #define BOOST_LEAF_DETAIL_CAPTURE_LIST_HPP_INCLUDED
0003
0004
0005
0006
0007
0008 #include <boost/leaf/config.hpp>
0009 #include <boost/leaf/detail/print.hpp>
0010
0011 #if BOOST_LEAF_CFG_CAPTURE
0012
0013 #include <iosfwd>
0014
0015 namespace boost { namespace leaf {
0016
0017 class error_id;
0018
0019 namespace detail
0020 {
0021 struct BOOST_LEAF_SYMBOL_VISIBLE tls_tag_id_factory_current_id;
0022
0023 class capture_list
0024 {
0025 capture_list( capture_list const & ) = delete;
0026 capture_list & operator=( capture_list const & ) = delete;
0027
0028 protected:
0029
0030 class node
0031 {
0032 friend class capture_list;
0033
0034 virtual void unload( int err_id ) = 0;
0035 #if BOOST_LEAF_CFG_DIAGNOSTICS
0036 virtual void print(std::ostream &, error_id const & to_print, char const * & prefix) const = 0;
0037 #endif
0038
0039 protected:
0040
0041 virtual ~node() noexcept
0042 {
0043 };
0044
0045 node * next_;
0046
0047 BOOST_LEAF_CONSTEXPR explicit node( node * * & last ) noexcept:
0048 next_(nullptr)
0049 {
0050 BOOST_LEAF_ASSERT(last != nullptr);
0051 *last = this;
0052 last = &next_;
0053 }
0054 } * first_;
0055
0056 template <class F>
0057 BOOST_LEAF_CONSTEXPR void for_each( F f ) const
0058 {
0059 for( node * p=first_; p; p=p->next_ )
0060 f(*p);
0061 }
0062
0063 public:
0064
0065 BOOST_LEAF_CONSTEXPR explicit capture_list( node * first ) noexcept:
0066 first_(first)
0067 {
0068 }
0069
0070 BOOST_LEAF_CONSTEXPR capture_list( capture_list && other ) noexcept:
0071 first_(other.first_)
0072 {
0073 other.first_ = nullptr;
0074 }
0075
0076 ~capture_list() noexcept
0077 {
0078 for( node const * p = first_; p; )
0079 {
0080 node const * n = p -> next_;
0081 delete p;
0082 p = n;
0083 }
0084 }
0085
0086 void unload( int const err_id )
0087 {
0088 capture_list moved(first_);
0089 first_ = nullptr;
0090 tls::write_uint<detail::tls_tag_id_factory_current_id>(unsigned(err_id));
0091 moved.for_each(
0092 [err_id]( node & n )
0093 {
0094 n.unload(err_id);
0095 } );
0096 }
0097
0098 template <class CharT, class Traits>
0099 void print(std::basic_ostream<CharT, Traits> & os, error_id const & to_print, char const * & prefix) const
0100 {
0101 #if BOOST_LEAF_CFG_DIAGNOSTICS
0102 if( first_ )
0103 {
0104 for_each(
0105 [&os, &to_print, &prefix]( node const & n )
0106 {
0107 n.print(os, to_print, prefix);
0108 } );
0109 }
0110 #else
0111 (void) os;
0112 (void) prefix;
0113 (void) to_print;
0114 #endif
0115 }
0116 };
0117
0118 }
0119
0120 } }
0121
0122 #endif
0123
0124 #endif