TOP --> libjdl

class CJdlBufferedFileWriter

Defines a buffered file writer.

Objects of this form write data to files using fopen(), fwrite() and fclose(). It is efficient because it reads data in large chunks and then manipulates the internal memory buffer.

A simple usage is shown below:

    CJdlBufferedFileReader rd("in.txt");
    if(rd.Open()) {
      CJdlBufferedFileWriter wr("out.txt");
      if(wr.Open()) {
        char ch;
        while((ch = rd.GetChar())) {
          if('*' == ch) {
            wr.PutChar('$'); // The next GetChar() will return '$'.
          }
          else {
            wr.PutChar(ch);
          }
        }
        wr.Close();
      }
      rd.Close();
    }
 

Author:
Joe Linoff

Version:
$Id: jdlbuffilewr.h,v 1.4 1999/06/12 18:26:00 jdl Exp $

Source:
../../libjdl/src/jdlbuffilewr.h:58

See Also:
CJdlBufferedFileReader

Constructors Index

CJdlBufferedFileWriter
[public] Default Constructor. This allows the class to be used in a has-a relationsip.
CJdlBufferedFileWriter
[public] Constructor.
CJdlBufferedFileWriter
[public] Constructor.
~CJdlBufferedFileWriter
[public] Destructor.


Methods Index

Close
[public] Close the file.
Debug
[public] Turn debugging on or off.
Eof
[public] End of file?
Flush
[public] Flush the contents of the buffer.
GetCharOffset
[public] Returns the offset from the beginning of the line for the current character.
GetFileName
[public]
GetLineNumber
[public]
GetNumChars
[public] The total number of characters written.
Ok
[public] Ok to write?
Open
[public] Open the file.
Open
[public] Open the file.
PutChar
[public] Put a character to the file.
PutString
[public] Put a C style string to the file.


Constructors

CJdlBufferedFileWriter

public CJdlBufferedFileWriter ( ) ;

Default Constructor. This allows the class to be used in a has-a relationsip.

Use Open(fn) to set the file name.

CJdlBufferedFileWriter

public CJdlBufferedFileWriter ( const char * fn ) ;

Constructor.

If the file does not exist, Ok() will return false. The default buffer size is 64K.

Parameters:
fn Name of the file to write.

CJdlBufferedFileWriter

public CJdlBufferedFileWriter ( const char * fn ,
                                uint bufsize ) ;

Constructor.

If the file does not exist, Ok() will return false.

Parameters:
fn Name of the file to write.
bufsize The size of the write buffer. If the buffer size specified is less than 64, then 64 is assumed as the minimum.

CJdlBufferedFileWriter

public ~ CJdlBufferedFileWriter ( ) ;

Destructor.


Methods

Open

public bool Open ( ) ;

Open the file.

The member function was provided so that the same output file could be opened and closed multiple times.

Return:
The status of the open (same as Ok()).

Open

public bool Open ( const char * fn ,
                   uint bufsz = 65535) ) ;

Open the file.

The member function was provided so that the same output file could be opened and closed multiple times.

Parameters:
fn The file name. This replaces the file name that was specified in the constructor.
bufsz The internal buffer size.

Return:
The status of the open (same as Ok()).

Ok

public bool Ok ( ) const ;

Ok to write?

Return:
true if the file was opened successfully.

Eof

public bool Eof ( ) const ;

End of file?

Return:
true if the file was opened successfully, written to and then closed.

PutChar

public void PutChar ( char ch ) ;

Put a character to the file.

The characters are cached in the internal buffer and when the buffer is full, they are written to the file in one big chunk resulting in faster I/O performance.

Parameters:
ch The character to queue.

PutString

public void PutString ( const char * string ) ;

Put a C style string to the file.

The characters are cached in the internal buffer and when the buffer is full, they are written to the file in one big chunk resulting in faster I/O performance.

Parameters:
string The character to queue.

Flush

public void Flush ( ) ;

Flush the contents of the buffer.

Close

public void Close ( ) ;

Close the file.

Flush is automatically called.

After the file is closed, Ok() will return true and Eof() will return true.

GetFileName

public const char * GetFileName ( ) const ;

Return:
The file name.

GetLineNumber

public long GetLineNumber ( ) const ;

Return:
The current line number.

GetCharOffset

public uint GetCharOffset ( ) const ;

Returns the offset from the beginning of the line for the current character.

The value returned is as follows:

    "This is a sample line.\n"
     ^    ^                ^
     |    |                +--- CharOffset() == 0
     |    +-------------------- CharOffset() == 6
     +------------------------- CharOffset() == 1
 

Return:
The current character offset from the beginning of the line.

GetNumChars

public long GetNumChars ( ) const ;

The total number of characters written.

This number persists after the file is Closed().

Return:
The total number of characters written.

Debug

public void Debug ( bool flag = true ) ;

Turn debugging on or off.

This generates a lot of output to stderr so use it sparingly.

Parameters:
flag If true, turn on debugging.

This documentation was generated automatically by the ccdoc tool (version 0.7a).
Click here to submit a bug report or feature request.

Click here to return to the top of the page.