Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
TempFile Class Reference

Create a temporary file to read and write data to. More...

#include <temp_file.hpp>

Public Member Functions

 ~TempFile ()
 The TempFile destructor. More...
 
const char * GetFilename () const
 Get the filename being used by this TempFile. More...
 
bool Open (const char *mode_s)
 Open the TempFile. More...
 
int Close ()
 Close the TempFile. More...
 
bool Print (const char *arg_s)
 Print a c-style string to the TempFile. More...
 
const char * GetData ()
 Get the contents of the TempFile as a c-style string. More...
 
void ClearData ()
 Clear the data from the underlying file. More...
 
bool IsOpen () const
 Check if a TempFile is currently open. More...
 
 ~TempFile ()
 The TempFile destructor. More...
 
const char * GetFilename () const
 Get the filename being used by this TempFile. More...
 
bool Open (const char *mode_s)
 Open the TempFile. More...
 
int Close ()
 Close the TempFile. More...
 
bool Print (const char *arg_s)
 Print a c-style string to the TempFile. More...
 
const char * GetData ()
 Get the contents of the TempFile as a c-style string. More...
 
void ClearData ()
 Clear the data from the underlying file. More...
 
bool IsOpen () const
 Check if a TempFile is currently open. More...
 
char * GetTempFilenameBuffer (const char *const working_directory_s, const char *const prefix_s, const char *const temp_suffix_s)
 Create a buffer of the required length to be used by TempFile *GetTempFile (const char *template_s, const bool temp_flag). More...
 

Static Public Member Functions

static TempFileGetTempFile (const char *template_s, const bool temp_flag)
 Create a TempFile. More...
 
static TempFileGetTempFile (const char *working_dir_s, const uuid_t id, const char *const suffix_s)
 Create a TempFile. More...
 
static TempFileGetTempFile (const char *template_s, const bool temp_flag)
 Create a TempFile. More...
 
static TempFileGetTempFile (const char *working_dir_s, const uuid_t id, const char *const suffix_s)
 Create a TempFile. More...
 

Detailed Description

Create a temporary file to read and write data to.

Constructor & Destructor Documentation

◆ ~TempFile() [1/2]

~TempFile ( )

The TempFile destructor.

◆ ~TempFile() [2/2]

~TempFile ( )

The TempFile destructor.

Member Function Documentation

◆ GetTempFile() [1/4]

static TempFile* GetTempFile ( const char *  template_s,
const bool  temp_flag 
)
static

Create a TempFile.

The filename used will be of the form

<working_dir_s>/<id>.<suffix_s>.

Parameters
template_sThe template for the filename. The filename generated from this will depend upon the value of tenp_flag.
temp_flagIf this is true then template_s will be passed to tmpnam. If not, template_s will be used as is for the filename.
Returns
The new TempFile upon success or 0 upon failure.

◆ GetTempFile() [2/4]

static TempFile* GetTempFile ( const char *  working_dir_s,
const uuid_t  id,
const char *const  suffix_s 
)
static

Create a TempFile.

The filename used will be of the form

<working_dir_s>/<id>.<suffix_s>.

Parameters
working_dir_sThe directory where the underlying file will be created.
idThe prefix of the filename.
suffix_sThe suffix of the filename
Returns
The new TempFile upon success or 0 upon failure.

◆ GetFilename() [1/2]

const char* GetFilename ( ) const

Get the filename being used by this TempFile.

Returns
The filename or 0 if it is not set.

◆ Open() [1/2]

bool Open ( const char *  mode_s)

Open the TempFile.

Parameters
mode_sThe mode string which is the same as the c standard library mode string used by fopen.
Returns
true if the file was opened successfully, false otherwise.

◆ Close() [1/2]

int Close ( )

Close the TempFile.

Returns
0 upon success. The value returned is the same as the c standard library function fclose.

◆ Print() [1/2]

bool Print ( const char *  arg_s)

Print a c-style string to the TempFile.

Parameters
arg_sThe strng to print.
Returns
true if the string was printed successfully, false otherwise.

◆ GetData() [1/2]

const char* GetData ( )

Get the contents of the TempFile as a c-style string.

Returns
The contents of the file or 0 upon error.

◆ ClearData() [1/2]

void ClearData ( )

Clear the data from the underlying file.

◆ IsOpen() [1/2]

bool IsOpen ( ) const

Check if a TempFile is currently open.

Returns
true if the file is open false otherwise.

◆ GetTempFile() [3/4]

static TempFile* GetTempFile ( const char *  template_s,
const bool  temp_flag 
)
static

Create a TempFile.

The filename used will be of the form

<working_dir_s>/<id>.<suffix_s>.

Parameters
template_sThe template for the filename. The filename generated from this will depend upon the value of tenp_flag.
temp_flagIf this is true then template_s will be passed to tmpnam. If not, template_s will be used as is for the filename.
Returns
The new TempFile upon success or 0 upon failure.

◆ GetTempFile() [4/4]

static TempFile* GetTempFile ( const char *  working_dir_s,
const uuid_t  id,
const char *const  suffix_s 
)
static

Create a TempFile.

The filename used will be of the form

<working_dir_s>/<id>.<suffix_s>.

Parameters
working_dir_sThe directory where the underlying file will be created.
idThe prefix of the filename.
suffix_sThe suffix of the filename
Returns
The new TempFile upon success or 0 upon failure.

◆ GetFilename() [2/2]

const char* GetFilename ( ) const

Get the filename being used by this TempFile.

Returns
The filename or 0 if it is not set.

◆ Open() [2/2]

bool Open ( const char *  mode_s)

Open the TempFile.

Parameters
mode_sThe mode string which is the same as the c standard library mode string used by fopen.
Returns
true if the file was opened successfully, false otherwise.

◆ Close() [2/2]

int Close ( )

Close the TempFile.

Returns
0 upon success. The value returned is the same as the c standard library function fclose.

◆ Print() [2/2]

bool Print ( const char *  arg_s)

Print a c-style string to the TempFile.

Parameters
arg_sThe strng to print.
Returns
true if the string was printed successfully, false otherwise.

◆ GetData() [2/2]

const char* GetData ( )

Get the contents of the TempFile as a c-style string.

Returns
The contents of the file or 0 upon error.

◆ ClearData() [2/2]

void ClearData ( )

Clear the data from the underlying file.

◆ IsOpen() [2/2]

bool IsOpen ( ) const

Check if a TempFile is currently open.

Returns
true if the file is open false otherwise.

◆ GetTempFilenameBuffer()

char * GetTempFilenameBuffer ( const char *const  working_directory_s,
const char *const  prefix_s,
const char *const  temp_suffix_s 
)

Create a buffer of the required length to be used by TempFile *GetTempFile (const char *template_s, const bool temp_flag).

The filename used will be of the form

<working_dir_s>/<id>.<suffix_s>.

Parameters
working_directory_sThe directory where the underlying file will be created.
prefix_sThe prefix of the filename.
temp_suffix_sThe suffix of the filename
Returns
The buffer containing the required string or NULL upon error.

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