SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Provides an automated mechanism for connecting an input stream to an output stream. More...
#include <rw/internet/RWStreamCoupler.h>
Public Types | |
enum | TransferMode { mode_ascii, mode_binary, ASCII, BINARY } |
typedef bool(* | Filter )(const RWCString &) |
Public Member Functions | |
RWStreamCoupler (TransferMode mode=mode_ascii) | |
bool | operator() (std::istream &in, std::ostream &out) |
bool | operator() (std::istream &in, RWPortalOStream &out) |
bool | operator() (std::istream &in, std::ostream &out, Filter filter) |
bool | operator() (std::istream &in, RWPortalOStream &out, Filter filter) |
void | setMode (TransferMode mode) |
TransferMode | getMode (void) const |
RWStreamCoupler provides an automated mechanism for connecting an input stream to an output stream. You can use it in conjunction with the network portal streams and the Internet classes to couple an FTP get
to an FTP put
, an FTP get
to a file, an FTP put
from a file, and a POP3 get
to a file. You can also use it to automate copying one file to another.
The coupling mechanism respects canonical line termination in ASCII mode, and always uses <cr><lf>
pairs to terminate lines when streaming out to a portal.
An optional end-of-input filter may be added to terminate the processing of the input stream prior to the end of the stream.
#include <rw/rstream.h> #include <rw/network/RWWinSockInfo.h> #include <rw/network/RWSocketPortal.h> #include <rw/network/RWPortalIStream.h> #include <rw/network/RWInetHost.h> #include <rw/network/RWInetAddr.h> #include <rw/internet/RWStreamCoupler.h> int main(void) { RWWinSockInfo info; try { // get an address for daytime port on localhost RWInetAddr addr("daytime", RWInetHost::me()); // connect to address RWSocketPortal portal(addr); // construct an input stream RWPortalIStream istr(portal); // construct a coupler object using ASCII mode to couple RWStreamCoupler couple; // connect the input stream to the output stream cout couple(istr, cout); } catch(const RWxmsg& msg) { cerr << "Error: " << msg.why() << endl; } return 0; }
typedef bool(* RWStreamCoupler::Filter)(const RWCString &) |
Defines a Filter function that takes const
RWCString&
as its argument. The purpose of a possible customized Filter function is to allow the termination of the processing of an input stream prior to the end of the stream.
Enumerates whether an RWStreamCoupler object adopts a line mode (mode_ascii) transfer with possible line termination and filter issues, or a byte mode (mode_binary) transfer.
mode_ascii |
line mode transfer |
mode_binary |
byte mode transfer |
ASCII |
|
BINARY |
|
RWStreamCoupler::RWStreamCoupler | ( | TransferMode | mode = mode_ascii |
) |
Constructs an RWStreamCoupler object. If the mode argument is not explicitly set, it is mode_ascii by default.
TransferMode RWStreamCoupler::getMode | ( | void | ) | const |
Gets the current transfer mode.
bool RWStreamCoupler::operator() | ( | std::istream & | in, | |
RWPortalOStream & | out, | |||
Filter | filter | |||
) |
Streams the contents of in into out. If the out argument is an RWPortalOStream and the current transfer mode is mode_ascii, <cr><lf>
line termination is enforced. If a filter function is passed in and the transfer mode is mode_ascii, each line of input from in is passed to the filter before streaming out to out.
bool RWStreamCoupler::operator() | ( | std::istream & | in, | |
std::ostream & | out, | |||
Filter | filter | |||
) |
Streams the contents of in into out. If the out argument is an RWPortalOStream and the current transfer mode is mode_ascii, <cr><lf>
line termination is enforced. If a filter function is passed in and the transfer mode is mode_ascii, each line of input from in is passed to the filter before streaming out to out.
bool RWStreamCoupler::operator() | ( | std::istream & | in, | |
RWPortalOStream & | out | |||
) |
Streams the contents of in into out. If the out argument is an RWPortalOStream and the current transfer mode is mode_ascii, <cr><lf>
line termination is enforced. If a filter function is passed in and the transfer mode is mode_ascii, each line of input from in is passed to the filter before streaming out to out.
bool RWStreamCoupler::operator() | ( | std::istream & | in, | |
std::ostream & | out | |||
) |
Streams the contents of in into out. If the out argument is an RWPortalOStream and the current transfer mode is mode_ascii, <cr><lf>
line termination is enforced. If a filter function is passed in and the transfer mode is mode_ascii, each line of input from in is passed to the filter before streaming out to out.
void RWStreamCoupler::setMode | ( | TransferMode | mode | ) |
Sets the transfer mode.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.