Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:40

0001 /* Copyright 2003-2013 Joaquin M Lopez Munoz.
0002  *           2019 Mike Dev <mike.dev@gmx.de>
0003  * Distributed under the Boost Software License, Version 1.0.
0004  * (See accompanying file LICENSE_1_0.txt or copy at
0005  * https://www.boost.org/LICENSE_1_0.txt)
0006  *
0007  * NOTE: internalized from Boost.MultiIndex
0008  *
0009  */
0010 
0011 
0012 #ifndef BOOST_SIGNALS2_DETAIL_SCOPE_GUARD_HPP
0013 #define BOOST_SIGNALS2_DETAIL_SCOPE_GUARD_HPP
0014 
0015 #if defined(_MSC_VER)
0016 #pragma once
0017 #endif
0018 
0019 #include <boost/core/no_exceptions_support.hpp>
0020 
0021 namespace boost{
0022 
0023 namespace signals2{
0024 
0025 namespace detail{
0026 
0027 /* This is a merely reformated version of
0028  * ScopeGuard.h as defined in:
0029  *   Alexandrescu, A., Marginean, P.:"Generic<Programming>: Change the Way You
0030  *     Write Exception-Safe Code - Forever", C/C++ Users Jornal, Dec 2000,
0031  *     http://www.drdobbs.com/184403758
0032  * with the following modifications:
0033  *   - General pretty formatting (pretty to my taste at least.)
0034  *   - Naming style changed to standard C++ library requirements.
0035  *   - Removed RefHolder and ByRef, whose functionality is provided
0036  *     already by Boost.Ref.
0037  *   - Removed static make_guard's and make_obj_guard's, so that the code
0038  *     will work even if BOOST_NO_MEMBER_TEMPLATES is defined. This forces
0039  *     us to move some private ctors to public, though.
0040  *
0041  * NB: CodeWarrior Pro 8 seems to have problems looking up safe_execute
0042  * without an explicit qualification.
0043  *
0044  *  TODO: Consider replacing with Boost.ScopeExit
0045  *
0046  */
0047 
0048 class scope_guard_impl_base
0049 {
0050 public:
0051   scope_guard_impl_base():dismissed_(false){}
0052   void dismiss()const{dismissed_=true;}
0053 
0054 protected:
0055   ~scope_guard_impl_base(){}
0056 
0057   scope_guard_impl_base(const scope_guard_impl_base& other):
0058     dismissed_(other.dismissed_)
0059   {
0060     other.dismiss();
0061   }
0062 
0063   template<typename J>
0064   static void safe_execute(J& j){
0065     BOOST_TRY{
0066       if(!j.dismissed_)j.execute();
0067     }
0068     BOOST_CATCH(...){}
0069     BOOST_CATCH_END
0070   }
0071 
0072   mutable bool dismissed_;
0073 
0074 private:
0075   scope_guard_impl_base& operator=(const scope_guard_impl_base&);
0076 };
0077 
0078 typedef const scope_guard_impl_base& scope_guard;
0079 
0080 template<class Obj,typename MemFun,typename P1,typename P2>
0081 class obj_scope_guard_impl2:public scope_guard_impl_base
0082 {
0083 public:
0084   obj_scope_guard_impl2(Obj& obj,MemFun mem_fun,P1 p1,P2 p2):
0085     obj_(obj),mem_fun_(mem_fun),p1_(p1),p2_(p2)
0086   {}
0087   ~obj_scope_guard_impl2(){scope_guard_impl_base::safe_execute(*this);}
0088   void execute(){(obj_.*mem_fun_)(p1_,p2_);}
0089 
0090 protected:
0091   Obj&     obj_;
0092   MemFun   mem_fun_;
0093   const P1 p1_;
0094   const P2 p2_;
0095 };
0096 
0097 template<class Obj,typename MemFun,typename P1,typename P2>
0098 inline obj_scope_guard_impl2<Obj,MemFun,P1,P2>
0099 make_obj_guard(Obj& obj,MemFun mem_fun,P1 p1,P2 p2)
0100 {
0101   return obj_scope_guard_impl2<Obj,MemFun,P1,P2>(obj,mem_fun,p1,p2);
0102 }
0103 
0104 } /* namespace signals2::detail */
0105 
0106 } /* namespace signals2 */
0107 
0108 } /* namespace boost */
0109 
0110 #endif