DD::Image::FileWriter Class Reference

Inherits DD::Image::Writer.

List of all members.

Public Member Functions

 FileWriter (Write *)
 ~FileWriter ()
virtual void finish ()
 Called when processing is finished for the current file.

Protected Member Functions

bool open ()
bool close ()
bool write (const void *, FILE_OFFSET)
bool write (FILE_OFFSET, const void *, FILE_OFFSET)
bool seek (FILE_OFFSET)
FILE_OFFSET tell () const
std::string getTempFileName (const char *pActualFileName=NULL) const
 Returns a temporary file name for the current output file (e. g. filename.ext.tmp)

Protected Attributes

void * file
 Actually a FILE* but I don't want the <stdio.h> header!
FILE_OFFSET offset
 Current offset into file.

Related Functions

(Note that these are not member functions.)
typedef unsigned long FILE_OFFSET
typedef unsigned long FILE_OFFSET

Detailed Description

Writer subclass to write a single Unix file. You must subclass this and implement several virtual functions to write pieces of a file. This takes care of opening and closing the file.


Constructor & Destructor Documentation

FileWriter::FileWriter ( Write iop)

This does not open the file. Instead a subclass should call open() as the first statement in execute() and then return if open fails.

References file.

FileWriter::~FileWriter ( )

Destruction closes the temporary file if execute() did not call close().

References file.


Member Function Documentation

bool FileWriter::open ( ) [protected]

Open the output file. This file is created with a temporary name so that the original file is not replaced until the write is successful. This returns false and calls iop->error() if it can't open the file.

References DD::Image::Op::critical(), file, DD::Image::Writer::filename(), getTempFileName(), DD::Image::Writer::iop, and offset.

bool FileWriter::close ( ) [protected]

Close the output file. If there have not been any errors this will mv the temporary file to the correct place.

References DD::Image::Writer::aborted(), DD::Image::Op::critical(), file, DD::Image::Writer::filename(), getTempFileName(), and DD::Image::Writer::iop.

bool FileWriter::write ( const void *  buf,
FILE_OFFSET  length 
) [protected]

Write length bytes to the file. Call iop->error() on any errors and returns false. Returns true on success.

References DD::Image::Op::critical(), file, DD::Image::Writer::iop, and offset.

Referenced by write().

bool FileWriter::write ( FILE_OFFSET  off,
const void *  buf,
FILE_OFFSET  length 
) [protected]

Same as "seek(off) && write(buf, length)", this writes length bytes to the file at offset and leaves the pointer after that.

References seek(), and write().

bool FileWriter::seek ( FILE_OFFSET  off) [protected]

Move the write pointer to offset. This is done efficiently if the pointer is already at that point. Calls iop->error() on any errors and returns false. Returns true on success.

References DD::Image::Op::critical(), file, DD::Image::Writer::iop, and offset.

Referenced by write().

FILE_OFFSET DD::Image::FileWriter::tell ( ) const [inline, protected]

Returns where the pointer currently is.

std::string FileWriter::getTempFileName ( const char *  pActualFileName = NULL) const [protected]

Returns a temporary file name for the current output file (e. g. filename.ext.tmp)

Returns a temporary file name for the given actual file name. e. g. filename.ext -> filename.ext.tmp Pass in NULL to use the current filename().

References DD::Image::Writer::filename().

Referenced by close(), finish(), and open().


Friends And Related Function Documentation

typedef unsigned long FILE_OFFSET [related]

This type may need to be replaced on 64-bit file systems.

typedef unsigned long FILE_OFFSET [related]

This type may need to be replaced on 64-bit file systems.