RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_ConnectionPtr.h
浏览该文件的文档.
1
14// Copyright Iowa State University 2011.
15// Distributed under the Boost Software License, Version 1.0.
16// (See accompanying file LICENSE_1_0.txt or copy at
17// http://www.boost.org/LICENSE_1_0.txt)
18
19#ifndef INCLUDED_vrpn_ConnectionPtr_h_GUID_52044DCC_1409_4F8B_FC18_0F80285ABDBE
20#define INCLUDED_vrpn_ConnectionPtr_h_GUID_52044DCC_1409_4F8B_FC18_0F80285ABDBE
21
22// Internal Includes
23// - none
24
25// Library/third-party includes
26#include <vrpn_Connection.h>
27#include <vrpn_MainloopObject.h>
28
29// Standard includes
30// - none
31
35public:
38 : _p(c)
39 {
40 if (_p) {
41 _p->addReference();
42 }
43 }
44
47 : _p(other._p)
48 {
49 if (_p) {
50 _p->addReference();
51 }
52 }
53
56 {
57 if (this == &other || _p == other._p) {
59 return *this;
60 }
61
62 reset();
63 if (other._p) {
64 _p = other._p;
65 _p->addReference();
66 }
67 return *this;
68 }
69
72 {
73 if (_p == other) {
75 return *this;
76 }
77
78 reset();
79 if (other) {
80 _p = other;
81 _p->addReference();
82 }
83 return *this;
84 }
85
88
91 void reset()
92 {
93 if (_p) {
94 _p->removeReference();
95 }
96 _p = NULL;
97 }
98
103 vrpn_Connection* get() const { return _p; }
104
107 vrpn_Connection& operator*() { return *_p; }
108
109 vrpn_Connection const& operator*() const { return *_p; }
110
111 vrpn_Connection* operator->() { return _p; }
112
113 vrpn_Connection const* operator->() const { return _p; }
115
116 bool operator!() const { return !_p; }
117
120 typedef vrpn_Connection* vrpn_ConnectionPtr::*unspecified_bool_type;
121 operator unspecified_bool_type() const
122 {
123 return (this->operator!()) ? &vrpn_ConnectionPtr::_p : NULL;
124 }
126
133 static vrpn_ConnectionPtr
134 create_server_connection(int port = vrpn_DEFAULT_LISTEN_PORT_NO,
135 const char* local_in_logfile_name = NULL,
136 const char* local_out_logfile_name = NULL,
137 const char* NIC_NAME = NULL)
138 {
139 return vrpn_ConnectionPtr(
140 vrpn_create_server_connection(port, local_in_logfile_name,
141 local_out_logfile_name, NIC_NAME),
142 false);
143 }
144
145 static vrpn_ConnectionPtr
146 create_server_connection(const char* cname,
147 const char* local_in_logfile_name = NULL,
148 const char* local_out_logfile_name = NULL)
149 {
150 return vrpn_ConnectionPtr(
151 vrpn_create_server_connection(cname, local_in_logfile_name,
152 local_out_logfile_name),
153 false);
154 }
156
157private:
161 vrpn_ConnectionPtr(vrpn_Connection* c, bool needsAddRef)
162 : _p(c)
163 {
164 if (_p && needsAddRef) {
165 _p->addReference();
166 }
167 }
168
170 vrpn_Connection* _p;
171
173 void this_type_does_not_support_comparisons() const {}
174};
175
178inline bool operator==(const vrpn_ConnectionPtr& lhs,
179 const vrpn_ConnectionPtr& rhs)
180{
181 return lhs.get() == rhs.get();
182}
183
186inline bool operator!=(const vrpn_ConnectionPtr& lhs,
187 const vrpn_ConnectionPtr& rhs)
188{
189 return lhs.get() != rhs.get();
190}
191
192#if 0
198template <typename T>
199bool operator!=(const T& lhs, const vrpn_ConnectionPtr& rhs) {
200 rhs.this_type_does_not_support_comparisons();
201 return false;
202}
203
204template <typename T>
205bool operator==(const T& lhs, const vrpn_ConnectionPtr& rhs) {
206 rhs.this_type_does_not_support_comparisons();
207 return false;
208}
209
210template <typename T>
211bool operator!=(const vrpn_ConnectionPtr& lhs, const T& rhs) {
212 lhs.this_type_does_not_support_comparisons();
213 return false;
214}
215
216template <typename T>
217bool operator==(const vrpn_ConnectionPtr& lhs, const T& rhs) {
218 lhs.this_type_does_not_support_comparisons();
219 return false;
220}
222#endif
223
225namespace detail {
226 template <class T> class TypedMainloopObject;
227
230 template <>
232 public:
234 : _instance(o)
235 {
236 if (!o) {
237 throw vrpn_MainloopObject::
238 CannotWrapNullPointerIntoMainloopObject();
239 }
240 }
241
242 virtual bool broken() { return (!_instance->doing_okay()); }
243
244 virtual void mainloop() { _instance->mainloop(); }
245
246 protected:
247 virtual void* _returnContained() const { return _instance.get(); }
248
249 private:
250 vrpn_ConnectionPtr _instance;
251 };
252} // end of namespace detail
253
254#endif // INCLUDED_vrpn_ConnectionPtr_h_GUID_52044DCC_1409_4F8B_FC18_0F80285ABDBE
virtual void mainloop()
The mainloop function: the primary thing we look for in a VRPN object
定义 vrpn_ConnectionPtr.h:244
virtual bool broken()
定义 vrpn_ConnectionPtr.h:242
virtual void * _returnContained() const
定义 vrpn_ConnectionPtr.h:247
定义 vrpn_MainloopObject.h:100
A shared pointer class for holding on to vrpn_Connection instances, using the existing "intrusive ref...
定义 vrpn_ConnectionPtr.h:34
bool operator!=(const vrpn_ConnectionPtr &lhs, const vrpn_ConnectionPtr &rhs)
定义 vrpn_ConnectionPtr.h:186
vrpn_Connection * get() const
定义 vrpn_ConnectionPtr.h:103
vrpn_ConnectionPtr & operator=(vrpn_Connection *other)
Assignment operator from non-smart pointer
定义 vrpn_ConnectionPtr.h:71
void reset()
定义 vrpn_ConnectionPtr.h:91
vrpn_ConnectionPtr & operator=(vrpn_ConnectionPtr const &other)
Assignment operator from smart pointer
定义 vrpn_ConnectionPtr.h:55
bool operator==(const vrpn_ConnectionPtr &lhs, const vrpn_ConnectionPtr &rhs)
定义 vrpn_ConnectionPtr.h:178
~vrpn_ConnectionPtr()
Destructor - decrements the contained reference count, if applicable
定义 vrpn_ConnectionPtr.h:87
vrpn_ConnectionPtr(vrpn_Connection *c=NULL)
Explicit constructor from a non-smart connection pointer
定义 vrpn_ConnectionPtr.h:37
vrpn_ConnectionPtr(vrpn_ConnectionPtr const &other)
Copy constructor from smart pointer
定义 vrpn_ConnectionPtr.h:46
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
void addReference()
Counting references to this connection.
定义 vrpn_MainloopObject.h:43
Namespace enclosing internal implementation details
定义 vrpn_ConnectionPtr.h:225