Choreonoid  1.8
ConnectionSet.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_BASE_CONNECTION_SET_H
6 #define CNOID_BASE_CONNECTION_SET_H
7 
8 #include "Signal.h"
9 #include <vector>
10 
11 namespace cnoid {
12 
14 {
15  std::vector<Connection> connections;
16 
17 protected:
20  : connections(org.connections) { }
22  : connections(std::move(org.connections)) { }
23  void clear() { connections.clear(); }
24 
25 public:
26  bool empty() const { return connections.empty(); }
27  int numConnections() const { return connections.size(); }
28  Connection& operator[](int index){ return connections[index]; };
29  int add(const Connection& connection){
30  auto index = connections.size();
31  connections.push_back(connection);
32  return index;
33  }
34  void add(const ConnectionSetBase& another){
35  for(auto& connection : another.connections){
36  connections.push_back(connection);
37  }
38  }
39  void block(){
40  for(auto& connection : connections){
41  connection.block();
42  }
43  }
44  void unblock(){
45  for(auto& connection : connections){
46  connection.unblock();
47  }
48  }
49  void block(int index){
50  connections[index].block();
51  }
52  void unblock(int index){
53  connections[index].unblock();
54  }
55  void disconnect(){
56  for(auto& connection : connections){
57  connection.disconnect();
58  }
59  connections.clear();
60  }
61 
62  class ScopedBlock {
63  ConnectionSetBase* pConnections;
64  public:
66  : pConnections(&connections) {
67  connections.block();
68  }
69  ScopedBlock(ScopedBlock&& org) : pConnections(org.pConnections) {
70  org.pConnections = nullptr;
71  }
72  ScopedBlock(const ScopedBlock&) = delete;
73  ScopedBlock& operator=(const ScopedBlock&) = delete;
75  if(pConnections){
76  pConnections->unblock();
77  }
78  }
79  };
80  ScopedBlock scopedBlock(){ return ScopedBlock(*this); }
81 };
82 
83 
85 {
86 public:
89  ConnectionSet(ConnectionSet&& org) : ConnectionSetBase(std::move(org)) { }
91  clear(); add(org); return *this;
92  }
93 };
94 
95 
97 {
98 public:
102 
103  ScopedConnectionSet(const ScopedConnectionSet&) = delete;
105 };
106 
107 }
108 
109 #endif
cnoid::ConnectionSetBase::block
void block()
Definition: ConnectionSet.h:39
cnoid::ConnectionSet::operator=
ConnectionSet & operator=(const ConnectionSet &org)
Definition: ConnectionSet.h:90
cnoid::ScopedConnectionSet::ScopedConnectionSet
ScopedConnectionSet()
Definition: ConnectionSet.h:99
cnoid::ConnectionSetBase::ScopedBlock
Definition: ConnectionSet.h:62
cnoid::ConnectionSetBase::ScopedBlock::ScopedBlock
ScopedBlock(ScopedBlock &&org)
Definition: ConnectionSet.h:69
cnoid::ConnectionSet::ConnectionSet
ConnectionSet(const ConnectionSet &org)
Definition: ConnectionSet.h:88
cnoid::ConnectionSet
Definition: ConnectionSet.h:84
cnoid::ConnectionSetBase::ConnectionSetBase
ConnectionSetBase(ConnectionSetBase &&org)
Definition: ConnectionSet.h:21
cnoid::ConnectionSetBase::disconnect
void disconnect()
Definition: ConnectionSet.h:55
cnoid::ConnectionSet::ConnectionSet
ConnectionSet()
Definition: ConnectionSet.h:87
cnoid::ConnectionSetBase::empty
bool empty() const
Definition: ConnectionSet.h:26
cnoid::ConnectionSetBase::block
void block(int index)
Definition: ConnectionSet.h:49
cnoid::ConnectionSetBase::ScopedBlock::ScopedBlock
ScopedBlock(ConnectionSetBase &connections)
Definition: ConnectionSet.h:65
cnoid::ConnectionSetBase::ConnectionSetBase
ConnectionSetBase()
Definition: ConnectionSet.h:18
cnoid::ConnectionSetBase::scopedBlock
ScopedBlock scopedBlock()
Definition: ConnectionSet.h:80
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::ConnectionSetBase::ConnectionSetBase
ConnectionSetBase(const ConnectionSetBase &org)
Definition: ConnectionSet.h:19
cnoid::ScopedConnectionSet::ScopedConnectionSet
ScopedConnectionSet(ScopedConnectionSet &&org)
Definition: ConnectionSet.h:100
cnoid::ConnectionSetBase
Definition: ConnectionSet.h:13
cnoid::ConnectionSetBase::ScopedBlock::~ScopedBlock
~ScopedBlock()
Definition: ConnectionSet.h:74
Signal.h
cnoid::ScopedConnectionSet
Definition: ConnectionSet.h:96
cnoid::ConnectionSetBase::unblock
void unblock(int index)
Definition: ConnectionSet.h:52
cnoid::ConnectionSetBase::unblock
void unblock()
Definition: ConnectionSet.h:44
cnoid::ScopedConnectionSet::~ScopedConnectionSet
~ScopedConnectionSet()
Definition: ConnectionSet.h:101
cnoid::ConnectionSetBase::ScopedBlock::operator=
ScopedBlock & operator=(const ScopedBlock &)=delete
cnoid::ConnectionSetBase::add
int add(const Connection &connection)
Definition: ConnectionSet.h:29
cnoid::ConnectionSetBase::operator[]
Connection & operator[](int index)
Definition: ConnectionSet.h:28
cnoid::ConnectionSet::ConnectionSet
ConnectionSet(ConnectionSet &&org)
Definition: ConnectionSet.h:89
cnoid::ConnectionSetBase::numConnections
int numConnections() const
Definition: ConnectionSet.h:27
cnoid::Connection
Definition: Signal.h:206
cnoid::ConnectionSetBase::add
void add(const ConnectionSetBase &another)
Definition: ConnectionSet.h:34
cnoid::ConnectionSetBase::clear
void clear()
Definition: ConnectionSet.h:23
cnoid::ScopedConnectionSet::operator=
ScopedConnectionSet & operator=(const ScopedConnectionSet &)=delete