SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWStreamCoupler Class Reference

Provides an automated mechanism for connecting an input stream to an output stream. More...

#include <rw/internet/RWStreamCoupler.h>

Public Types

typedef bool(* Filter) (const RWCString &)
 
enum  TransferMode { ASCII , BINARY , mode_ascii , mode_binary }
 

Public Member Functions

 RWStreamCoupler (TransferMode mode=mode_ascii)
 
TransferMode getMode (void) const
 
bool operator() (std::istream &in, RWPortalOStream &out)
 
bool operator() (std::istream &in, RWPortalOStream &out, Filter filter)
 
bool operator() (std::istream &in, std::ostream &out)
 
bool operator() (std::istream &in, std::ostream &out, Filter filter)
 
void setMode (TransferMode mode)
 

Detailed Description

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.

Example
#include <rw/rstream.h>
#include <rw/network/RWInetAddr.h>
#include <rw/network/RWInetHost.h>
#include <rw/network/RWPortalIStream.h>
#include <rw/network/RWSocketPortal.h>
#include <rw/network/RWWinSockInfo.h>
#include <rw/internet/RWStreamCoupler.h>
int main(void) {
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
// connect the input stream to the output stream cout
couple(istr, cout);
} catch (const RWxmsg& msg) {
cerr << "Error: " << msg.why() << endl;
}
return 0;
}
Encapsulates a complete Internet address that includes type information, a host, and a port.
Definition RWInetAddr.h:68
static RWInetHost me()
Socket implementation of a portal.
Definition RWSocketPortal.h:34
Provides an automated mechanism for connecting an input stream to an output stream.
Definition RWStreamCoupler.h:78
Provides a std::basic_istream that uses an RWPortal as its source of bytes.
Definition RWTPortalIStream.h:38
Initializes the Winsock DLL on Windows platforms.
Definition RWWinSockInfo.h:49
Base class for the hierarchy of exceptions in the Essential Tools Module.
Definition rwerr.h:57
virtual const char * why() const

Member Typedef Documentation

◆ Filter

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.

Member Enumeration Documentation

◆ TransferMode

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.

Enumerator
ASCII 
Deprecated
As of SourcePro 1, use mode_ascii instead.

line mode transfer

BINARY 
Deprecated
As of SourcePro 1, use mode_binary instead.

byte mode transfer

mode_ascii 

line mode transfer

mode_binary 

byte mode transfer

Constructor & Destructor Documentation

◆ RWStreamCoupler()

RWStreamCoupler::RWStreamCoupler ( TransferMode mode = mode_ascii)

Constructs an RWStreamCoupler object. If the mode argument is not explicitly set, it is mode_ascii by default.

Member Function Documentation

◆ getMode()

TransferMode RWStreamCoupler::getMode ( void ) const

Gets the current transfer mode.

◆ operator()() [1/4]

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.

◆ operator()() [2/4]

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.

◆ operator()() [3/4]

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.

◆ operator()() [4/4]

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.

◆ setMode()

void RWStreamCoupler::setMode ( TransferMode mode)

Sets the transfer mode.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.