Choreonoid  1.8
LazySignal.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_BASE_LAZY_SIGNAL_H
6 #define CNOID_BASE_LAZY_SIGNAL_H
7 
8 #include "LazyCaller.h"
9 #include <cnoid/Signal>
10 #include <vector>
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15 class CNOID_EXPORT LazySignalBase : public LazyCaller
16 {
17 public:
18  void request(){ (*this)(); }
19  void requestBlocking(Connection connection){
20  connectionsToBlock.push_back(connection);
21  }
22  void emit(){ flush(); }
23 
24 protected:
25  LazySignalBase(int priority);
26  LazySignalBase(std::function<void()> emitFunction, int priority);
27  std::function<void()> emitFunction;
28  std::vector<Connection> connectionsToBlock;
29  virtual void defaultEmitFunction() = 0;
30 
31 private:
32  void doEmit();
33 };
34 
35 template <class SignalType> class LazySignal : public LazySignalBase
36 {
37 public:
38  LazySignal(int priority = LazyCaller::PRIORITY_HIGH) : LazySignalBase(priority) { }
39 
40  LazySignal(std::function<void()> emitFunction, int priority = LazyCaller::PRIORITY_HIGH)
41  : LazySignalBase(emitFunction, priority) {
42  }
43 
44  SignalType& signal() { return signal_; }
45 
46 protected:
47  virtual void defaultEmitFunction() override {
48  signal_();
49  }
50 
51 private:
52  SignalType signal_;
53 };
54 
55 }
56 
57 #endif
cnoid::LazyCaller::PRIORITY_HIGH
@ PRIORITY_HIGH
Definition: LazyCaller.h:36
cnoid::LazySignal::signal
SignalType & signal()
Definition: LazySignal.h:44
cnoid::LazySignalBase::requestBlocking
void requestBlocking(Connection connection)
Definition: LazySignal.h:19
cnoid::LazySignal
Definition: LazySignal.h:35
cnoid::LazySignalBase::emit
void emit()
Definition: LazySignal.h:22
LazyCaller.h
cnoid::LazySignalBase::emitFunction
std::function< void()> emitFunction
Definition: LazySignal.h:27
cnoid::LazySignalBase::request
void request()
Definition: LazySignal.h:18
cnoid::LazyCaller
Definition: LazyCaller.h:20
cnoid::LazySignal::LazySignal
LazySignal(int priority=LazyCaller::PRIORITY_HIGH)
Definition: LazySignal.h:38
cnoid::LazySignal::defaultEmitFunction
virtual void defaultEmitFunction() override
Definition: LazySignal.h:47
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::LazySignal::LazySignal
LazySignal(std::function< void()> emitFunction, int priority=LazyCaller::PRIORITY_HIGH)
Definition: LazySignal.h:40
cnoid::LazySignalBase::connectionsToBlock
std::vector< Connection > connectionsToBlock
Definition: LazySignal.h:28
cnoid::LazySignalBase
Definition: LazySignal.h:15
cnoid::Connection
Definition: Signal.h:206