ACE
6.3.3
|
Efficiently reads an arbitrarily large buffer from an input stream up to and including a termination character. Also performs search/replace on single occurrences a character in the buffer using the principles of Integrated Layer Processing. More...
#include <Read_Buffer.h>
Public Member Functions | |
ACE_Read_Buffer (FILE *fp, bool close_on_delete=false, ACE_Allocator *=0) | |
Read from a FILE *. More... | |
ACE_Read_Buffer (ACE_HANDLE handle, bool close_on_delete=false, ACE_Allocator *=0) | |
Read from an open HANDLE. More... | |
~ACE_Read_Buffer (void) | |
Closes the FILE *. More... | |
char * | read (int terminator=EOF, int search= '\n', int replace= '\0') |
size_t | replaced (void) const |
Returns the number of characters replaced during a read . More... | |
size_t | size (void) const |
ACE_Allocator * | alloc (void) const |
Returns a pointer to its allocator. More... | |
void | dump (void) const |
Dump the state of the object. More... | |
Private Member Functions | |
void | operator= (const ACE_Read_Buffer &) |
ACE_Read_Buffer (const ACE_Read_Buffer &) | |
char * | rec_read (int term, int search, int replace) |
Recursive helper method that does the work... More... | |
Private Attributes | |
size_t | size_ |
The total number of characters in the buffer. More... | |
size_t | occurrences_ |
The total number of characters replaced. More... | |
FILE * | stream_ |
The stream we are reading from. More... | |
bool const | close_on_delete_ |
ACE_Allocator * | allocator_ |
Pointer to the allocator. More... | |
Efficiently reads an arbitrarily large buffer from an input stream up to and including a termination character. Also performs search/replace on single occurrences a character in the buffer using the principles of Integrated Layer Processing.
This implementation is optimized to do a single dynamic allocation and make only one copy of the data. It uses recursion and the run-time stack to accomplish this efficiently.
ACE_Read_Buffer::ACE_Read_Buffer | ( | FILE * | fp, |
bool | close_on_delete = false , |
||
ACE_Allocator * | alloc = 0 |
||
) |
Read from a FILE *.
ACE_Read_Buffer::ACE_Read_Buffer | ( | ACE_HANDLE | handle, |
bool | close_on_delete = false , |
||
ACE_Allocator * | alloc = 0 |
||
) |
Read from an open HANDLE.
ACE_Read_Buffer::~ACE_Read_Buffer | ( | void | ) |
Closes the FILE *.
|
private |
|
inline |
Returns a pointer to its allocator.
void ACE_Read_Buffer::dump | ( | void | ) | const |
Dump the state of the object.
|
private |
char * ACE_Read_Buffer::read | ( | int | terminator = EOF , |
int | search = '\n' , |
||
int | replace = '\0' |
||
) |
Returns a pointer dynamically allocated with ACE_Allocator::malloc() to data from the input stream up to (and including) the terminator. If search is >= 0 then all occurrences of the search value are substituted with the replace value. The last of the byte of data is a 0, so that strlen
can be used on it. The caller is responsible for freeing the pointer returned from this method using the ACE_Allocator::free().
|
private |
Recursive helper method that does the work...
|
inline |
Returns the number of characters replaced during a read
.
|
inline |
Returns the size of the allocated buffer obtained during a read
, not including the null terminator.
|
private |
Pointer to the allocator.
|
private |
Keeps track of whether we should close the FILE in the destructor.
|
private |
The total number of characters replaced.
|
private |
The total number of characters in the buffer.
|
private |
The stream we are reading from.