RflySimSDK v3.08
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_SendTextMessageStreamProxy.h
浏览该文件的文档.
1/** @file
2 @brief Header allowing use of a output stream-style method of sending
3 text messages from devices. Contains the operator<< overload needed to
4 stream into a vrpn_BaseClassUnique::SendTextMessageBoundCall, and the
5 proxy object containing an ostringstream that executes the bound call
6 when it's done having data streamed in to it.
7
8 This is a separate header to avoid including <sstream> in vrpn_BaseClass.h
9 since the functionality is only used by device implementations themselves,
10 and not even all of them. Further, since we create the stream proxy
11 only once we've seen an operator<< (rather than as a part of the bound
12 call),
13 we know that if a stream proxy exists, it has a message to send.
14
15 @date 2011
16
17 @author
18 Ryan Pavlik
19 <rpavlik@iastate.edu> and <abiryan@ryand.net>
20 http://academic.cleardefinition.com/
21 Iowa State University Virtual Reality Applications Center
22 Human-Computer Interaction Graduate Program
23*/
24
25// Copyright Iowa State University 2011.
26// Distributed under the Boost Software License, Version 1.0.
27// (See accompanying file LICENSE_1_0.txt or copy at
28// http://www.boost.org/LICENSE_1_0.txt)
29
30#pragma once
31
32// Internal Includes
33#include "vrpn_BaseClass.h"
34
35// Library/third-party includes
36// - none
37
38// Standard includes
39#include <sstream>
40
42private:
43 /// Functor allowing us to perform a send_text_message call on
44 /// a device's behalf once we're done having data streamed in.
46
47 /// Stream that will accumulate the message
48 std::ostringstream _s;
49
50 /// assignment operator disabled
52 operator=(vrpn_SendTextMessageStreamProxy const&);
53
54public:
55 /// Templated constructor taking anything streamable.
56 template <typename T>
59 T const& firstData)
60 : _call(call)
61 {
62 _s << firstData;
63 }
64
65 /// Constructor taking a std::string, since we can use the ostringstream's
66 /// std::string constructor in this case.
69 std::string const& firstData)
70 : _call(call)
71 , _s(firstData)
72 {
73 }
74
75 /// Copy constructor - required for return by value (?)
78 : _call(other._call)
79 , _s(other._s.str())
80 {
81 }
82
83 /// Destructor performs the send_text_message call with all contents
84 /// streamed into it.
85 ~vrpn_SendTextMessageStreamProxy() { _call(_s.str().c_str()); }
86
87 /// Template operator<<, used for the second item streamed into the results
88 /// of a BoundCall-returning send_text_message() call. The first one is
89 /// handled below, and creates this temporary proxy object. Now, we can
90 /// return a reference to the internal ostream, and we'll still
91 /// stick around until the end of the statement to make the call
92 /// once it's all done.
93 template <typename T> std::ostream& operator<<(T const& other)
94 {
95 _s << other;
96 return _s;
97 }
98};
99
100/// Templated operator << that takes a
101/// vrpn_BaseClassUnique::SendTextMessageBoundCall on the left, and some data on
102/// the
103/// right, and uses that to initialize and return a temporary
104/// vrpn_SendTextMessageStreamProxy who will be able to accept
105/// additional streamed data before making the send_text_message call in its
106/// destructor at the
107/// end of the statement.
108template <typename T>
111 T const& firstData)
112{
113 return vrpn_SendTextMessageStreamProxy(call, firstData);
114}
定义 vrpn_SendTextMessageStreamProxy.h:41
vrpn_SendTextMessageStreamProxy(vrpn_BaseClassUnique::SendTextMessageBoundCall const &call, T const &firstData)
Templated constructor taking anything streamable.
定义 vrpn_SendTextMessageStreamProxy.h:57
~vrpn_SendTextMessageStreamProxy()
定义 vrpn_SendTextMessageStreamProxy.h:85
vrpn_SendTextMessageStreamProxy(vrpn_BaseClassUnique::SendTextMessageBoundCall const &call, std::string const &firstData)
定义 vrpn_SendTextMessageStreamProxy.h:67
std::ostream & operator<<(T const &other)
定义 vrpn_SendTextMessageStreamProxy.h:93
vrpn_SendTextMessageStreamProxy(vrpn_SendTextMessageStreamProxy const &other)
Copy constructor - required for return by value (?)
定义 vrpn_SendTextMessageStreamProxy.h:76
vrpn_SendTextMessageStreamProxy operator<<(vrpn_BaseClassUnique::SendTextMessageBoundCall const &call, T const &firstData)
定义 vrpn_SendTextMessageStreamProxy.h:110