Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/leaf/detail/capture_list.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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