Connection.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2016 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_CONNECTION_HPP
30 #define THOR_CONNECTION_HPP
31 
32 #include <Thor/Config.hpp>
33 
34 #include <SFML/System/NonCopyable.hpp>
35 
36 #include <memory>
37 
38 
39 namespace thor
40 {
41 namespace detail
42 {
43 
44  class AbstractConnectionImpl;
45 
46 } // namespace detail
47 
48 
51 
57 class THOR_API Connection
58 {
59  // ---------------------------------------------------------------------------------------------------------------------------
60  // Public member functions
61  public:
64  Connection();
65 
68  bool isConnected() const;
69 
75  void invalidate();
76 
80  void disconnect();
81 
82 
83  // ---------------------------------------------------------------------------------------------------------------------------
84  // Implementation details
85  public:
86  // Create connection from tracker object
87  explicit Connection(std::weak_ptr<detail::AbstractConnectionImpl> tracker);
88 
89 
90  // ---------------------------------------------------------------------------------------------------------------------------
91  // Private variables
92  private:
93  std::weak_ptr<detail::AbstractConnectionImpl> mWeakRef;
94 };
95 
96 
102 class THOR_API ScopedConnection : private sf::NonCopyable
103 {
104  // ---------------------------------------------------------------------------------------------------------------------------
105  // Public member functions
106  public:
110 
114  explicit ScopedConnection(const Connection& connection);
115 
119 
122  ScopedConnection& operator= (ScopedConnection&& source);
123 
126  ~ScopedConnection();
127 
130  bool isConnected() const;
131 
132 
133  // ---------------------------------------------------------------------------------------------------------------------------
134  // Private variables
135  private:
136  Connection mConnection;
137 };
138 
140 
141 } // namespace thor
142 
143 #endif // THOR_CONNECTION_HPP
Definition: AnimationMap.hpp:42
Configuration header of the library.
Class that maintains control over a registered object.
Definition: Connection.hpp:57
RAII style connection with automatic disconnect.
Definition: Connection.hpp:102