SourcePro® API Reference Guide

 
List of all members | Public Types | Public Member Functions
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, 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)
 

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/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)
{
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;
}

Member Typedef Documentation

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

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 ( 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

TransferMode RWStreamCoupler::getMode ( void  ) const

Gets the current transfer mode.

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.

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,
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,
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.

void RWStreamCoupler::setMode ( TransferMode  mode)

Sets the transfer mode.

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