Loading...
Searching...
No Matches
OFTempFile Class Reference

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

## 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
OFTempFile & | operator= (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::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

  flags | additional flags to pass to open() as its third argument.
  dir | the directory in which the file should be created. The default is a directory suitable for temporary files.
  prefix | this string is prepended to the name of the temporary file.
  postfix | this 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

Referenced by OFTempFile(), and operator=().

## Member Function Documentation

## createFile()

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

  fileName | after this call, this will contain the name of the file that was created
  fd_out | if not NULL, this will be set to a file descriptor for this file
  flags | additional flags to pass to open() as its third argument
  dir | the directory in which the file should be created. The default is a directory suitable for temporary files.
  prefix | this string is prepended to the name of the temporary file.
  postfix | this string is appended to the name of the temporary file.

Returns
  EC_Normal if a file could be created.

## getFileHandle()

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

References m_fileHandle.

## getFilename()

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

References m_fileName.

## getTempPath()

void OFTempFile::getTempPath | ( | OFString & | sPath | ) |

static

Return the system-specific path for storing temporary files.

Parameters

  sPath | will be set to the path on return.

## stealFile()

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

  dontCloseHandle | if true, the file handle is not closed.

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

- ofstd/include/dcmtk/ofstd/oftempf.h

Generated on for DCMTK Version 3.7.0 by Doxygen 1.15.0