Constructs a stream and audits the bytes that pass through it.
More...
#include <rw/auditbuf.h>
Inherits std::streambuf.
|
(Note that these are not member symbols.)
|
typedef void(* | RWauditFunction) (unsigned char, void *) |
|
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);
std::istream is(&buf);
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>
#include <rw/collstr.h>
#include <rw/dlistcol.h>
#include <iostream>
int main() {
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:167
virtual RWCollectable * prepend(RWCollectable *a)
Definition dlistcol.h:285
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
◆ 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]
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 ) |
|
explicit |
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 ) |
|
explicit |
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 ) |
|
explicit |
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 ) |
|
explicit |
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.
◆ 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.
◆ 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.