DCMTK  Version 3.6.1 20120515
OFFIS DICOM Toolkit
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
OFTempFile Class Reference

this class manages the lifetime of a temporary file. More...

List of all members.

Public Member Functions

 OFTempFile (unsigned int flags=O_RDWR, const OFString &dir="", const OFString &prefix="", const OFString &postfix=".tmp")
 default constructor, create a temporary file with a random name.
 ~OFTempFile ()
 destructor. Deletes the temporary file, if one was created
OFCondition getStatus () const
 gets the error status of this class. If this is bad, no file was created
const char * getFilename () const
 gets the filename of the temporary file.
int getFileHandle () const
 gets the file descriptor of the temporary file.
void stealFile (OFBool dontCloseHandle=OFFalse)
 steals the created temporary file from this class.

Static Public Member Functions

static OFCondition createFile (OFString &fileName, int *fd_out=NULL, unsigned int flags=O_RDWR, const OFString &dir="", const OFString &prefix="", const OFString &postfix=".tmp")
 Create a new temporary file.
static void getTempPath (OFString &sPath)
 Return the system-specific path for storing temporary files.

Private Member Functions

 OFTempFile (const OFTempFile &)
 private undefined copy constructor
OFTempFileoperator= (const OFTempFile &)
 private undefined assignment operator

Private Attributes

OFCondition m_status
 Status for this class, if EC_Normal then we are managing a temporary file.
OFString m_fileName
 Path to the temporary file that we are managing, empty string if none.
int m_fileHandle
 File handle for our file, -1 if we don't have any file.

Detailed Description

this class manages the lifetime of a temporary file.

The file will be created when needed and automatically be deleted by the destructor.


Constructor & Destructor Documentation

OFTempFile::OFTempFile ( unsigned int  flags = O_RDWR,
const OFString dir = "",
const OFString prefix = "",
const OFString postfix = ".tmp" 
)

default constructor, create a temporary file with a random name.

The file will be automatically deleted.

Parameters:
flagsadditional flags to pass to open() as its third argument.
dirthe directory in which the file should be created. The default is a directory suitable for temporary files.
prefixthis string is prepended to the name of the temporary file.
postfixthis string is appended to the name of the temporary file.
Returns:
EC_Normal if a file could be created.
See also:
getStatus() to know if a file was successfully created

Member Function Documentation

static OFCondition OFTempFile::createFile ( OFString fileName,
int *  fd_out = NULL,
unsigned int  flags = O_RDWR,
const OFString dir = "",
const OFString prefix = "",
const OFString postfix = ".tmp" 
) [static]

Create a new temporary file.

Parameters:
fileNameafter this call, this will contain the name of the file that was created
fdif not NULL, this will be set to a file descriptor for this file
flagsadditional flags to pass to open() as its third argument
dirthe directory in which the file should be created. The default is a directory suitable for temporary files.
prefixthis string is prepended to the name of the temporary file.
postfixthis string is appended to the name of the temporary file.
Returns:
EC_Normal if a file could be created.
int OFTempFile::getFileHandle ( ) const [inline]

gets the file descriptor of the temporary file.

If no temporary file was created, this will return -1. The returned fd is still owned by this class and will be closed later.

Returns:
file descriptor for the temporary file
const char* OFTempFile::getFilename ( ) const [inline]

gets the filename of the temporary file.

If no temporary file was created, this will return an empty string.

Returns:
filename of the temporary file
static void OFTempFile::getTempPath ( OFString sPath) [static]

Return the system-specific path for storing temporary files.

Parameters:
sPathwill be set to the path on return.
void OFTempFile::stealFile ( OFBool  dontCloseHandle = OFFalse)

steals the created temporary file from this class.

This means that the file won't be deleted. However, by default the file handle is closed.

Parameters:
dontCloseHandleif true, the file handle is not closed.

The documentation for this class was generated from the following file:


Generated on Tue May 15 2012 for DCMTK Version 3.6.1 20120515 by Doxygen 1.7.5.1-20111027