File indexing completed on 2025-01-18 09:51:40
0001
0002
0003
0004
0005
0006
0007
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
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
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 }
0105
0106 }
0107
0108 }
0109
0110 #endif