LLVM OpenMP 22.0.0git
kmp_safe_raii_file_t Class Reference

This class safely opens and closes a C-style FILE* object using RAII semantics. More...

#include "/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/openmp/runtime/src/kmp.h"

Public Member Functions

 kmp_safe_raii_file_t ()
 kmp_safe_raii_file_t (const char *filename, const char *mode, const char *env_var=nullptr)
 kmp_safe_raii_file_t (const kmp_safe_raii_file_t &other)=delete
kmp_safe_raii_file_toperator= (const kmp_safe_raii_file_t &other)=delete
 ~kmp_safe_raii_file_t ()
void open (const char *filename, const char *mode, const char *env_var=nullptr)
 Open filename using mode.
int try_open (const char *filename, const char *mode)
 Instead of erroring out, return non-zero when unsuccessful fopen() for any reason.
void set_stdout ()
 Set the FILE* object to stdout and output there No open call should happen before this call.
void set_stderr ()
 Set the FILE* object to stderr and output there No open call should happen before this call.
 operator bool ()
 operator FILE * ()

Detailed Description

This class safely opens and closes a C-style FILE* object using RAII semantics.

There are also methods which allow using stdout or stderr as the underlying FILE* object. With the implicit conversion operator to FILE*, an object with this type can be used in any function which takes a FILE* object e.g., fprintf(). No close method is needed at use sites.

Definition at line 4716 of file kmp.h.

Constructor & Destructor Documentation

◆ kmp_safe_raii_file_t() [1/3]

kmp_safe_raii_file_t::kmp_safe_raii_file_t ( )
inline

Definition at line 4727 of file kmp.h.

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

◆ kmp_safe_raii_file_t() [2/3]

kmp_safe_raii_file_t::kmp_safe_raii_file_t ( const char * filename,
const char * mode,
const char * env_var = nullptr )
inline

Definition at line 4728 of file kmp.h.

References mode, and open().

◆ kmp_safe_raii_file_t() [3/3]

kmp_safe_raii_file_t::kmp_safe_raii_file_t ( const kmp_safe_raii_file_t & other)
delete

◆ ~kmp_safe_raii_file_t()

kmp_safe_raii_file_t::~kmp_safe_raii_file_t ( )
inline

Definition at line 4735 of file kmp.h.

Member Function Documentation

◆ open()

void kmp_safe_raii_file_t::open ( const char * filename,
const char * mode,
const char * env_var = nullptr )
inline

Open filename using mode.

This is automatically closed in the destructor. The env_var parameter indicates the environment variable the filename came from if != nullptr.

Definition at line 4740 of file kmp.h.

References __kmp_fatal(), __kmp_msg_null, KMP_ASSERT, KMP_ERR, KMP_HNT, KMP_MSG, and mode.

Referenced by kmp_safe_raii_file_t().

◆ operator bool()

kmp_safe_raii_file_t::operator bool ( )
inline

Definition at line 4776 of file kmp.h.

◆ operator FILE *()

kmp_safe_raii_file_t::operator FILE * ( )
inline

Definition at line 4777 of file kmp.h.

◆ operator=()

kmp_safe_raii_file_t & kmp_safe_raii_file_t::operator= ( const kmp_safe_raii_file_t & other)
delete

◆ set_stderr()

void kmp_safe_raii_file_t::set_stderr ( )
inline

Set the FILE* object to stderr and output there No open call should happen before this call.

Definition at line 4772 of file kmp.h.

References KMP_ASSERT.

◆ set_stdout()

void kmp_safe_raii_file_t::set_stdout ( )
inline

Set the FILE* object to stdout and output there No open call should happen before this call.

Definition at line 4766 of file kmp.h.

References KMP_ASSERT.

◆ try_open()

int kmp_safe_raii_file_t::try_open ( const char * filename,
const char * mode )
inline

Instead of erroring out, return non-zero when unsuccessful fopen() for any reason.

Definition at line 4757 of file kmp.h.

References KMP_ASSERT, and mode.


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