SourcePro® C++ API Reference Guide

Product Documentation:
   SourcePro C++
Documentation Home
List of all members | Public Member Functions | Related Functions
RWAuditStreamBuffer Class Reference

Constructs a stream and audits the bytes that pass through it. More...

#include <rw/auditbuf.h>

Inherits streambuf.

Public Member Functions

 RWAuditStreamBuffer (RWauditFunction=0, void *=0)
 
 RWAuditStreamBuffer (std::istream &, RWauditFunction=0, void *=0)
 
 RWAuditStreamBuffer (std::iostream &, RWauditFunction=0, void *=0)
 
 RWAuditStreamBuffer (std::ostream &, RWauditFunction=0, void *=0)
 
 RWAuditStreamBuffer (std::streambuf *, RWauditFunction=0, void *=0)
 
 operator unsigned long ()
 
unsigned long reset (unsigned long val=0ul)
 

Related Functions

(Note that these are not member functions.)

typedef void(* RWauditFunction) (unsigned char, void *)
 

Detailed Description

Class RWAuditStreamBuffer is used to construct a stream, after which the RWAuditStreamBuffer instance counts all the bytes that pass through the stream. If constructed with a function pointer, RWAuditStreamBuffer calls that function with each byte that passes through the stream. The counting capacity provides for streams the equivalent of the method RWCollectable::recursiveStoreSize(), which is only available for RWFile.

Synopsis
#include <rw/auditbuf.h>
#include <iostream>
RWAuditStreamBuffer buf(arguments)
std::ostream os(&buf); // may be used for ostreams
std::istream is(&buf); // or istreams of any kind
Example
#include <rw/bstream.h>
#include <rw/pstream.h>
#include <rw/auditbuf.h>
#include <rw/collint.h> // for RWCollectableInt
#include <rw/collstr.h> // for RWCollectableString
#include <rw/dlistcol.h> // for RWDlistCollectables
#include <iostream>
int main ()
{
RWCollectableString s("Hello!\n");
// Construct a collection
ct.append(&i);
ct.append(&s);
ct.prepend(&ct);
RWAuditStreamBuffer bcounter, pcounter;
RWbostream bcount(&bcounter); // ctor takes streambuf pointer
RWpostream pcount(&pcounter);
bcount << ct;
pcount << ct;
std::cout << "We just counted " << bcounter
<< " bytes from an RWbostream.\n";
std::cout << "We just counted " << pcounter
<< " bytes from an RWpostream." << std::endl;
return 0;
}

Program output:

We just counted 43 bytes from an RWbostream.
We just counted 52 bytes from an RWpostream.
See also
RWAuditStreamBuffer may be used as the std::streambuf for any stream, including those derived from RWvostream or RWvistream, std::strstream, std::ifstream, std::ofstream, etc.
Persistence
None

Constructor & Destructor Documentation

RWAuditStreamBuffer::RWAuditStreamBuffer ( RWauditFunction  = 0,
void *  = 0 
)

Constructs a new RWAuditStreamBuffer that may be used only to examine and count every byte that passes into an std::ostream that has the RWAuditStreamBuffer instance as its std::streambuf. It does not forward the bytes to any stream, nor accept bytes from a stream. The second parameter to the constructor allows you to supply storage for the byte count. It is optional.

RWAuditStreamBuffer::RWAuditStreamBuffer ( std::istream &  ,
RWauditFunction  = 0,
void *  = 0 
)

Constructs a new RWAuditStreamBuffer that passes bytes from the std::istream on which it is constructed to the std::istream that has the RWAuditStreamBuffer instance as its std::streambuf. A typical use would be to count or examine the bytes being input from a file through a stream derived from RWvistream. The third parameter to the constructor allows you to supply storage for the byte count. It is optional.

RWAuditStreamBuffer::RWAuditStreamBuffer ( std::iostream &  ,
RWauditFunction  = 0,
void *  = 0 
)

Constructs a new RWAuditStreamBuffer that passes bytes to and from the std::iostream on which it is constructed to and from the std::istream that has the RWAuditStreamBuffer instance as its std::streambuf. A typical use would be to count or examine the bytes being transferred to and from a file used to store and retrieve changing data. The third parameter to the constructor allows you to supply storage for the byte count. It is optional.

RWAuditStreamBuffer::RWAuditStreamBuffer ( std::ostream &  ,
RWauditFunction  = 0,
void *  = 0 
)

Constructs a new RWAuditStreamBuffer that passes bytes into the std::ostream on which it is constructed from the std::ostream that has the RWAuditStreamBuffer instance as its std::streambuf. A typical use would be to count or examine the bytes being output to a file through a stream derived from RWvostream. The third parameter to the constructor allows you to supply storage for the byte count. It is optional.

RWAuditStreamBuffer::RWAuditStreamBuffer ( std::streambuf *  ,
RWauditFunction  = 0,
void *  = 0 
)

Constructs a new RWAuditStreamBuffer that passes bytes into the std::ostream on which it is constructed from the std::ostream that has the RWAuditStreamBuffer instance as its std::streambuf. A typical use would be to count or examine the bytes being output to a file through a stream derived from RWvostream. The third parameter to the constructor allows you to supply storage for the byte count. It is optional.

Member Function Documentation

RWAuditStreamBuffer::operator unsigned long ( )
inline

Provides the count of bytes seen so far.

unsigned long RWAuditStreamBuffer::reset ( unsigned long  val = 0ul)
inline

Resets the count of bytes seen so far. Returns the current count.

Friends And Related Function Documentation

typedef void(* RWauditFunction) (unsigned char, void *)
related

If you wish to do more than count each character handled by the buffer, you may provide an RWauditFunction to the constructor. The first parameter to this function is a byte provided by the stream. The second parameter is the address of the counter to be manipulated by RWAuditFunction.

Copyright © 2016 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.
Provide feedback to Rogue Wave about its documentation.