CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
connect_but_block_self.h
Go to the documentation of this file.
1 #ifndef ServiceRegistry_connect_but_block_self_h
2 #define ServiceRegistry_connect_but_block_self_h
3 // -*- C++ -*-
4 //
5 // Package: ServiceRegistry
6 // Class : connect_but_block_self
7 //
17 //
18 // Original Author: Chris Jones
19 // Created: Thu Sep 22 20:42:32 CEST 2005
20 // $Id: connect_but_block_self.h,v 1.3 2007/01/22 23:04:27 wmtan Exp $
21 //
22 
23 // system include files
24 #include "boost/shared_ptr.hpp"
25 #include "sigc++/signal.h"
26 #include "sigc++/connection.h"
27 #include "boost/bind.hpp"
28 
29 // user include files
30 
31 // forward declarations
32 namespace edm {
33  namespace serviceregistry {
34  template<class Func, class T1=void*, class T2=void*, class T3=void*>
36  {
37 
38  public:
39  BlockingWrapper(Func iFunc): func_(iFunc), numBlocks_(0) {}
40  //virtual ~BlockingWrapper();
41 
42  // ---------- const member functions ---------------------
43  void operator()() {
44  boost::shared_ptr<void> guard(static_cast<void*>(0), boost::bind(&BlockingWrapper::unblock,this) );
45  if( startBlocking() ) { func_(); }
46  }
47 
48  void operator()(T1 iT) {
49  boost::shared_ptr<void> guard(static_cast<void*>(0), boost::bind(&BlockingWrapper::unblock,this) );
50  if( startBlocking() ) { func_(iT); }
51  }
52 
53  void operator()(T1 iT1, T2 iT2) {
54  boost::shared_ptr<void> guard(static_cast<void*>(0), boost::bind(&BlockingWrapper::unblock,this) );
55  if( startBlocking() ) { func_(iT1,iT2); }
56  }
57 
58  void operator()(T1 iT1, T2 iT2, T3 iT3) {
59  boost::shared_ptr<void> guard(static_cast<void*>(0), boost::bind(&BlockingWrapper::unblock,this) );
60  if( startBlocking() ) { func_(iT1,iT2,iT3); }
61  }
62 
63  // ---------- static member functions --------------------
64 
65  // ---------- member functions ---------------------------
66 
67  private:
68  // ---------- member data --------------------------------
69  bool startBlocking() { return 1 == ++numBlocks_; }
70  void unblock() { --numBlocks_;}
71  Func func_;
73  };
74 
75  template<class T>
76  typename T::value_type
77  deref(T& iT){ return *iT;}
78 
79  template<class T>
81  const sigc::slot<void>*){
82  return BlockingWrapper<T>(iT);
83  }
84  template<class T, class TArg>
86  const sigc::slot<void,TArg>*) {
87  return BlockingWrapper<T,TArg>(iT);
88  }
89 
90 
91  template<class Func, class Signal>
92  void
93  connect_but_block_self(Signal& oSignal, const Func& iFunc) {
94  boost::shared_ptr<boost::shared_ptr<sigc::connection> > holder(new boost::shared_ptr<sigc::connection>());
95  *holder = boost::shared_ptr<sigc::connection>(
96  new sigc::connection(oSignal.connect(
98  static_cast<const typename Signal::slot_type*>(0)))));
99  }
100  }
101 }
102 
103 #endif
BlockingWrapper< T > make_blockingwrapper(T iT, const sigc::slot< void > *)
T::value_type deref(T &iT)
Container::value_type value_type
void operator()(T1 iT1, T2 iT2, T3 iT3)
long double T
void connect_but_block_self(Signal &oSignal, const Func &iFunc)
Definition: vlib.h:40