Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Link.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 // (C) 199x-2009 University of Washington
10 // (C) 199x-2009 University of California Santa Cruz
11 // (C) 199x-2009 University of California San Francisco
12 // (C) 199x-2009 Johns Hopkins University
13 // (C) 199x-2009 University of North Carolina, Chapel Hill
14 // (C) 199x-2009 Vanderbilt University
15 
16 /// @file utility/signals/Link.hh
17 /// @brief class storing the link between observers and subjects
18 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
19 
20 #ifndef INCLUDED_utility_signals_Link_hh
21 #define INCLUDED_utility_signals_Link_hh
22 
23 
24 // unit headers
26 
27 // package headers
30 #include <utility/assert.hh>
31 
32 
33 namespace utility {
34 namespace signals {
35 
36 
37 /// @brief interface wrapper around utility::signals::LinkUnit
38 /// @details Can be used to manage the link between Subject
39 /// and Observer. Signals can be temporarily blocked and the
40 /// connection can be invalidated (disconnected) by the user.
41 /// If a Subject is destroyed or a manual disconnect is called
42 /// via the SignalHub, the Link will automatically become invalidated.
43 /// @remarks Returned by utility::signals::SignalHub upon connection.
44 class Link {
45 
46 
47 private: // typedefs
48 
49 
50  typedef utility::pointer::shared_ptr< LinkUnit > LinkUnitOP;
51 
52 
53 public: // construct/destruct
54 
55 
56  /// @brief default constructor
57  inline
58  Link() {}
59 
60 
61  /// @brief LinkUnit constructor
62  inline
63  Link( LinkUnitOP unit ) :
64  unit_( unit ) // must store the same LinkUnit
65  {}
66 
67 
68  /// @brief copy constructor
69  inline
70  Link( Link const & rval ) :
71  unit_( rval.unit_ ) // must store the same LinkUnit
72  {}
73 
74 
75  /// @brief default destructor
76  inline
77  ~Link() {}
78 
79 
80 public: // copy assignment
81 
82 
83  /// @brief copy assignment
84  Link & operator =( Link const & rval ) {
85  if ( this != &rval ) {
86  unit_ = rval.unit_; // must store the same LinkUnit
87  }
88 
89  return *this;
90  }
91 
92 
93 public: // operators
94 
95 
96  /// @brief equality comparison
97  bool
98  operator ==( Link const & rval ) {
99  return unit_.get() == rval.unit_.get();
100  }
101 
102 
103 public: // interface
104 
105 
106  /// @brief link empty?
107  inline
108  bool empty() const {
109  return ( unit_ == NULL );
110  }
111 
112 
113  /// @brief link still valid?
114  /// @return false if link invalid or empty, otherwise true
115  inline
116  bool valid() const {
117  if ( unit_ ) {
118  return unit_->valid;
119  }
120  return false;
121  }
122 
123 
124  /// @brief cut the connection, safe to call even when link is empty
125  inline
126  void invalidate() {
127  if ( unit_ ) {
128  unit_->valid = false;
129  }
130  }
131 
132 
133  /// @brief link blocked?
134  /// @brief true if link is blocked or empty, otherwise false
135  inline
136  bool blocked() const {
137  if ( unit_ ) {
138  return unit_->blocked;
139  }
140  return true;
141  }
142 
143 
144  /// @brief locally block the link
145  inline
146  void block() {
147  if ( unit_ ) {
148  unit_->blocked = true;
149  }
150  }
151 
152 
153  /// @brief locally unblock the link
154  inline
155  void unblock() {
156  if ( unit_ ) {
157  unit_->blocked = false;
158  }
159  }
160 
161 
162 private: // data
163 
164 
166 
167 };
168 
169 
170 } // namespace signals
171 } // namespace utility
172 
173 #endif /* INCLUDED_utility_signals_Link_HH */
Non-owning access smart pointer – dispatch class.