SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWAuditStreamBuffer Class Reference

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

#include <rw/auditbuf.h>

Inherits std::streambuf.

Public Member Functions

 RWAuditStreamBuffer ()
 
 RWAuditStreamBuffer (RWauditFunction, void *=0)
 
 RWAuditStreamBuffer (std::iostream &, RWauditFunction=0, void *=0)
 
 RWAuditStreamBuffer (std::istream &, 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 Symbols

(Note that these are not member symbols.)

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 available only for RWFile.

Synopsis
#include <rw/auditbuf.h>
#include <iostream>
std::ostream os(&buf); // may be used for ostreams
std::istream is(&buf); // or istreams of any kind
Constructs a stream and audits the bytes that pass through it.
Definition auditbuf.h:112
Example
#include <rw/auditbuf.h>
#include <rw/bstream.h>
#include <rw/pstream.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;
}
Provides a polymorphically persistable RWInteger.
Definition collint.h:49
Provides a polymorphically persistable RWCString.
Definition collstr.h:50
Represents a group of ordered items, not accessible by an external key.
Definition dlistcol.h:49
virtual RWCollectable * append(RWCollectable *a)
Definition dlistcol.h:175
virtual RWCollectable * prepend(RWCollectable *a)
Definition dlistcol.h:288
Stores variables in binary format.
Definition bstream.h:338
Specializes the abstract base class RWvostream to store variables in a portable (printable) US-ASCII ...
Definition pstream.h:398

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() [1/6]

RWAuditStreamBuffer::RWAuditStreamBuffer ( )

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.

◆ RWAuditStreamBuffer() [2/6]

RWAuditStreamBuffer::RWAuditStreamBuffer ( RWauditFunction ,
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() [3/6]

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() [4/6]

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() [5/6]

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() [6/6]

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

◆ operator unsigned long()

RWAuditStreamBuffer::operator unsigned long ( )
inline

Provides the count of bytes seen so far.

◆ reset()

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

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

Friends And Related Symbol Documentation

◆ RWauditFunction

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 © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.